Commit Graph

734 Commits

Author SHA1 Message Date
xypron.glpk@gmx.de
71275a3e98 efi_memory: avoid NULL dereference in efi_free_pool
If efi_free_pool is called with argument NULL an illegal memory
access occurs.

So let's check the parameter on entry.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-07-19 14:14:41 +02:00
xypron.glpk@gmx.de
70bfcdc6bb efi_loader: disk: iterate only over valid block devices
The efi_loader currently stops iterating over the available
block devices stopping at the first device that fails.
This may imply that no block device is found.

With the patch efi_loader only iterates over valid devices.

It is based on patch
06d592bf52f6 (dm: core: Add uclass_first/next_device_check())
which is currently in u-boot-dm.git.

For testing I used an odroid-c2 with a dts including
&sd_emmc_a {
	status = "okay";
};
This device does not exist on the board and cannot be initialized.

Without the patch:

=> bootefi hello
## Starting EFI application at 01000000 ...
WARNING: Invalid device tree, expect boot to fail
mmc_init: -95, time 1806
Found 0 disks
Hello, world!
## Application terminated, r = 0

With the patch:

=> bootefi hello
## Starting EFI application at 01000000 ...
WARNING: Invalid device tree, expect boot to fail
mmc_init: -95, time 1806
Scanning disk mmc@70000.blk...
Scanning disk mmc@72000.blk...
Card did not respond to voltage select!
mmc_init: -95, time 9
Scanning disk mmc@74000.blk...
Found 3 disks
Hello, world!
## Application terminated, r = 0

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-07-19 14:14:41 +02:00
xypron.glpk@gmx.de
cc5b70812f efi_loader: implement EFI_DEVICE_PATH_TO_TEXT_PROTOCOL
ConvertPathToText is implemented for
* type 4    - media device path
* subtype 4 - file path

This is the kind of device path we hand out for block devices.

All other cases may be implemented later.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
[agraf: fix whitespace]
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-07-19 14:14:40 +02:00
xypron.glpk@gmx.de
88adae5ef0 efi_loader: reimplement efi_locate_protocol
The UEFI specification requires that LocateProtol finds the first
handle supporting the protocol and to return a pointer to its
interface.

So we have to assign the protocols to an efi_object and not use
any separate storage.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-07-19 14:14:40 +02:00
xypron.glpk@gmx.de
c2e703f903 efi_loader: implement LocateHandleBuffer
UEFI boot service LocateHandleBuffer is implemented by calling
efi_allocate_handle and efi_locate_handle.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-07-19 14:14:39 +02:00
xypron.glpk@gmx.de
26329584f3 efi_loader: refactor efi_locate_handle
To implement LocateHandleBuffer we need to call efi_locate_handle
internally without running through EFI_EXIT.

So put EFI_ENTRY and EFI_EXIT into a new wrapper function
efi_locate_handle_ext.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-07-19 14:14:39 +02:00
xypron.glpk@gmx.de
58b8358606 efi_loader: implement InstallMultipleProtocolInterfaces
Implement InstallMultipleProtocolInterfaces in function
efi_install_multiple_protocol_interfaces by repeatedly
calling efi_install_protocol_interface.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-07-19 14:14:39 +02:00
xypron.glpk@gmx.de
3d8e145608 efi_loader: refactor efi_uninstall_protocol_interface
For the implementation of UninstallMultipleProtocolInterfaces we
need to call efi_uninstall_protocol_interface. In internal calls
we should not pass through EFI_EXIT.

The patch introduces a wrapper function
efi_uninstall_protocol_interface_ext.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-07-19 14:14:39 +02:00
xypron.glpk@gmx.de
8bee5a3c13 efi_loader: refactor efi_install_protocol_interface
For the implementation of InstallMultipleProtocolInterfaces we
need to call efi_install_protocol_interface. In internal calls
we should not pass through EFI_EXIT.

