Merge tag 'efi-2023-10-rc2-2' of https://source.denx.de/u-boot/custodians/u-boot-efi

Pull request efi-2023-10-rc2-2

Documentation:

* Move README.falcon to HTML
* Describe usage of QEMU virtio block device
* Add SPDX license identifiers to svg images
* Add more detail to the description of U-Boot boot phases

UEFI:

* Fix buffer overflows
* Fix memory leak in efi_add_memory_map_pg
* Properly check return values of calloc, uuid_str_to_bin,
  efi_parse_pkcs7_header
diff --git a/doc/README.falcon b/doc/README.falcon
deleted file mode 100644
index 88218d3..0000000
--- a/doc/README.falcon
+++ /dev/null
@@ -1,232 +0,0 @@
-U-Boot Falcon Mode
-====================
-
-Introduction
-------------
-
-This document provides an overview of how to add support for Falcon Mode
-to a board.
-
-Falcon Mode is introduced to speed up the booting process, allowing
-to boot a Linux kernel (or whatever image) without a full blown U-Boot.
-
-Falcon Mode relies on the SPL framework. In fact, to make booting faster,
-U-Boot is split into two parts: the SPL (Secondary Program Loader) and U-Boot
-image. In most implementations, SPL is used to start U-Boot when booting from
-a mass storage, such as NAND or SD-Card. SPL has now support for other media,
-and can generally be seen as a way to start an image performing the minimum
-required initialization. SPL mainly initializes the RAM controller, and then
-copies U-Boot image into the memory.
-
-The Falcon Mode extends this way allowing to start the Linux kernel directly
-from SPL. A new command is added to U-Boot to prepare the parameters that SPL
-must pass to the kernel, using ATAGS or Device Tree.
-
-In normal mode, these parameters are generated each time before
-loading the kernel, passing to Linux the address in memory where
-the parameters can be read.
-With Falcon Mode, this snapshot can be saved into persistent storage and SPL is
-informed to load it before running the kernel.
-
-To boot the kernel, these steps under a Falcon-aware U-Boot are required:
-
-1. Boot the board into U-Boot.
-After loading the desired legacy-format kernel image into memory (and DT as
-well, if used), use the "spl export" command to generate the kernel parameters
-area or the DT.  U-Boot runs as when it boots the kernel, but stops before
-passing the control to the kernel.
-
-2. Save the prepared snapshot into persistent media.
-The address where to save it must be configured into board configuration
-file (CONFIG_CMD_SPL_NAND_OFS for NAND).
-
-3. Boot the board into Falcon Mode. SPL will load the kernel and copy
-the parameters which are saved in the persistent area to the required address.
-If a valid uImage is not found at the defined location, U-Boot will be
-booted instead.
-
-It is required to implement a custom mechanism to select if SPL loads U-Boot
-or another image.
-
-The value of a GPIO is a simple way to operate the selection, as well as
-reading a character from the SPL console if CONFIG_SPL_CONSOLE is set.
-
-Falcon Mode is generally activated by setting CONFIG_SPL_OS_BOOT. This tells
-SPL that U-Boot is not the only available image that SPL is able to start.
-
-Configuration
-----------------------------
-CONFIG_CMD_SPL		Enable the "spl export" command.
-			The command "spl export" is then available in U-Boot
-			mode
-CONFIG_SYS_SPL_ARGS_ADDR	Address in RAM where the parameters must be
-				copied by SPL.
-				In most cases, it is <start_of_ram> + 0x100
-
-CONFIG_SYS_NAND_SPL_KERNEL_OFFS	Offset in NAND where the kernel is stored
-
-CONFIG_CMD_SPL_NAND_OFS	Offset in NAND where the parameters area was saved.
-
-CONFIG_CMD_SPL_NOR_OFS	Offset in NOR where the parameters area was saved.
-
-CONFIG_CMD_SPL_WRITE_SIZE	Size of the parameters area to be copied
-
-CONFIG_SPL_OS_BOOT	Activate Falcon Mode.
-
-Function that a board must implement
-------------------------------------
-
-void spl_board_prepare_for_linux(void) : optional
-	Called from SPL before starting the kernel
-
-spl_start_uboot() : required
-		Returns "0" if SPL should start the kernel, "1" if U-Boot
-		must be started.
-
-Environment variables
----------------------
-
-A board may chose to look at the environment for decisions about falcon
-mode.  In this case the following variables may be supported:
-
-boot_os :		Set to yes/Yes/true/True/1 to enable booting to OS,
-			any other value to fall back to U-Boot (including
-			unset)
-falcon_args_file :	Filename to load as the 'args' portion of falcon mode
-			rather than the hard-coded value.
-falcon_image_file :	Filename to load as the OS image portion of falcon
-			mode rather than the hard-coded value.
-
-Using spl command
------------------
-
-spl - SPL configuration
-
-Usage:
-
-spl export <img=atags|fdt> [kernel_addr] [initrd_addr] [fdt_addr ]
-
-img		: "atags" or "fdt"
-kernel_addr	: kernel is loaded as part of the boot process, but it is not started.
-		  This is the address where a kernel image is stored.
-initrd_addr	: Address of initial ramdisk
-		  can be set to "-" if fdt_addr without initrd_addr is used
-fdt_addr	: in case of fdt, the address of the device tree.
-
-The spl export command does not write to a storage media. The user is
-responsible to transfer the gathered information (assembled ATAGS list
-or prepared FDT) from temporary storage in RAM into persistant storage
-after each run of 'spl export'. Unfortunately the position of temporary
-storage can not be predicted nor provided at commandline, it depends
-highly on your system setup and your provided data (ATAGS or FDT).
-However at the end of an succesful 'spl export' run it will print the
-RAM address of temporary storage. The RAM address of FDT will also be
-set in the environment variable 'fdtargsaddr', the new length of the
-prepared FDT will be set in the environment variable 'fdtargslen'.
-These environment variables can be used in scripts for writing updated
-FDT to persistent storage.
-
-Now the user have to save the generated BLOB from that printed address
-to the pre-defined address in persistent storage
-(CONFIG_CMD_SPL_NAND_OFS in case of NAND).
-The following example shows how to prepare the data for Falcon Mode on
-twister board with ATAGS BLOB.
-
-The "spl export" command is prepared to work with ATAGS and FDT. However,
-using FDT is at the moment untested. The ppc port (see a3m071 example
-later) prepares the fdt blob with the fdt command instead.
-
-
-Usage on the twister board:
---------------------------------
-
-Using mtd names with the following (default) configuration
-for mtdparts:
-
-device nand0 <omap2-nand.0>, # parts = 9
- #: name		size		offset		mask_flags
- 0: MLO                 0x00080000      0x00000000      0
- 1: u-boot              0x00100000      0x00080000      0
- 2: env1                0x00040000      0x00180000      0
- 3: env2                0x00040000      0x001c0000      0
- 4: kernel              0x00600000      0x00200000      0
- 5: bootparms           0x00040000      0x00800000      0
- 6: splashimg           0x00200000      0x00840000      0
- 7: mini                0x02800000      0x00a40000      0
- 8: rootfs              0x1cdc0000      0x03240000      0
-
-
-twister => nand read 82000000 kernel
-
-NAND read: device 0 offset 0x200000, size 0x600000
- 6291456 bytes read: OK
-
-Now the kernel is in RAM at address 0x82000000
-
-twister => spl export atags 0x82000000
-## Booting kernel from Legacy Image at 82000000 ...
-   Image Name:   Linux-3.5.0-rc4-14089-gda0b7f4
-   Image Type:   ARM Linux Kernel Image (uncompressed)
-   Data Size:    3654808 Bytes = 3.5 MiB
-   Load Address: 80008000
-   Entry Point:  80008000
-   Verifying Checksum ... OK
-   Loading Kernel Image ... OK
-OK
-cmdline subcommand not supported
-bdt subcommand not supported
-Argument image is now in RAM at: 0x80000100
-
-The result can be checked at address 0x80000100:
-
-twister => md 0x80000100
-80000100: 00000005 54410001 00000000 00000000    ......AT........
-80000110: 00000000 00000067 54410009 746f6f72    ....g.....ATroot
-80000120: 65642f3d 666e2f76 77722073 73666e20    =/dev/nfs rw nfs
-
-The parameters generated with this step can be saved into NAND at the offset
-0x800000 (value for twister for CONFIG_CMD_SPL_NAND_OFS)
-
-nand erase.part bootparms
-nand write 0x80000100 bootparms 0x4000
-
-Now the parameters are stored into the NAND flash at the address
-CONFIG_CMD_SPL_NAND_OFS (=0x800000).
-
-Next time, the board can be started into Falcon Mode moving the
-setting the gpio (on twister gpio 55 is used) to kernel mode.
-
-The kernel is loaded directly by the SPL without passing through U-Boot.
-
-Example with FDT: a3m071 board
--------------------------------
-
-To boot the Linux kernel from the SPL, the DT blob (fdt) needs to get
-prepard/patched first. U-Boot usually inserts some dynamic values into
-the DT binary (blob), e.g. autodetected memory size, MAC addresses,
-clocks speeds etc. To generate this patched DT blob, you can use
-the following command:
-
-1. Load fdt blob to SDRAM:
-=> tftp 1800000 a3m071/a3m071.dtb
-
-2. Set bootargs as desired for Linux booting (e.g. flash_mtd):
-=> run mtdargs addip2 addtty
-
-3. Use "fdt" commands to patch the DT blob:
-=> fdt addr 1800000
-=> fdt boardsetup
-=> fdt chosen
-
-4. Display patched DT blob (optional):
-=> fdt print
-
-5. Save fdt to NOR flash:
-=> erase fc060000 fc07ffff
-=> cp.b 1800000 fc060000 10000
-...
-
-
-Falcon Mode was presented at the RMLL 2012. Slides are available at:
-
-http://schedule2012.rmll.info/IMG/pdf/LSM2012_UbootFalconMode_Babic.pdf
diff --git a/doc/board/emulation/blkdev.rst b/doc/board/emulation/blkdev.rst
index dc83a00..f187ff2 100644
--- a/doc/board/emulation/blkdev.rst
+++ b/doc/board/emulation/blkdev.rst
@@ -11,8 +11,8 @@
   .. code-block:: bash
 
       -device sdhci-pci,sd-spec-version=3 \
-      -device sd-card,drive=MMC1 \
-      -drive if=none,file=disk.img,format=raw,id=MMC1
+      -drive if=none,file=disk.img,format=raw,id=MMC1 \
+      -device sd-card,drive=MMC1
 
 * NVMe
 
@@ -36,3 +36,13 @@
       -device qemu-xhci \
       -drive if=none,file=disk.img,format=raw,id=USB1 \
       -device usb-storage,drive=USB1
+
+* Virtio
+
+  .. code-block:: bash
+
+      -drive if=none,file=disk.img,format=raw,id=VIRTIO1 \
+      -device virtio-blk,drive=VIRTIO1
+
+  .. note::
+     As of v2023.07 U-Boot does not have a driver for virtio-scsi-pci.
diff --git a/doc/board/ti/img/boot_diagram_am65.svg b/doc/board/ti/img/boot_diagram_am65.svg
index fe5533a..79c65e1 100644
--- a/doc/board/ti/img/boot_diagram_am65.svg
+++ b/doc/board/ti/img/boot_diagram_am65.svg
@@ -1,4 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause-->
+
+<!--Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/-->
+
 <svg
    version="1.1"
    width="707px"
diff --git a/doc/board/ti/img/boot_diagram_j721e.svg b/doc/board/ti/img/boot_diagram_j721e.svg
index e61af5b..182462c 100644
--- a/doc/board/ti/img/boot_diagram_j721e.svg
+++ b/doc/board/ti/img/boot_diagram_j721e.svg
@@ -1,4 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause-->
+
+<!--Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/-->
+
 <svg
    version="1.1"
    width="707px"