The patch introduces a wrapper function
efi_install_protocol_interface_ext.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-07-19 14:14:38 +02:00
xypron.glpk@gmx.de
4b6ed0d7a1 efi_loader: implement UninstallProtocolInterface
Without the patch efi_uninstall_protocol_interface always returns an
error.

With the patch protocols without interface can be uninstalled.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-07-19 14:14:38 +02:00
xypron.glpk@gmx.de
e0549f8a17 efi_loader: implement InstallProtocolInterface
efi_install_protocol_interface up to now only returned an error code.

The patch implements the UEFI specification for InstallProtocolInterface
with the exception that it will not create new handles.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-07-19 14:14:38 +02:00
xypron.glpk@gmx.de
69baec6781 efi_loader: efi_open_protocol: parameter checks
Add all parameter checks for function efi_open_protocol that do not
depend on a locking table.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-07-19 14:14:38 +02:00
xypron.glpk@gmx.de
b5349f742a efi_loader: refactor efi_open_protocol
efi_open_protocol was implemented to call a protocol specific open
function to retrieve the protocol interface.

The UEFI specification does not know of such a function.

It is not possible to implement InstallProtocolInterface with the
current design.

With the patch the protocol interface itself is stored in the list
of installed protocols of an efi_object instead of an open function.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
[agraf: fix efi gop support]
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-07-19 14:14:23 +02:00
Simon Glass
c1eb3d5966 dm: Fix error handling when unflattening the DT
The error handling code does not current detect an error right away.
Adjust it to return immediately.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
Tested-on: Beaver, Jetson-TK1
2017-07-11 10:08:20 -06:00
Simon Glass
6c519f2dc4 display_options: Refactor to allow obtaining the banner
Move the display options code into a separate function so that the U-Boot
banner can be obtained from other code. Adjust the 'version' command to
use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>
2017-07-11 10:08:19 -06:00
Cooper Jr., Franklin
2059ecf30f fdt: Enable selecting correct DTB from appended FIT Image
This patch gives U-boot the runtime support to have the board specific
code decide which FDT to use. This is especially useful for devices
that need this type of runtime determination and also doesn't use SPL.

Signed-off-by: Franklin S Cooper Jr <fcooper@ti.com>
Reviewed-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
2017-07-10 14:25:52 -04:00
Simon Glass
2bf94120e9 libfdt: Drop -FDT_ERR_TOODEEP
This error code has not been upstreamed and is not really needed since it
is unlikely to be triggered. Drop it to maintain compatability with
upstream.

Reported-by: Peter Robinson <pbrobinson@gmail.com>

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
2017-07-10 08:39:24 -04:00
xypron.glpk@gmx.de
da684a646d efi_loader: abort on unsupported relocation type
If a relocation type is not supported loading the EFI binary
should be aborted.

Writing a message only is insufficient.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
[agraf: use a() != b coding style]
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-07-04 09:03:00 +02:00
xypron.glpk@gmx.de
8e1d329ff5 efi_loader: efi_handle_protocol set attributes
UEFI spec 2.7 indicates that HandleProtocol can be implemented
by calling OpenProtocol with
attributes = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL.

Currently we pass attributes = 0 to efi_open_protocol. 0 is not a
valid value when calling OpenProtocol. This does not cause any errors
yet because our implementation of OpenProtocol is incomplete.

We should pass the correct value to enable a fully compliant
implementation of OpenProtocol in the future.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-07-04 09:01:23 +02:00
Masahiro Yamada
6e0bf8d8b4 efi_loader: add static to local functions
These are locally used in lib/efi_loader/efi_boottime.c

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-07-03 14:41:13 +02:00
Jonathan Gray
a95343b8d3 efi_loader: check CreateEvent() parameters
Add some of the invalid parameter checks described in the UEFI
specification for CreateEvent().  This does not include checking
the validity of the type and tpl parameters.

Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
Acked-By: Heinrich Schuchardt <xypron.glpk@gmx.de>
[agraf: fix checkpatch.pl indent warning]
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-07-03 13:54:48 +02:00
Jonathan Gray
37a980b3fa efi_loader: run CreateEvent() notify function based on flags
The UEFI specification states that the tpl, function and context
arguments are to be ignored if neither EVT_NOTIFY_WAIT or
EVT_NOTIFY_SIGNAL are specified.  This matches observed behaviour with
an AMI EDK2 based UEFI implementation.