diff --git a/doc/board/ti/img/boot_diagram_k3_current.svg b/doc/board/ti/img/boot_diagram_k3_current.svg
index 995afd8..e38a42a 100644
--- a/doc/board/ti/img/boot_diagram_k3_current.svg
+++ b/doc/board/ti/img/boot_diagram_k3_current.svg
@@ -1,4 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause-->
+
+<!--Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/-->
+
 <svg
    version="1.1"
    width="706px"
diff --git a/doc/board/ti/img/boot_flow_01.svg b/doc/board/ti/img/boot_flow_01.svg
index b5bd0ac..15a0357 100644
--- a/doc/board/ti/img/boot_flow_01.svg
+++ b/doc/board/ti/img/boot_flow_01.svg
@@ -1,4 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause-->
+
+<!--Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/-->
+
 <svg
    version="1.1"
    width="296px"
diff --git a/doc/board/ti/img/boot_flow_02.svg b/doc/board/ti/img/boot_flow_02.svg
index 4e282d8..9357021 100644
--- a/doc/board/ti/img/boot_flow_02.svg
+++ b/doc/board/ti/img/boot_flow_02.svg
@@ -1,4 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause-->
+
+<!--Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/-->
+
 <svg
    version="1.1"
    width="751px"
diff --git a/doc/board/ti/img/boot_flow_03.svg b/doc/board/ti/img/boot_flow_03.svg
index b77d679..d8e4f87 100644
--- a/doc/board/ti/img/boot_flow_03.svg
+++ b/doc/board/ti/img/boot_flow_03.svg
@@ -1,4 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause-->
+
+<!--Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/-->
+
 <svg
    version="1.1"
    width="1031px"
diff --git a/doc/board/ti/img/dm_tispl.bin.svg b/doc/board/ti/img/dm_tispl.bin.svg
index ffca67d..57bf385 100644
--- a/doc/board/ti/img/dm_tispl.bin.svg
+++ b/doc/board/ti/img/dm_tispl.bin.svg
@@ -1,4 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause-->
+
+<!--Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/-->
+
 <svg
    version="1.1"
    width="231px"
diff --git a/doc/board/ti/img/emmc_am65x_evm_boot0.svg b/doc/board/ti/img/emmc_am65x_evm_boot0.svg
index ff5c7bf..6201347 100644
--- a/doc/board/ti/img/emmc_am65x_evm_boot0.svg
+++ b/doc/board/ti/img/emmc_am65x_evm_boot0.svg
@@ -1,4 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause-->
+
+<!--Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/-->
+
 <svg
    version="1.1"
    width="570px"
diff --git a/doc/board/ti/img/emmc_j7200_evm_boot01.svg b/doc/board/ti/img/emmc_j7200_evm_boot01.svg
index 43e8b254..5c33ca1 100644
--- a/doc/board/ti/img/emmc_j7200_evm_boot01.svg
+++ b/doc/board/ti/img/emmc_j7200_evm_boot01.svg
@@ -1,4 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause-->
+
+<!--Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/-->
+
 <svg
    version="1.1"
    width="570px"
diff --git a/doc/board/ti/img/emmc_j7200_evm_udafs.svg b/doc/board/ti/img/emmc_j7200_evm_udafs.svg
index 4287bb6..6a5d274 100644
--- a/doc/board/ti/img/emmc_j7200_evm_udafs.svg
+++ b/doc/board/ti/img/emmc_j7200_evm_udafs.svg
@@ -1,4 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause-->
+
+<!--Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/-->
+
 <svg
    version="1.1"
    width="571px"
diff --git a/doc/board/ti/img/j7200_tiboot3.bin.svg b/doc/board/ti/img/j7200_tiboot3.bin.svg
index f535310..acc442f 100644
--- a/doc/board/ti/img/j7200_tiboot3.bin.svg
+++ b/doc/board/ti/img/j7200_tiboot3.bin.svg
@@ -1,4 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause-->
+
+<!--Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/-->
+
 <svg
    version="1.1"
    width="231px"
diff --git a/doc/board/ti/img/multi_cert_tiboot3.bin.svg b/doc/board/ti/img/multi_cert_tiboot3.bin.svg
index a210d66..9094037 100644
--- a/doc/board/ti/img/multi_cert_tiboot3.bin.svg
+++ b/doc/board/ti/img/multi_cert_tiboot3.bin.svg
@@ -1,4 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause-->
+
+<!--Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/-->
+
 <svg
    version="1.1"
    width="231px"