Skip calling the notify function if neither flag is present.

Signed-off-by: Jonathan Gray <jsg@jsg.id.au>
Acked-By: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
2017-07-03 13:48:51 +02:00
Emmanuel Vadot
4ecc988301 bch: Fix build on FreeBSD host
endian.h on FreeBSD system exist in sys/ subdirectory.
FreeBSD already have a fls function defined in strings.h which is included
in string.h if __BSD_VISIBLE is defined, as a check for this.

Signed-off-by: Emmanuel Vadot <manu@bidouilliste.com>
2017-06-20 14:03:33 -04:00
Simon Glass
9fb34b01f7 bootstage: Provide a default timer function
If CONFIG_SYS_TIMER_COUNTER is used we can provide a default microsecond
timer implementation.

Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-05 14:13:03 -04:00
Simon Glass
727f153629 fdt: Stop building the old python libfdt module
This is no-longer needed, so stop building it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-02 10:18:19 -06:00
Simon Glass
555ba4889c fdt: Rename existing python libfdt module
Now that this module has been accepted upstream we should stop using the
local U-Boot one. In preparation for this, rename it to indicate it is for
legacy use.

Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-02 10:16:47 -06:00
Simon Glass
7e91b10253 fdt: Allow swig options to be provided by Makefile
U-Boot needs to provide some swig include directories. Add this feature.

Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-02 10:16:47 -06:00
Simon Glass
a2b2caae5a fdt: Move header files into lib/libfdt
These header files are actually part of libfdt. Move them there to make
it easier to build pylibfdt and easier to merge changes from upstream.

Update the license header to use SPDX at the same time.

Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-02 10:16:46 -06:00
Simon Glass
c69380f85d fdt: Correct cast for sandbox in fdtdec_setup_memory_size()
This gives a warning with some native compilers:

lib/fdtdec.c:1203:8: warning: format ‘%llx’ expects argument of type
   ‘long long unsigned int’, but argument 3 has type
   ‘long unsigned int’ [-Wformat=]

Fix it with a cast.

Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-02 10:16:46 -06:00
Simon Glass
cf2064d785 fdt: Add Python bindings
An early version of this is available upstream. Bring it in as a starting
point. This is from dtc upstream commit e56f2b0.

Future work will plumb it into dtoc and remove the now-unnecessary local
libraries.

Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-02 10:16:46 -06:00
Simon Glass
a7d0021063 string: Add strcspn()
Add an implementation of strcspn() which returns the number of initial
characters that do not match any in a rejection list.

Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-01 07:03:12 -06:00
Simon Glass
6b45ba45fb string: Add strchrnul()
This functions works like strchr() but returns the end of the string if
the character is not found. Add an implementation of this.

Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-01 07:03:12 -06:00
Simon Glass
2ec9d171bc cros_ec: Convert to support live tree
Convert this driver to support the live device tree and remove the old
fdtdec support.

The keyboard is not yet converted.

Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-01 07:03:11 -06:00
Simon Glass
b7e0d73bad dm: core: Add a place to put extra device-tree reading functions
Some functions deal with structured data rather than simple data types.
It makes sense to have these in their own file. For now this just has a
function to read a flashmap entry. Move the data types also.

Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-01 07:03:07 -06:00
Simon Glass
8b50d526ea dm: Add a function to create a 'live' device tree
This function converts the flat device tree into a hierarchical one with
C structures and pointers. This is easier to access.

Signed-off-by: Simon Glass <sjg@chromium.org>
2017-06-01 07:03:06 -06:00
Simon Glass
aed998aa34 Convert CONFIG_LZMA to Kconfig
This converts the following to Kconfig:
   CONFIG_LZMA