diff --git a/doc/board/ti/img/no_multi_cert_tiboot3.bin.svg b/doc/board/ti/img/no_multi_cert_tiboot3.bin.svg
index 557dbf0..f31672d 100644
--- a/doc/board/ti/img/no_multi_cert_tiboot3.bin.svg
+++ b/doc/board/ti/img/no_multi_cert_tiboot3.bin.svg
@@ -1,4 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause-->
+
+<!--Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/-->
+
 <svg
    version="1.1"
    width="231px"
diff --git a/doc/board/ti/img/nodm_tispl.bin.svg b/doc/board/ti/img/nodm_tispl.bin.svg
index 0406764..056cfda 100644
--- a/doc/board/ti/img/nodm_tispl.bin.svg
+++ b/doc/board/ti/img/nodm_tispl.bin.svg
@@ -1,4 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause-->
+
+<!--Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/-->
+
 <svg
    version="1.1"
    width="231px"
diff --git a/doc/board/ti/img/ospi_sysfw.svg b/doc/board/ti/img/ospi_sysfw.svg
index e7a0fd2..648f6fd 100644
--- a/doc/board/ti/img/ospi_sysfw.svg
+++ b/doc/board/ti/img/ospi_sysfw.svg
@@ -1,4 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause-->
+
+<!--Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/-->
+
 <svg
    version="1.1"
    width="321px"
diff --git a/doc/board/ti/img/sysfw.itb.svg b/doc/board/ti/img/sysfw.itb.svg
index 2d6640a..1be2b61 100644
--- a/doc/board/ti/img/sysfw.itb.svg
+++ b/doc/board/ti/img/sysfw.itb.svg
@@ -1,4 +1,8 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause-->
+
+<!--Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/-->
+
 <svg
    version="1.1"
    width="231px"
diff --git a/doc/develop/falcon.rst b/doc/develop/falcon.rst
new file mode 100644
index 0000000..a569d1a
--- /dev/null
+++ b/doc/develop/falcon.rst
@@ -0,0 +1,258 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+Falcon Mode
+===========
+
+Introduction
+------------
+
+This document provides an overview of how to add support for Falcon Mode
+to a board.
+
+Falcon Mode is introduced to speed up the booting process, allowing
+to boot a Linux kernel (or whatever image) without a full blown U-Boot.
+
+Falcon Mode relies on the SPL framework. In fact, to make booting faster,
+U-Boot is split into two parts: the SPL (Secondary Program Loader) and U-Boot
+image. In most implementations, SPL is used to start U-Boot when booting from
+a mass storage, such as NAND or SD-Card. SPL has now support for other media,
+and can generally be seen as a way to start an image performing the minimum
+required initialization. SPL mainly initializes the RAM controller, and then
+copies U-Boot image into the memory.
+
+The Falcon Mode extends this way allowing to start the Linux kernel directly
+from SPL. A new command is added to U-Boot to prepare the parameters that SPL
+must pass to the kernel, using ATAGS or Device Tree.
+
+In normal mode, these parameters are generated each time before
+loading the kernel, passing to Linux the address in memory where
+the parameters can be read.
+With Falcon Mode, this snapshot can be saved into persistent storage and SPL is
+informed to load it before running the kernel.
+
+To boot the kernel, these steps under a Falcon-aware U-Boot are required:
+
+1. Boot the board into U-Boot.
+    After loading the desired legacy-format kernel image into memory (and DT as
+    well, if used), use the "spl export" command to generate the kernel
+    parameters area or the DT.  U-Boot runs as when it boots the kernel, but
+    stops before passing the control to the kernel.
+
+2. Save the prepared snapshot into persistent media.
+    The address where to save it must be configured into board configuration
+    file (CONFIG_CMD_SPL_NAND_OFS for NAND).
+
+3. Boot the board into Falcon Mode. SPL will load the kernel and copy
+    the parameters which are saved in the persistent area to the required
+    address. If a valid uImage is not found at the defined location, U-Boot
+    will be booted instead.
+
+It is required to implement a custom mechanism to select if SPL loads U-Boot
+or another image.
+
+The value of a GPIO is a simple way to operate the selection, as well as
+reading a character from the SPL console if CONFIG_SPL_CONSOLE is set.
+
+Falcon Mode is generally activated by setting CONFIG_SPL_OS_BOOT. This tells
+SPL that U-Boot is not the only available image that SPL is able to start.
+
+Configuration
+-------------
+
+CONFIG_CMD_SPL
+    Enable the "spl export" command.
+    The command "spl export" is then available in U-Boot mode.
+
+CONFIG_SYS_SPL_ARGS_ADDR
+    Address in RAM where the parameters must be copied by SPL.
+    In most cases, it is <start_of_ram> + 0x100.
+
+CONFIG_SYS_NAND_SPL_KERNEL_OFFS
+    Offset in NAND where the kernel is stored
+
+CONFIG_CMD_SPL_NAND_OFS
+    Offset in NAND where the parameters area was saved.
+
+CONFIG_CMD_SPL_NOR_OFS
+    Offset in NOR where the parameters area was saved.
+
+CONFIG_CMD_SPL_WRITE_SIZE
+    Size of the parameters area to be copied
+
+CONFIG_SPL_OS_BOOT
+    Activate Falcon Mode.
+
+Function that a board must implement
+------------------------------------
+
+void spl_board_prepare_for_linux(void)
+    optional, called from SPL before starting the kernel
+
+spl_start_uboot()
+    required, returns "0" if SPL should start the kernel, "1" if U-Boot
+    must be started.
+
+Environment variables
+---------------------
+
+A board may chose to look at the environment for decisions about falcon
+mode.  In this case the following variables may be supported:
+
+boot_os
+    Set to yes/Yes/true/True/1 to enable booting to OS,
+    any other value to fall back to U-Boot (including unset)
+
+falcon_args_file
+    Filename to load as the 'args' portion of falcon mode rather than the
+    hard-coded value.
+
+falcon_image_file
+    Filename to load as the OS image portion of falcon mode rather than the
+    hard-coded value.
+
+Using spl command
+-----------------
+
+spl - SPL configuration
+
+Usage::
+
+    spl export <img=atags|fdt> [kernel_addr] [initrd_addr] [fdt_addr ]
+
+img
+    "atags" or "fdt"
+
+kernel_addr
+    kernel is loaded as part of the boot process, but it is not started.
+    This is the address where a kernel image is stored.
+
+initrd_addr
+    Address of initial ramdisk
+    can be set to "-" if fdt_addr without initrd_addr is used
+
+fdt_addr
+    in case of fdt, the address of the device tree.
+
+The *spl export* command does not write to a storage media. The user is
+responsible to transfer the gathered information (assembled ATAGS list
+or prepared FDT) from temporary storage in RAM into persistent storage
+after each run of *spl export*. Unfortunately the position of temporary
+storage can not be predicted nor provided at command line, it depends
+highly on your system setup and your provided data (ATAGS or FDT).
+However at the end of an successful *spl export* run it will print the
+RAM address of temporary storage. The RAM address of FDT will also be
+set in the environment variable *fdtargsaddr*, the new length of the
+prepared FDT will be set in the environment variable *fdtargslen*.
+These environment variables can be used in scripts for writing updated
+FDT to persistent storage.
+
+Now the user have to save the generated BLOB from that printed address
+to the pre-defined address in persistent storage
+(CONFIG_CMD_SPL_NAND_OFS in case of NAND).
+The following example shows how to prepare the data for Falcon Mode on
+twister board with ATAGS BLOB.
+
+The *spl export* command is prepared to work with ATAGS and FDT. However,
+using FDT is at the moment untested. The ppc port (see a3m071 example
+later) prepares the fdt blob with the fdt command instead.
+
+
+Usage on the twister board
+--------------------------
+
+Using mtd names with the following (default) configuration
+for mtdparts::
+
+    device nand0 <omap2-nand.0>, # parts = 9
+     #: name        size        offset      mask_flags
+     0: MLO                 0x00080000      0x00000000      0
+     1: u-boot              0x00100000      0x00080000      0
+     2: env1                0x00040000      0x00180000      0
+     3: env2                0x00040000      0x001c0000      0
+     4: kernel              0x00600000      0x00200000      0
+     5: bootparms           0x00040000      0x00800000      0
+     6: splashimg           0x00200000      0x00840000      0
+     7: mini                0x02800000      0x00a40000      0
+     8: rootfs              0x1cdc0000      0x03240000      0
+
+::
+
+    twister => nand read 82000000 kernel
+
+    NAND read: device 0 offset 0x200000, size 0x600000
+    6291456 bytes read: OK
+
+Now the kernel is in RAM at address 0x82000000::
+
+    twister => spl export atags 0x82000000
+    ## Booting kernel from Legacy Image at 82000000 ...
+       Image Name:   Linux-3.5.0-rc4-14089-gda0b7f4
+       Image Type:   ARM Linux Kernel Image (uncompressed)
+       Data Size:    3654808 Bytes = 3.5 MiB
+       Load Address: 80008000
+       Entry Point:  80008000
+       Verifying Checksum ... OK
+       Loading Kernel Image ... OK
+    OK
+    cmdline subcommand not supported
+    bdt subcommand not supported
+    Argument image is now in RAM at: 0x80000100
+
+The result can be checked at address 0x80000100::
+
+    twister => md 0x80000100
+    80000100: 00000005 54410001 00000000 00000000    ......AT........
+    80000110: 00000000 00000067 54410009 746f6f72    ....g.....ATroot
+    80000120: 65642f3d 666e2f76 77722073 73666e20    =/dev/nfs rw nfs
+
+The parameters generated with this step can be saved into NAND at the offset
+0x800000 (value for twister for CONFIG_CMD_SPL_NAND_OFS)::
+
+    nand erase.part bootparms
+    nand write 0x80000100 bootparms 0x4000
+
+Now the parameters are stored into the NAND flash at the address
+CONFIG_CMD_SPL_NAND_OFS (=0x800000).
+
+Next time, the board can be started into Falcon Mode moving the
+setting the GPIO (on twister GPIO 55 is used) to kernel mode.
+
+The kernel is loaded directly by the SPL without passing through U-Boot.
+
+Example with FDT: a3m071 board
+-------------------------------
+
+To boot the Linux kernel from the SPL, the DT blob (fdt) needs to get
+prepared/patched first. U-Boot usually inserts some dynamic values into
+the DT binary (blob), e.g. autodetected memory size, MAC addresses,
+clocks speeds etc. To generate this patched DT blob, you can use
+the following command:
+
+1. Load fdt blob to SDRAM::
+
+        => tftp 1800000 a3m071/a3m071.dtb
+
+2. Set bootargs as desired for Linux booting (e.g. flash_mtd)::
+
+        => run mtdargs addip2 addtty
+
+3. Use "fdt" commands to patch the DT blob::
+
+        => fdt addr 1800000
+        => fdt boardsetup
+        => fdt chosen
+
+4. Display patched DT blob (optional)::
+
+        => fdt print
+
+5. Save fdt to NOR flash::
+
+        => erase fc060000 fc07ffff
+        => cp.b 1800000 fc060000 10000
+        ...
+
+
+Falcon Mode was presented at the RMLL 2012. Slides are available at:
+
+http://schedule2012.rmll.info/IMG/pdf/LSM2012_UbootFalconMode_Babic.pdf
diff --git a/doc/develop/index.rst b/doc/develop/index.rst
index ddbf8da..263d404 100644
--- a/doc/develop/index.rst
+++ b/doc/develop/index.rst
@@ -45,6 +45,7 @@
    printf
    smbios
    spl