Signed-off-by: Simon Glass <sjg@chromium.org>
2017-05-22 12:45:32 -04:00
Tom Rini
089df18bfe lib: move hash CONFIG options to Kconfig
Commit 94e3c8c4fd ("crypto/fsl - Add progressive hashing support
using hardware acceleration.") created entries for CONFIG_SHA1,
CONFIG_SHA256, CONFIG_SHA_HW_ACCEL, and CONFIG_SHA_PROG_HW_ACCEL.
However, no defconfig has migrated to it.  Complete the move by first
adding additional logic to various Kconfig files to select this when
required and then use the moveconfig tool.  In many cases we can select
these because they are required to implement other drivers.  We also
correct how we include the various hashing algorithms in SPL.

This commit was generated as follows (after Kconfig additions):

[1] tools/moveconfig.py -y SHA1 SHA256 SHA_HW_ACCEL
[2] tools/moveconfig.py -y SHA_PROG_HW_ACCEL

Note:
We cannot move SHA_HW_ACCEL and SHA_PROG_HW_ACCEL simultaneously
because there is dependency between them.

Cc: Poonam Aggrwal <poonam.aggrwal@freescale.com>
Cc: Naveen Burmi <NaveenBurmi@freescale.com>
Cc: Po Liu <po.liu@freescale.com>
Cc: Shengzhou Liu <Shengzhou.Liu@freescale.com>
Cc: Priyanka Jain <Priyanka.Jain@freescale.com>
Cc: Shaohui Xie <Shaohui.Xie@freescale.com>
Cc: Chunhe Lan <Chunhe.Lan@freescale.com>
Cc: Chander Kashyap <k.chander@samsung.com>
Cc: Steve Rae <steve.rae@raedomain.com>
Cc: Dirk Eibach <eibach@gdsys.de>
Cc: Feng Li <feng.li_2@nxp.com>
Cc: Alison Wang <alison.wang@freescale.com>
Cc: Sumit Garg <sumit.garg@nxp.com>
Cc: Mingkai Hu <Mingkai.Hu@freescale.com>
Cc: York Sun <york.sun@nxp.com>
Cc: Prabhakar Kushwaha <prabhakar.kushwaha@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Akshay Saraswat <akshay.s@samsung.com>
Cc: Heiko Schocher <hs@denx.de>
Cc: Jagan Teki <jagan@amarulasolutions.com>
Signed-off-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>
2017-05-22 08:36:58 -04:00
Tom Rini
667d685697 tpm: Fix comparison of unsigned expression warning
The function tpm_xfer returns int so make 'err' be int rather than
uint32_t so that we can catch an error condition.  Reported by
clang-3.8.

Signed-off-by: Tom Rini <trini@konsulko.com>
2017-05-12 08:37:40 -04:00
Jelle van der Waa
c3b4328166 rsa: Fix build with OpenSSL 1.1.x
The rsa_st struct has been made opaque in 1.1.x, add forward compatible
code to access the n, e, d members of rsa_struct.

EVP_MD_CTX_cleanup has been removed in 1.1.x and EVP_MD_CTX_reset should be
called to reinitialise an already created structure.
2017-05-12 08:37:19 -04:00
xypron.glpk@gmx.de
b8865e6bf0 lib/slre: remove superfluous assignment
The value assigned to saved_offset is never used.

The problem was indicated by clang scan-build.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2017-05-12 08:37:18 -04:00
Alex Deymo
82f766d1d2 Allow boards to initialize the DT at runtime.
In some boards like the Raspberry Pi the initial bootloader will pass
a DT to the kernel. When using U-Boot as such kernel, the board code in
U-Boot should be able to provide U-Boot with this, already assembled
device tree blob.

This patch introduces a new config option CONFIG_OF_BOARD to use instead
of CONFIG_OF_EMBED or CONFIG_OF_SEPARATE which will initialize the DT
from a board-specific funtion instead of bundling one with U-Boot or as
a separated file. This allows boards like the Raspberry Pi to reuse the
device tree passed from the bootcode.bin and start.elf firmware
files, including the run-time selected device tree overlays.

Signed-off-by: Alex Deymo <deymo@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2017-05-09 20:35:06 -04:00
Simon Glass
cb0eae8cf8 string: Use memcpy() within memmove() when we can
A common use of memmove() can be handled by memcpy(). Also memcpy()
includes an optimisation for large sizes: it copies a word at a time. So
we can get a speed-up by calling memcpy() to handle our move in this case.

Update memmove() to call memcpy() if the destination is before the source.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
2017-05-09 20:19:04 -04:00
xypron.glpk@gmx.de
05d887b461 lib: circbuf: avoid possible null pointer dereference
We should not first dereference p and afterwards assert that is
was not NULL. Instead do the assert first.

The problem was indicated by cppcheck.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2017-05-05 16:45:57 -04:00
Simon Glass
b1a873df0a Convert CONFIG_CMD_AES et al to Kconfig
This converts the following to Kconfig:
   CONFIG_CMD_AES
   CONFIG_AES

Signed-off-by: Simon Glass <sjg@chromium.org>
[trini: Add select AES to CMD_AES]
Signed-off-by: Tom Rini <trini@konsulko.com>
2017-04-30 10:29:55 -04:00
Tom Rini
c1a16c3ab5 Merge branch 'master' of git://git.denx.de/u-boot-socfpga 2017-04-14 09:05:57 -04:00
Ley Foon Tan
e11b5e8d6e fdt: Add compatible strings for Arria 10
Add compatible strings for Intel Arria 10 SoCFPGA device.

Signed-off-by: Tien Fong Chee <tien.fong.chee@intel.com>
Signed-off-by: Ley Foon Tan <ley.foon.tan@intel.com>
2017-04-14 14:06:55 +02:00
Tom Rini
b7b24a7a3c Merge git://git.denx.de/u-boot-dm
Here with some DM changes as well as the long-standing AT91 DM/DT
conversion patches which I have picked up via dm.
2017-04-13 17:31:06 -04:00
Simon Glass
c47a38b477 fdtgrep: Cope with the /aliases node being last
With skeleton.dtsi being dropped it is more likely that the /aliases node
will be last in the device tree. Update fdtgrep to handle this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Tested-by: Masahiro Yamada <yamada.masahiro@socionext.com>
2017-04-13 14:43:31 -06:00
Peng Fan
0342e335ba lib: div64: sync with Linux
Sync with Linux commit ad0376eb1483b ("Merge tag 'edac_for_4.11_2'").

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Tom Rini <trini@konsulko.com>
2017-04-13 09:41:10 -04:00
Vignesh R
cdce1f7620 tiny-printf: Add support for %p format
Add support for %p, %pa[p], %pM, %pm and %pI4 formats to tiny-printf.
%pM and %pI4 are widely used by SPL networking stack and is required if
networking support is desired in SPL.
%p, %pa and %pap are mostly used by debug prints and hence supported
only when DEBUG is enabled.

Before this patch:
$ size spl/u-boot-spl
   text	   data	    bss	    dec	    hex	filename
  99325	   4899	 218584	 322808	  4ecf8	spl/u-boot-spl

After this patch (with CONFIG_SPL_NET_SUPPORT):
$ size spl/u-boot-spl
   text	   data	    bss	    dec	    hex	filename
  99666	   4899	 218584	 323149	  4ee4d	spl/u-boot-spl

So, this patch adds ~350 bytes to code size.

If CONFIG_SPL_NET_SUPPORT is not enabled, this adds ~25 bytes.

If CONFIG_USE_TINY_PRINTF is disabled then:
$ size spl/u-boot-spl
  text	   data	    bss	    dec	    hex	filename
 101116	   4899	 218584	 324599	  4f3f7	spl/u-boot-spl

So, there is still ~1.4K space saved even with support for %pM/%pI4.

Compiler used is to build is:
arm-linux-gnueabihf-gcc (Linaro GCC 6.2-2016.11) 6.2.1 20161016

Signed-off-by: Vignesh R <vigneshr@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2017-04-13 09:41:09 -04:00