+   falcon
    uefi/index
    vbe
    version
diff --git a/doc/develop/spl.rst b/doc/develop/spl.rst
index a1515a7..76e87f0 100644
--- a/doc/develop/spl.rst
+++ b/doc/develop/spl.rst
@@ -77,10 +77,11 @@
 This checks CONFIG_CLK for the main build, CONFIG_SPL_CLK for the SPL build,
 CONFIG_TPL_CLK for the TPL build, etc.
 
-U-Boot Phases
--------------
+U-Boot Boot Phases
+------------------
 
-U-Boot boots through the following phases:
+U-Boot goes through the following boot phases where TPL, VPL, SPL are optional.
+While many boards use SPL, less use TPL.
 
 TPL
    Very early init, as tiny as possible. This loads SPL (or VPL if enabled).
@@ -97,6 +98,12 @@
 U-Boot
    U-Boot proper, containing the command line and boot logic.
 
+Further usages of U-Boot SPL comprise:
+
+* Launching BL31 of ARM Trusted Firmware which invokes main U-Boot as BL33
+* launching EDK II
+* launching Linux kernel
+* launching RISC-V OpenSBI which invokes main U-Boot
 
 Checking the boot phase
 -----------------------
diff --git a/include/dm/device.h b/include/dm/device.h
index b86bf90..e54cb6b 100644
--- a/include/dm/device.h
+++ b/include/dm/device.h
@@ -367,7 +367,7 @@
  * @ops: Driver-specific operations. This is typically a list of function
  * pointers defined by the driver, to implement driver functions required by
  * the uclass.
- * @flags: driver flags - see `DM_FLAGS_...`
+ * @flags: driver flags - see `DM_FLAG_...`
  * @acpi_ops: Advanced Configuration and Power Interface (ACPI) operations,
  * allowing the device to add things to the ACPI tables passed to Linux
  */
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 3a64eb9..4a29dda 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -696,9 +696,21 @@
 /* return true if the device is removable */
 bool efi_disk_is_removable(efi_handle_t handle);
 
-/* open file system: */
-struct efi_simple_file_system_protocol *efi_simple_file_system(
-		struct blk_desc *desc, int part, struct efi_device_path *dp);
+/**
+ * efi_create_simple_file_system() - create simple file system protocol
+ *
+ * Create a simple file system protocol for a partition.
+ *
+ * @desc:	block device descriptor
+ * @part:	partition number
+ * @dp:		device path
+ * @fsp:	simple file system protocol
+ * Return:	status code
+ */
+efi_status_t
+efi_create_simple_file_system(struct blk_desc *desc, int part,
+			      struct efi_device_path *dp,
+			      struct efi_simple_file_system_protocol **fsp);
 
 /* open file from device-path: */
 struct efi_file_handle *efi_file_from_path(struct efi_device_path *fp);
diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
index 7a6f195..af8a2ee 100644
--- a/lib/efi_loader/efi_capsule.c
+++ b/lib/efi_loader/efi_capsule.c
@@ -368,9 +368,8 @@
 					     auth_hdr->auth_info.hdr.dwLength
 					     - sizeof(auth_hdr->auth_info),
 					     &buf);
-	if (IS_ERR(capsule_sig)) {
+	if (!capsule_sig) {
 		debug("Parsing variable's pkcs7 header failed\n");
-		capsule_sig = NULL;
 		goto out;
 	}
 
@@ -581,6 +580,13 @@
 		fw_accept_os = capsule_data->flags & FW_ACCEPT_OS ? 0x1 : 0x0;
 	}
 
+	if (guidcmp(&capsule_data->capsule_guid,
+		    &efi_guid_firmware_management_capsule_id)) {
+		log_err("Unsupported capsule type: %pUs\n",
+			&capsule_data->capsule_guid);
+		return EFI_UNSUPPORTED;
+	}
+
 	/* sanity check */
 	if (capsule_data->header_size < sizeof(*capsule) ||
 	    capsule_data->header_size >= capsule_data->capsule_image_size)
@@ -751,15 +757,7 @@
 
 		log_debug("Capsule[%d] (guid:%pUs)\n",
 			  i, &capsule->capsule_guid);
-		if (!guidcmp(&capsule->capsule_guid,
-			     &efi_guid_firmware_management_capsule_id)) {
-			ret  = efi_capsule_update_firmware(capsule);
-		} else {
-			log_err("Unsupported capsule type: %pUs\n",
-				&capsule->capsule_guid);
-			ret = EFI_UNSUPPORTED;
-		}
-
+		ret  = efi_capsule_update_firmware(capsule);
 		if (ret != EFI_SUCCESS)
 			goto out;
 	}
diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index 46cb570..f0d7611 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -487,15 +487,16 @@
 	 */
 	if ((part || desc->part_type == PART_TYPE_UNKNOWN) &&
 	    efi_fs_exists(desc, part)) {
-		diskobj->volume = efi_simple_file_system(desc, part,
-							 diskobj->dp);
+		ret = efi_create_simple_file_system(desc, part, diskobj->dp,
+						    &diskobj->volume);
+		if (ret != EFI_SUCCESS)
+			goto error;
+
 		ret = efi_add_protocol(&diskobj->header,
 				       &efi_simple_file_system_protocol_guid,
 				       diskobj->volume);
-		if (ret != EFI_SUCCESS) {
-			log_debug("simple FS failed\n");
-			return ret;
-		}
+		if (ret != EFI_SUCCESS)
+			goto error;
 	}
 	diskobj->ops = block_io_disk_template;
 	diskobj->dev_index = dev_index;
@@ -538,6 +539,8 @@
 	return EFI_SUCCESS;
 error:
 	efi_delete_handle(&diskobj->header);
+	free(diskobj->volume);
+	free(diskobj);
 	return ret;
 }
 
diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c
index 520c730..3c56ceb 100644
--- a/lib/efi_loader/efi_file.c
+++ b/lib/efi_loader/efi_file.c
@@ -195,6 +195,8 @@
 
 	/* +2 is for null and '/' */
 	fh = calloc(1, sizeof(*fh) + plen + (flen * MAX_UTF8_PER_UTF16) + 2);
+	if (!fh)
+		return NULL;
 
 	fh->open_mode = open_mode;
 	fh->base = efi_file_handle_protocol;
@@ -1192,18 +1194,22 @@
 	return EFI_EXIT(efi_open_volume_int(this, root));
 }
 
-struct efi_simple_file_system_protocol *
-efi_simple_file_system(struct blk_desc *desc, int part,
-		       struct efi_device_path *dp)
+efi_status_t
+efi_create_simple_file_system(struct blk_desc *desc, int part,
+			      struct efi_device_path *dp,
+			      struct efi_simple_file_system_protocol **fsp)
 {
 	struct file_system *fs;
 
 	fs = calloc(1, sizeof(*fs));
+	if (!fs)
+		return EFI_OUT_OF_RESOURCES;
 	fs->base.rev = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;
 	fs->base.open_volume = efi_open_volume;
 	fs->desc = desc;
 	fs->part = part;
 	fs->dp = dp;
+	*fsp = &fs->base;
 
-	return &fs->base;
+	return EFI_SUCCESS;
 }
diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c
index b557738..9abb29f 100644
--- a/lib/efi_loader/efi_firmware.c
+++ b/lib/efi_loader/efi_firmware.c
@@ -159,7 +159,7 @@
 	const fdt32_t *val;
 	const char *guid_str;
 	int len, offset, index;
-	int parent;
+	int parent, ret;
 
 	*lsv = 0;
 
@@ -173,7 +173,11 @@
 		guid_str = fdt_getprop(fdt, offset, "image-type-id", &len);
 		if (!guid_str)
 			continue;
-		uuid_str_to_bin(guid_str, guid.b, UUID_STR_FORMAT_GUID);
+		ret = uuid_str_to_bin(guid_str, guid.b, UUID_STR_FORMAT_GUID);
+		if (ret < 0) {
+			log_warning("Wrong image-type-id format.\n");
+			continue;
+		}
 
 		val = fdt_getprop(fdt, offset, "image-index", &len);
 		if (!val)
diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c
index 26df0da..9754757 100644
--- a/lib/efi_loader/efi_image_loader.c
+++ b/lib/efi_loader/efi_image_loader.c
@@ -592,6 +592,7 @@
 	struct efi_signature_store *db = NULL, *dbx = NULL;
 	void *new_efi = NULL;
 	u8 *auth, *wincerts_end;
+	u64 new_efi_size = efi_size;
 	size_t auth_size;
 	bool ret = false;
 
@@ -600,11 +601,11 @@
 	if (!efi_secure_boot_enabled())
 		return true;
 
-	new_efi = efi_prepare_aligned_image(efi, (u64 *)&efi_size);
+	new_efi = efi_prepare_aligned_image(efi, &new_efi_size);
 	if (!new_efi)
 		return false;
 
-	if (!efi_image_parse(new_efi, efi_size, &regs, &wincerts,
+	if (!efi_image_parse(new_efi, new_efi_size, &regs, &wincerts,
 			     &wincerts_len)) {
 		log_err("Parsing PE executable image failed\n");
 		goto out;
diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c
index e2ca78d..ebf4a2d 100644
--- a/lib/efi_loader/efi_memory.c
+++ b/lib/efi_loader/efi_memory.c
@@ -34,6 +34,7 @@
 #define EFI_CARVE_NO_OVERLAP		-1
 #define EFI_CARVE_LOOP_AGAIN		-2
 #define EFI_CARVE_OVERLAPS_NONRAM	-3
+#define EFI_CARVE_OUT_OF_RESOURCES	-4
 
 /* This list contains all memory map items */
 static LIST_HEAD(efi_mem);
@@ -239,6 +240,8 @@
 
 	/* Create a new map from [ carve_start ... map_end ] */
 	newmap = calloc(1, sizeof(*newmap));
+	if (!newmap)
+		return EFI_CARVE_OUT_OF_RESOURCES;
 	newmap->desc = map->desc;
 	newmap->desc.physical_start = carve_start;
 	newmap->desc.virtual_start = carve_start;
@@ -282,6 +285,8 @@
 
 	++efi_memory_map_key;
 	newlist = calloc(1, sizeof(*newlist));
+	if (!newlist)
+		return EFI_OUT_OF_RESOURCES;
 	newlist->desc.type = memory_type;
 	newlist->desc.physical_start = start;
 	newlist->desc.virtual_start = start;
@@ -311,11 +316,15 @@
 			r = efi_mem_carve_out(lmem, &newlist->desc,
 					      overlap_only_ram);
 			switch (r) {
+			case EFI_CARVE_OUT_OF_RESOURCES:
+				free(newlist);
+				return EFI_OUT_OF_RESOURCES;
 			case EFI_CARVE_OVERLAPS_NONRAM:
 				/*
 				 * The user requested to only have RAM overlaps,
 				 * but we hit a non-RAM region. Error out.
 				 */
+				free(newlist);
 				return EFI_NO_MAPPING;
 			case EFI_CARVE_NO_OVERLAP:
 				/* Just ignore this list entry */
@@ -346,6 +355,7 @@
 		 * The payload wanted to have RAM overlaps, but we overlapped
 		 * with an unallocated region. Error out.
 		 */
+		free(newlist);
 		return EFI_NO_MAPPING;
 	}
 
@@ -487,7 +497,7 @@
 				enum efi_memory_type memory_type,
 				efi_uintn_t pages, uint64_t *memory)
 {
-	u64 len = pages << EFI_PAGE_SHIFT;
+	u64 len;
 	efi_status_t ret;
 	uint64_t addr;
 
@@ -497,6 +507,11 @@
 		return EFI_INVALID_PARAMETER;
 	if (!memory)
 		return EFI_INVALID_PARAMETER;
+	len = (u64)pages << EFI_PAGE_SHIFT;
+	/* Catch possible overflow on 64bit systems */
+	if (sizeof(efi_uintn_t) == sizeof(u64) &&
+	    (len >> EFI_PAGE_SHIFT) != (u64)pages)
+		return EFI_OUT_OF_RESOURCES;
 
 	switch (type) {
 	case EFI_ALLOCATE_ANY_PAGES:
diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c
index 49f8a5e..7b7926a 100644
--- a/lib/efi_loader/efi_tcg2.c
+++ b/lib/efi_loader/efi_tcg2.c
@@ -706,8 +706,7 @@
 			sha512_finish(&ctx_512, final);
 			break;
 		default:
-			EFI_PRINT("Unsupported algorithm %x\n", hash_alg);
-			return EFI_INVALID_PARAMETER;
+			continue;
 		}
 		digest_list->digests[digest_list->count].hash_alg = hash_alg;
 		memcpy(&digest_list->digests[digest_list->count].digest, final,
@@ -930,8 +929,7 @@
 			hash_calculate("sha512", regs->reg, regs->num, hash);
 			break;
 		default:
-			EFI_PRINT("Unsupported algorithm %x\n", hash_alg);
-			return EFI_INVALID_PARAMETER;
+			continue;
 		}
 		digest_list->digests[digest_list->count].hash_alg = hash_alg;
 		memcpy(&digest_list->digests[digest_list->count].digest, hash,
diff --git a/lib/efi_selftest/efi_selftest_hii.c b/lib/efi_selftest/efi_selftest_hii.c
index f4b5588..f219c01 100644
--- a/lib/efi_selftest/efi_selftest_hii.c
+++ b/lib/efi_selftest/efi_selftest_hii.c
@@ -220,14 +220,12 @@
 	if (ret != EFI_BUFFER_TOO_SMALL) {
 		efi_st_error("list_package_lists returned %u\n",
 			     (unsigned int)ret);
-		ret = EFI_ST_FAILURE;
 		goto out;
 	}
 	ret = boottime->allocate_pool(EFI_LOADER_DATA, handles_size,
 				      (void **)&handles);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("AllocatePool failed\n");
-		ret = EFI_ST_FAILURE;
 		goto out;
 	}
 	ret = hii_database_protocol->list_package_lists(hii_database_protocol,
@@ -236,7 +234,6 @@
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("list_package_lists returned %u\n",
 			     (unsigned int)ret);
-		ret = EFI_ST_FAILURE;
 		goto out;
 	}
 	ret = boottime->free_pool(handles);
@@ -254,14 +251,12 @@
 	if (ret != EFI_BUFFER_TOO_SMALL) {
 		efi_st_error("list_package_lists returned %u\n",
 			     (unsigned int)ret);
-		ret = EFI_ST_FAILURE;
 		goto out;
 	}
 	ret = boottime->allocate_pool(EFI_LOADER_DATA, handles_size,
 				      (void **)&handles);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("AllocatePool failed\n");
-		ret = EFI_ST_FAILURE;
 		goto out;
 	}
 	ret = hii_database_protocol->list_package_lists(hii_database_protocol,
@@ -270,13 +265,11 @@
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("list_package_lists returned %u\n",
 			     (unsigned int)ret);
-		ret = EFI_ST_FAILURE;
 		goto out;
 	}
 	ret = boottime->free_pool(handles);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("FreePool failed\n");
-		ret = EFI_ST_FAILURE;
 		goto out;
 	}
 
@@ -289,14 +282,12 @@
 	if (ret != EFI_BUFFER_TOO_SMALL) {
 		efi_st_error("list_package_lists returned %u\n",
 			     (unsigned int)ret);
-		ret = EFI_ST_FAILURE;
 		goto out;
 	}
 	ret = boottime->allocate_pool(EFI_LOADER_DATA, handles_size,
 				      (void **)&handles);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("AllocatePool failed\n");
-		ret = EFI_ST_FAILURE;
 		goto out;
 	}
 	ret = hii_database_protocol->list_package_lists(hii_database_protocol,
@@ -305,13 +296,11 @@
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("list_package_lists returned %u\n",
 			     (unsigned int)ret);
-		ret = EFI_ST_FAILURE;
 		goto out;
 	}
 	ret = boottime->free_pool(handles);
 	if (ret != EFI_SUCCESS) {
 		efi_st_error("FreePool failed\n");
-		ret = EFI_ST_FAILURE;
 		goto out;
 	}