platform/kernel/u-boot.git
3 years agox86: apl: Reduce size for TPL
Simon Glass [Wed, 23 Dec 2020 15:11:30 +0000 (08:11 -0700)]
x86: apl: Reduce size for TPL

Update various drivers to use of_match_ptr() and to avoid including debug
strings in TPL. Omit the WiFi driver entirely, since it is not used in
TPL.

This reduces the TPL binary size by about 608 bytes.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agox86: apl: Update hostbridge to remove unwanted TPL code
Simon Glass [Wed, 23 Dec 2020 15:11:29 +0000 (08:11 -0700)]
x86: apl: Update hostbridge to remove unwanted TPL code

At present several strings from this file appear in the TPL binary. Add
preprocessor checks to drop them.

This reduces the TPL binary size by about 128 bytes.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agox86: coral: Move fsp-m settings to a subnode
Simon Glass [Wed, 23 Dec 2020 15:11:28 +0000 (08:11 -0700)]
x86: coral: Move fsp-m settings to a subnode

At present these settings are in the node for host-bridge and so are
visible in TPL as well as SPL. But they are only used for SPL.

Move them to a subnode so that TPL does not included them.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agox86: Move call64 into its own section
Simon Glass [Wed, 23 Dec 2020 15:11:27 +0000 (08:11 -0700)]
x86: Move call64 into its own section

When this code is not used (e.g. by TPL) we want it to be excluded from
the image. Put it in its own section so that this happens.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agox86: apl: Use const for driver operations
Simon Glass [Wed, 23 Dec 2020 15:11:26 +0000 (08:11 -0700)]
x86: apl: Use const for driver operations

Update these declarations to const to ensure that the data ends up in the
rodata section.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodtoc: Convert _drivers to a dict
Simon Glass [Wed, 23 Dec 2020 15:11:23 +0000 (08:11 -0700)]
dtoc: Convert _drivers to a dict

At present this member holds a simple list of driver names. Update it to
be a dict of DriverInfo, with the name being the key. This will allow more
information to be added about each driver, in future patches.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodtoc: Output the struct values in a separate function
Simon Glass [Wed, 23 Dec 2020 15:11:22 +0000 (08:11 -0700)]
dtoc: Output the struct values in a separate function

Reduce the length of output_node() futher by moving the struct-output
functionality into a two separate functions.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodtoc: Output the device in a separate function
Simon Glass [Wed, 23 Dec 2020 15:11:21 +0000 (08:11 -0700)]
dtoc: Output the device in a separate function

Reduce the length of output_node() by moving the device-output
functionality into a separate function.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodtoc: Make _output_list a top-level function
Simon Glass [Wed, 23 Dec 2020 15:11:20 +0000 (08:11 -0700)]
dtoc: Make _output_list a top-level function

It is annoying to have this function inside its parent since it makes the
parent longer and hard to read. Move it to the top level.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodtoc: Fix a few pylint warnings in dtb_platdata
Simon Glass [Wed, 23 Dec 2020 15:11:19 +0000 (08:11 -0700)]
dtoc: Fix a few pylint warnings in dtb_platdata

These have crept in again. Update the file to fix all but these ones:

   dtb_platdata.py:143:0: R0902: Too many instance attributes (10/7)
      (too-many-instance-attributes)
   dtb_platdata.py:713:0: R0913: Too many arguments (6/5)
      (too-many-arguments)

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agotest: Move some test drivers into their own file
Simon Glass [Wed, 23 Dec 2020 15:11:18 +0000 (08:11 -0700)]
test: Move some test drivers into their own file

At present several test drivers are part of the test file itself. Some of
these are useful for of-platdata tests. Separate them out so we can use
them for other things also.

A few adjustments are needed so this driver can build for sandbox_spl as
well.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agotest: Use a simple variable to record removed device
Simon Glass [Wed, 23 Dec 2020 15:11:17 +0000 (08:11 -0700)]
test: Use a simple variable to record removed device

At present the entire test state is effective passed into a test driver
just to record which device was removed. This is unnecessary and makes it
harder to track what is going on.

Use a simple boolean instead.

Also drop the unused 'removed' member while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agotimer: Use a shorter error in TPL
Simon Glass [Wed, 23 Dec 2020 15:11:16 +0000 (08:11 -0700)]
timer: Use a shorter error in TPL

This error should not happen in normal use. Reduce the length of it to
save space in the image.

Add an empty spl.h file to sh since it appears to lack this.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agoarc: m68k: nds32: nios2: sh: xtensa: Add empty spl.h header
Simon Glass [Wed, 23 Dec 2020 15:11:15 +0000 (08:11 -0700)]
arc: m68k: nds32: nios2: sh: xtensa: Add empty spl.h header

At present it is not possible to include spl.h in on these architectures
since the asm/spl.h file is not present. We want to be able to use the
spl_phase() function, so add empty headers to make things build.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agosysreset: Use a shorter error with SPL
Simon Glass [Wed, 23 Dec 2020 15:11:14 +0000 (08:11 -0700)]
sysreset: Use a shorter error with SPL

Use a minimal error message to save space. Sort the header files while we
are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agopinctrl: Drop post_bind() method when not needed
Simon Glass [Wed, 23 Dec 2020 15:11:13 +0000 (08:11 -0700)]
pinctrl: Drop post_bind() method when not needed

This is not used with of-platdata, so remove it in that case.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodm: core: Rename the priv/plat members
Simon Glass [Wed, 23 Dec 2020 02:30:30 +0000 (19:30 -0700)]
dm: core: Rename the priv/plat members

These are supposed to be private to driver model, not accessed by any code
outside. Add a trailing underscore to indicate this.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodm: core: Use access methods for dev/uclass private data
Simon Glass [Wed, 23 Dec 2020 02:30:29 +0000 (19:30 -0700)]
dm: core: Use access methods for dev/uclass private data

Use these functions in the core code as much as possible. With this, there
are only two places where each priv/plat pointer is accessed, one for read
and one for write.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodm: Use access methods for dev/uclass private data
Simon Glass [Wed, 23 Dec 2020 02:30:28 +0000 (19:30 -0700)]
dm: Use access methods for dev/uclass private data

Most drivers use these access methods but a few do not. Update them.

In some cases the access is not permitted, so mark those with a FIXME tag
for the maintainer to check.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Pratyush Yadav <p.yadav@ti.com>
3 years agodm: core: Add functions to set priv/plat
Simon Glass [Wed, 23 Dec 2020 02:30:27 +0000 (19:30 -0700)]
dm: core: Add functions to set priv/plat

This should not normally be needed in drivers, but add accessors for the
few cases that exist.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodm: core: Add function to access uclass priv
Simon Glass [Wed, 23 Dec 2020 02:30:26 +0000 (19:30 -0700)]
dm: core: Add function to access uclass priv

Add functions so this information is not accessed directly. This will be
needed for of-platdata which stores it in a different place.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agox86: apl: Drop support for !OF_PLATDATA_PARENT
Simon Glass [Wed, 23 Dec 2020 02:30:25 +0000 (19:30 -0700)]
x86: apl: Drop support for !OF_PLATDATA_PARENT

This code was kept around after of-platdata started supporting parent
devices. That feature seems stable now, so let's drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodm: core: Only include simple-bus devicetree id when needed
Simon Glass [Wed, 23 Dec 2020 02:30:24 +0000 (19:30 -0700)]
dm: core: Only include simple-bus devicetree id when needed

This is not needed when of-platdata is in use. Update it.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodm: core: Use 'uclass_driver' for the uclass linker_list
Simon Glass [Wed, 23 Dec 2020 02:30:23 +0000 (19:30 -0700)]
dm: core: Use 'uclass_driver' for the uclass linker_list

At present the name 'uclass_driver' is used for the uclass linker list.
This does not follow the convention of using the struct name. Fix it.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodm: core: Support dm_dump_all() in SPL
Simon Glass [Wed, 23 Dec 2020 02:30:22 +0000 (19:30 -0700)]
dm: core: Support dm_dump_all() in SPL

At present the output from this function is hard to read in SPL, due to
(intended) limitations in SPL's printf() function. Add an SPL version so
it is clearer.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agospl: Drop bd_info in the data section
Simon Glass [Wed, 23 Dec 2020 02:30:21 +0000 (19:30 -0700)]
spl: Drop bd_info in the data section

This uses up space in the SPL binary but it always starts as zero. Also
some boards cannot support data in TPL (e.g. Intel Apollo Lake).

Use malloc() to allocate this structure instead, by moving the init a
little later, after malloc() is inited. Make this function optional since
it pulls in malloc().

This reduces the TPL binary size on coral by about 64 bytes

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agosandbox: Drop unnecessary test node
Simon Glass [Wed, 23 Dec 2020 02:30:20 +0000 (19:30 -0700)]
sandbox: Drop unnecessary test node

The spl-test4 node deliberately has an invalid compatible string. This
causes a warning from dtoc and the check it does is not really necessary.
Drop it, to avoid the warning and associated confusion.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agoserial: Rename ns16550 functions to lower case
Simon Glass [Wed, 23 Dec 2020 02:30:19 +0000 (19:30 -0700)]
serial: Rename ns16550 functions to lower case

Lower case should be used for function names. Update this driver and its
callers accordingly.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
3 years agoserial: Update NS16550_t and struct NS16550
Simon Glass [Wed, 23 Dec 2020 02:30:18 +0000 (19:30 -0700)]
serial: Update NS16550_t and struct NS16550

Typedefs should not be used in U-Boot and structs should be lower case.
Update the code to use struct ns16550 consistently.

Put a header guard on the file while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
3 years agoMakefile: Use common args for dtoc
Simon Glass [Wed, 23 Dec 2020 02:30:16 +0000 (19:30 -0700)]
Makefile: Use common args for dtoc

At present the dtoc commmand line is repeated twice in the Makefile. Use a
variable to avoid this, so it is easier to add more conditional arguments.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agoMakefile: Tidy up SPL dtb production
Simon Glass [Wed, 23 Dec 2020 02:30:15 +0000 (19:30 -0700)]
Makefile: Tidy up SPL dtb production

Use the SPL_NAME variable to simplify the rules. Drop the SPL targets
clean-files since the SPL and TPL dts/ directories are removed by
existing rules. Move the SPL rules into a new spl_dtbs to avoid the
complicated $(if) construct.

Also drop unused pieces from the 'targets' variable.

With this, SPL and TPL have separate dtbs which respect the various
u-boot,dm-spl / u-boot,dm-tpl tags.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agoMakefile: Build SPL dtbs in the spl/ directory
Simon Glass [Wed, 23 Dec 2020 02:30:14 +0000 (19:30 -0700)]
Makefile: Build SPL dtbs in the spl/ directory

Rather than putting these in the top-level dts/ directory (which is
intended for U-Boot proper), put them in the correct subdirectory for
SPL (either spl/ or tpl/). This is where other SPL targets are kept,
so this is more consistent.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agoMakefile: Build a separate .dtb for TPL
Simon Glass [Wed, 23 Dec 2020 02:30:13 +0000 (19:30 -0700)]
Makefile: Build a separate .dtb for TPL

At present both SPL and TPL use the same devicetree binary. While there
is logic to run fdtgrep separately on each one, it does not actually
happen.

Add a new TPL rule and use that instead. Make this rule conditional on
there actually being a TPL. Do the same for SPL for consistency.

Note that the SPL and TPL dtbs are build by a Makefule rule used for
U-Boot proper. This is the 'dtbs' target in dts/Makefile. So the check
for CONFIG_TPL_BUILD in cmd_fdtgrep never actually works at present.

We don't support CONFIG_OF_EMBED for TPL at present.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agoMerge tag 'efi-next' of https://gitlab.denx.de/u-boot/custodians/u-boot-efi into...
Tom Rini [Fri, 1 Jan 2021 03:28:09 +0000 (22:28 -0500)]
Merge tag 'efi-next' of https://gitlab.denx.de/u-boot/custodians/u-boot-efi into next

Pull request for UEFI sub-system for next

* UEFI capsule authentication
* UEFI capsule update on QEMU ARM
* fsuuid command for FAT file system
* bug fixes

3 years agoqemu: arm64: Add documentation for capsule update
Sughosh Ganu [Wed, 30 Dec 2020 13:57:12 +0000 (19:27 +0530)]
qemu: arm64: Add documentation for capsule update

Add documentation highlighting the steps for using the uefi capsule
update feature for updating the u-boot firmware image.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
3 years agoefidebug: capsule: Add a command to update capsule on disk
Sughosh Ganu [Wed, 30 Dec 2020 13:57:11 +0000 (19:27 +0530)]
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>
3 years agoefi_loader: Enable uefi capsule authentication
Sughosh Ganu [Wed, 30 Dec 2020 13:57:10 +0000 (19:27 +0530)]
efi_loader: Enable uefi capsule authentication

Add support for enabling uefi capsule authentication. This feature is
enabled by setting the environment variable
"capsule_authentication_enabled".

The following configs are needed for enabling uefi capsule update and
capsule authentication features on the platform.

CONFIG_EFI_HAVE_CAPSULE_SUPPORT=y
CONFIG_EFI_CAPSULE_ON_DISK=y
CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT=y
CONFIG_EFI_CAPSULE_FIRMWARE=y
CONFIG_EFI_CAPSULE_FIRMWARE_RAW=y
CONFIG_EFI_CAPSULE_AUTHENTICATE=y

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
3 years agoefi: capsule: Add support for uefi capsule authentication
Sughosh Ganu [Wed, 30 Dec 2020 13:57:09 +0000 (19:27 +0530)]
efi: capsule: Add support for uefi capsule authentication

Add support for authenticating uefi capsules. Most of the signature
verification functionality is shared with the uefi secure boot
feature.

The root certificate containing the public key used for the signature
verification is stored as part of the device tree blob. The root
certificate is stored as an efi signature list(esl) file -- this file
contains the x509 certificate which is the root certificate.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
3 years agoefi_loader: Re-factor code to build the signature store from efi signature list
Sughosh Ganu [Wed, 30 Dec 2020 13:57:08 +0000 (19:27 +0530)]
efi_loader: Re-factor code to build the signature store from efi signature list

The efi_sigstore_parse_sigdb function reads the uefi authenticated
variable, stored in the signature database format and builds the
signature store structure. Factor out the code for building
the signature store. This can then be used by the capsule
authentication routine to build the signature store even when the
signature database is not stored as an uefi authenticated variable

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
3 years agoefi_loader: Make the pkcs7 header parsing function an extern
Sughosh Ganu [Wed, 30 Dec 2020 13:57:07 +0000 (19:27 +0530)]
efi_loader: Make the pkcs7 header parsing function an extern

The pkcs7 header parsing functionality is pretty generic, and can be
used by other features like capsule authentication. Make the function
an extern, also changing it's name to efi_parse_pkcs7_header

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
3 years agodfu_mtd: Add provision to unlock mtd device
Sughosh Ganu [Wed, 30 Dec 2020 13:57:06 +0000 (19:27 +0530)]
dfu_mtd: Add provision to unlock mtd device

Prior to writing to an mtd device, mtd_erase is called. This call
fails in case the sector being erased is locked. Call mtd_unlock to
unlock the region which is to be erased and later written to. Lock the
region once the write to the region has completed.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
3 years agoefi_loader: Add logic to parse EDKII specific fmp payload header
Sughosh Ganu [Wed, 30 Dec 2020 13:57:05 +0000 (19:27 +0530)]
efi_loader: Add logic to parse EDKII specific fmp payload header

When building the capsule using scripts in edk2, a fmp header is
added on top of the binary payload. Add logic to detect presence of
the header. When present, the pointer to the image needs to be
adjusted as per the size of the header to point to the actual binary
payload.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
3 years agofsp: Move and rename fsp_types.h file
Sughosh Ganu [Wed, 30 Dec 2020 13:57:04 +0000 (19:27 +0530)]
fsp: Move and rename fsp_types.h file

The fsp_types.h header file contains macros for building signatures of
different widths. These signature macros are architecture agnostic,
and can be used in all places which use signatures in a data
structure. Move and rename the fsp_types.h under the common include
header.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
3 years agoqemu: common: Set dfu_alt_info variable for the platform
Sughosh Ganu [Wed, 30 Dec 2020 13:57:03 +0000 (19:27 +0530)]
qemu: common: Set dfu_alt_info variable for the platform

The dfu framework uses the dfu_alt_info environment variable to get
information that is needed for performing the firmware update. Add
logic to set the dfu_alt_info for the qemu arm64 platform to reflect
the two mtd partitions created for the u-boot env and the firmware
image. This can be subsequently extended for other qemu architectures
which need this variable set.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
3 years agoqemu: common: Add support for dynamic mtdparts for the platform
Sughosh Ganu [Wed, 30 Dec 2020 13:57:02 +0000 (19:27 +0530)]
qemu: common: Add support for dynamic mtdparts for the platform

Add support for setting the default values for mtd partitions on the
platform. This would be used for updating the firmware image using
uefi capsule update with the dfu mtd backend driver.

Currently, values have been defined for the qemu arm64 platform, with
default values defined for the mtd partitions based on the NOR
flash. This can be subsequently extended for other qemu architectures
which need mtdparts set.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
3 years agocrypto: Fix the logic to calculate hash with authattributes set
Sughosh Ganu [Wed, 30 Dec 2020 13:57:01 +0000 (19:27 +0530)]
crypto: Fix the logic to calculate hash with authattributes set

RFC 2315 Section 9.3 describes the message digesting process. The
digest calculated depends on whether the authenticated attributes are
present. In case of a scenario where the authenticated attributes are
present, the message digest that gets signed and is part of the pkcs7
message is computed from the auth attributes rather than the contents
field.

Check if the auth attributes are present, and if set, use the auth
attributes to compute the hash that would be compared with the
encrypted hash on the pkcs7 message.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
3 years agoqemu: arm: Initialise virtio devices in board_late_init
Sughosh Ganu [Wed, 30 Dec 2020 13:57:00 +0000 (19:27 +0530)]
qemu: arm: Initialise virtio devices in board_late_init

On the qemu arm platform, the virtio devices are initialised in the
board_init function, which gets called before the initr_pci. With
this sequence, the virtio block devices on the pci bus are not
initialised. Move the initialisation of the virtio devices to
board_late_init which gets called after the call to initr_pci.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
3 years agomkeficapsule: Add support for embedding public key in a dtb
Sughosh Ganu [Wed, 30 Dec 2020 13:56:59 +0000 (19:26 +0530)]
mkeficapsule: Add support for embedding public key in a dtb

Add options for embedding the public key esl(efi signature list) file
to the platform's dtb. The esl file is then retrieved and used for
authenticating the capsule to be used for updating firmare components
on the platform.

The esl file can now be embedded in the dtb by invoking the following
command
mkeficapsule -K <pub_key.esl> -D <dtb>

In the scenario where the esl file is to be embedded in an overlay,
this can be done through the following command
mkeficapsule -O -K <pub_key.esl> -D <dtb>

This will create a node named 'signature' in the dtb, and the esl file
will be stored as 'capsule-key'

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
3 years agoefi_loader: event queueing
Heinrich Schuchardt [Sun, 27 Dec 2020 23:25:34 +0000 (00:25 +0100)]
efi_loader: event queueing

When a new event is queued we have to process the event queue by calling
efi_process_event_queue(). But there is not reason to call the function
when the event is not queueable.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
3 years agoefi_loader: Add size checks to efi_create_indexed_name()
Ilias Apalodimas [Thu, 31 Dec 2020 10:26:46 +0000 (12:26 +0200)]
efi_loader: Add size checks to efi_create_indexed_name()

Although the function description states the caller must provide a
sufficient buffer, it's better to have in function checks that the
destination buffer can hold the intended value.

So let's add an extra argument with the buffer size and check that
before doing any copying.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
3 years agoefi_loader: Remove unconditional installation of file2 protocol for initrd
Ilias Apalodimas [Wed, 30 Dec 2020 15:07:14 +0000 (17:07 +0200)]
efi_loader: Remove unconditional installation of file2 protocol for initrd

Up to now we install the EFI_LOAD_FILE2_PROTOCOL to load an initrd
unconditionally. Although we correctly return various EFI exit codes
depending on the file status (i.e EFI_NO_MEDIA, EFI_NOT_FOUND etc), the
kernel loader only falls back to the cmdline interpreted initrd if the
protocol is not installed.

This creates a problem for EFI installers, since they won't be able to
load their own initrd and start the installation.

A following patch introduces a different logic where we search for an
initrd path defined in an EFI variable named 'Initrd####'.
If the bootmgr is used to launch the EFI payload, we'll will try to match
the BootCurrent value and find the corresponding initrd
(i.e Boot0000 -> Initrd0000 etc). If the file is found, we'll install
the required protocol which the kernel's efi-stub can use and load our
initrd.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
3 years agoefi_loader: Remove unused headers from efi_load_initrd.c
Ilias Apalodimas [Thu, 31 Dec 2020 10:33:23 +0000 (12:33 +0200)]
efi_loader: Remove unused headers from efi_load_initrd.c

dm.h and env.h serve no purpose here. Remove them and sort the
remaining in alphabetical order.

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
3 years agoefi_loader: use after free in efi_exit()
Heinrich Schuchardt [Mon, 28 Dec 2020 22:24:40 +0000 (23:24 +0100)]
efi_loader: use after free in efi_exit()

Do not use data from the loaded image object after deleting it.

Fixes: 126a43f15b36 ("efi_loader: unload applications upon Exit()")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
3 years agoefi_loader: describe struct efi_loaded_image_obj
Heinrich Schuchardt [Mon, 28 Dec 2020 21:42:51 +0000 (22:42 +0100)]
efi_loader: describe struct efi_loaded_image_obj

Add the missing description of some fields of struct efi_loaded_image_obj.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
3 years agoefi_loader: efi_signal_event() fix comment typos
Heinrich Schuchardt [Sun, 27 Dec 2020 23:59:09 +0000 (00:59 +0100)]
efi_loader: efi_signal_event() fix comment typos

Add missing commas.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
3 years agoefi_loader: avoid invalid free
Heinrich Schuchardt [Sun, 27 Dec 2020 14:46:00 +0000 (15:46 +0100)]
efi_loader: avoid invalid free

load_options passed from do_efibootmgr() to do_bootefi_exec() may contain
invalid data from the stack which will lead to an invalid free().

Fixes: 0ad64007feb9 ("efi_loader: set load options in boot manager")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
3 years agoefi_loader: escape key handling
Heinrich Schuchardt [Sun, 27 Dec 2020 13:47:50 +0000 (14:47 +0100)]
efi_loader: escape key handling

Up to now the escape key was not correctly detected in UEFI applications.
We had to hit it twice for a single escape to be recognized.

Use a 10 ms delay to detect if we are dealing with the escape key or an
escape sequence.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
3 years agoefi_loader: missing parentheses after if
Heinrich Schuchardt [Sun, 27 Dec 2020 14:33:09 +0000 (15:33 +0100)]
efi_loader: missing parentheses after if

IS_ENABLED() contains parentheses. But we should still put extra
parentheses around it in an if statement for readability.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
3 years agofs/fat: implement fsuuid command
Heinrich Schuchardt [Wed, 30 Dec 2020 23:38:13 +0000 (00:38 +0100)]
fs/fat: implement fsuuid command

The FAT file system does not have a UUID but a 4 byte volume ID.
Let the fsuuid command show it in XXXX-XXXX format.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
3 years agofs: fat: eliminate DIRENTSPERBLOCK() macro
Heinrich Schuchardt [Fri, 25 Dec 2020 13:30:04 +0000 (14:30 +0100)]
fs: fat: eliminate DIRENTSPERBLOCK() macro

The FAT filesystem implementation uses several marcros referring to a magic
variable name mydata which renders the code less readable. Eliminate one of
them which is only used for a debug() statement.

Use log_debug() instead of debug().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
3 years agoefi_loader: Extra checks while opening an OPTEE session
Ilias Apalodimas [Wed, 23 Dec 2020 11:25:00 +0000 (13:25 +0200)]
efi_loader: Extra checks while opening an OPTEE session

When opening an OP-TEE session we need to check the internal return
value of OP-TEE call arguments as well the return code of the
function itself.
The code was also ignoring to close the OP-TEE session in case the
shared memory registration failed.

Fixes: f042e47e8fb43 ("efi_loader: Implement EFI variable handling via OP-TEE")
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
3 years agoefi_loader: make variable store size customizable
Heinrich Schuchardt [Sun, 20 Dec 2020 10:05:38 +0000 (11:05 +0100)]
efi_loader: make variable store size customizable

Currently the size of the buffer to keep UEFI variables in memory is fixed
at 16384 bytes. This size has proven to be too small for some use cases.

Make the size of the memory buffer for UEFI variables customizable.

Reported-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
3 years agoMerge tag 'dm-next-23dec20' of git://git.denx.de/u-boot-dm into next
Tom Rini [Wed, 23 Dec 2020 23:10:15 +0000 (18:10 -0500)]
Merge tag 'dm-next-23dec20' of git://git.denx.de/u-boot-dm into next

dm: New sequence number implementation
SPI handling of bus with different-speed devices
patman supression of sign-offs

3 years agodm: core: Inline a few ofnode functions in SPL
Simon Glass [Thu, 17 Dec 2020 00:25:06 +0000 (17:25 -0700)]
dm: core: Inline a few ofnode functions in SPL

A recent change to unify the flattree/livetree code introduced a small
size increase in SPL on some boards. For example SPL code size for
px30-core-ctouch2-px30 increased by 40 bytes.

To address this we can take advantage of the fact that some of the ofnode
functions are only called a few times in SPL, so it is worth inlining
them.

Add new Kconfig options to control this. These functions are not inlined
for U-Boot proper, since this increases code size.

Fixes: 2ebea5eaebf ("dm: core: Combine the flattree and livetree binding code")
Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agobuildman: Remove output binaries before building
Simon Glass [Thu, 17 Dec 2020 00:24:17 +0000 (17:24 -0700)]
buildman: Remove output binaries before building

Buildman reuses build directories from previous builds to avoid the cost
of 'make mrproper' for every build. If the previous build produced an SPL
image but the current one does not, the SPL image will remain and buildman
will think it is a result of building the current board.

Remove these files before building, to avoid this problem.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodm: spi: Fix spi_free_slave() freed memory write
Niel Fourie [Wed, 16 Dec 2020 11:11:52 +0000 (12:11 +0100)]
dm: spi: Fix spi_free_slave() freed memory write

Remove setting slave->dev to NULL after the device_remove() call.

The slave pointer points to dev->parent_priv, which has already
been freed by device_free(), called from device_remove() in the
preceding line. Writing to slave->dev may cause corruption of the
dlmalloc free chunk forward pointer of the previously freed chunk.

Signed-off-by: Niel Fourie <lusus@denx.de>
Cc: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
3 years agotest: dm: spi: Add testcase for spi_claim_bus()
Ovidiu Panait [Mon, 14 Dec 2020 17:06:51 +0000 (19:06 +0200)]
test: dm: spi: Add testcase for spi_claim_bus()

Add testcase for spi_claim_bus(), which checks that sandbox spi bus
speed/mode settings are updated correctly when multiple slaves use
the bus consecutively. The following configurations are used for the
two spi slaves involved:
  * different max_hz / different modes
  * different max_hz / same modes
  * different modes / same max_hz

asm/test.h header is added in order to be able to retrieve the current
speed/mode of the sandbox spi bus, via sandbox_spi_get_{speed, mode}.

Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
3 years agospi: spi-uclass: Fix spi_claim_bus() speed/mode setup logic
Ovidiu Panait [Mon, 14 Dec 2020 17:06:50 +0000 (19:06 +0200)]
spi: spi-uclass: Fix spi_claim_bus() speed/mode setup logic

Currently, when different spi slaves claim the bus consecutively using
spi_claim_bus(), spi_set_speed_mode() will only be executed on the first
two calls, leaving the bus in a bad state starting with the third call.

This patch drops spi_slave->speed member and adds caching of bus
speed/mode in dm_spi_bus struct. It also updates spi_claim_bus() to call
spi_set_speed_mode() if either speed or mode is different from what the
bus is currently configured for. Current behavior is to only take into
account the speed, but not the mode, which seems wrong.

Fixes: 60e2809a848 ("dm: spi: Avoid setting the speed with every transfer")
Reviewed-by: Simon Glass <sjg@chromium.org>
Reported-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reported-by: Moshe, Yaniv <yanivmo@amazon.com>
Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
3 years agotest: spi: Add sandbox_spi_get_{speed, mode} interface
Ovidiu Panait [Mon, 14 Dec 2020 17:06:49 +0000 (19:06 +0200)]
test: spi: Add sandbox_spi_get_{speed, mode} interface

Introduce sandbox_spi_get_{speed, mode} public interface to retrieve the
sandbox spi bus internal state. They are meant to be used in sandbox spi
testcases.

Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
3 years agospi: sandbox_spi: Implement speed/mode setup
Ovidiu Panait [Mon, 14 Dec 2020 17:06:48 +0000 (19:06 +0200)]
spi: sandbox_spi: Implement speed/mode setup

Implement sandbox_spi_set_{speed, mode} routines, to be able to keep track
of the current bus speed/mode. This will help determine whether the values
passed from dm_spi_claim_bus() are valid.

Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
3 years agosandbox: test: Add a second SPI slave on sandbox_spi bus
Ovidiu Panait [Mon, 14 Dec 2020 17:06:47 +0000 (19:06 +0200)]
sandbox: test: Add a second SPI slave on sandbox_spi bus

Place a second spi slave on the sandbox_spi bus, to be used by the
spi_claim_bus() testcase we are about to introduce. We need to make sure
that jumping between slaves calling spi_claim_bus() sets the bus speed and
mode appropriately. Use different max-hz and mode properties for this new
slave.

Also, update sandbox_spi cs_info call to allow activity on CS0/CS1 and
adapt dm_test_spi_find() testcase for this new setup.

Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
3 years agosandbox: spi: Drop unused sandbox_spi_parse_spec function
Ovidiu Panait [Mon, 14 Dec 2020 17:06:46 +0000 (19:06 +0200)]
sandbox: spi: Drop unused sandbox_spi_parse_spec function

Commit 1289e96797bf ("sandbox: spi: Drop command-line SPI option") dropped
support for specifying SPI devices on the command line, removing the only
user of sandbox_spi_parse_spec(). Remove the function too.

Fixes: 1289e96797bf ("sandbox: spi: Drop command-line SPI option")
Signed-off-by: Ovidiu Panait <ovidiu.panait@windriver.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
3 years agosandbox: implement invalidate_icache_all()
Heinrich Schuchardt [Wed, 9 Dec 2020 18:42:44 +0000 (19:42 +0100)]
sandbox: implement invalidate_icache_all()

Before executing code that we have loaded from a file we need to flush the
data cache and invalidate the instruction flash.

Implement functions flush_cache() and invalidate_icache_all().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
3 years agofdt: Use phandle to distinguish DT nodes with same name
Aswath Govindraju [Thu, 3 Dec 2020 05:25:45 +0000 (10:55 +0530)]
fdt: Use phandle to distinguish DT nodes with same name

While assigning the sequence number to subsystem instances by reading the
aliases property, only DT nodes names are compared and not the complete
path. This causes a problem when there are two DT nodes with same name but
have different paths.

In arch/arm/dts/k3-am65-main.dtsi there are two USB controllers with the
same device tree node name but different path. When aliases are defined for
these USB controllers then fdtdec_get_alias_seq() fails to pick the correct
instance for a given index.

fdt_path_offset() function is slow and this would effect the U-Boot
startup. To avert the time penalty on all boards, apply this extra check
only when required by using a config option.

Fix it by comparing the phandles of DT nodes after the node names match,
under a config option.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Fix whitespace error in Kconfig:
Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agoCommon:fdt: Check for error return value
Hongwei Zhang [Wed, 2 Dec 2020 19:47:03 +0000 (14:47 -0500)]
Common:fdt: Check for error return value

Check for negative return value of fdt_noffset from calling
boot_get_fdt_fit().

Signed-off-by: Hongwei Zhang <hongweiz@ami.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
3 years agosandbox: implement runtime system reset
Heinrich Schuchardt [Wed, 2 Dec 2020 15:22:11 +0000 (16:22 +0100)]
sandbox: implement runtime system reset

Implement a reset function that we can call after ExitBootServices(),
when all driver model devices are gone.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
3 years agoconfigs: sandbox: activate DEBUG_UART
Patrick Delaunay [Fri, 27 Nov 2020 10:49:29 +0000 (11:49 +0100)]
configs: sandbox: activate DEBUG_UART

Add CONFIG_DEBUG_UART=y for all sandbox defconfig
as it is already done in sandbox_defconfig.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
3 years agopatman: Add project-default for 'gcc'
Philipp Tomsich [Tue, 24 Nov 2020 17:14:53 +0000 (18:14 +0100)]
patman: Add project-default for 'gcc'

Add defaults for FSF/GNU projects, such as gcc, that provide sensible
settings for those projects.

Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
Reviewed-by: Simon Glass <sjg@chromium.org>
3 years agopatman: Add --no-signoff to suppress adding signoffs
Philipp Tomsich [Tue, 24 Nov 2020 17:14:52 +0000 (18:14 +0100)]
patman: Add --no-signoff to suppress adding signoffs

To enable use of patman with FSF/GNU projects, such as GCC or
Binutils, no Signed-off-by may be added.  This adds a command
line flag '--no-signoff' to suppress adding signoffs in patman
when processing commits.

Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
Reviewed-by: Simon Glass <sjg@chromium.org>
Fix patman testBranch() test:
Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodm: Update documentation for new sequence numbers
Simon Glass [Thu, 17 Dec 2020 04:20:33 +0000 (21:20 -0700)]
dm: Update documentation for new sequence numbers

Update the driver model documention to describe how sequence numbers now
work.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodm: core: Drop seq and req_seq
Simon Glass [Thu, 17 Dec 2020 04:20:32 +0000 (21:20 -0700)]
dm: core: Drop seq and req_seq

Now that migration to the new sequence numbers is complete, drop the old
fields. Add a test that covers the new behaviour.

Also drop the check for OF_PRIOR_STAGE since we always assign sequence
numbers now.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agocmd: Drop use of old sequence numbers in commands
Simon Glass [Thu, 17 Dec 2020 04:20:31 +0000 (21:20 -0700)]
cmd: Drop use of old sequence numbers in commands

Several commands use sequence numbers. Update them to use the new ones.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodm: core: Update uclass_find_next_free_req_seq() for new scheme
Simon Glass [Thu, 17 Dec 2020 04:20:30 +0000 (21:20 -0700)]
dm: core: Update uclass_find_next_free_req_seq() for new scheme

This function current deals with req_seq which is deprecated. Update it to
use the new sequence numbers, putting them above existing aliases. Rename
the function to make this clear.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodm: Drop the unused arg in uclass_find_device_by_seq()
Simon Glass [Thu, 17 Dec 2020 04:20:29 +0000 (21:20 -0700)]
dm: Drop the unused arg in uclass_find_device_by_seq()

Now that there is only one sequence number (rather than both requested and
assigned ones) we can simplify this function. Also update its caller to
simplify the logic.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodm: Drop uclass_resolve_seq()
Simon Glass [Thu, 17 Dec 2020 04:20:28 +0000 (21:20 -0700)]
dm: Drop uclass_resolve_seq()

This function is not needed anymore. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodm: test: Add a test for DM_UC_FLAG_NO_AUTO_SEQ
Simon Glass [Thu, 17 Dec 2020 04:20:27 +0000 (21:20 -0700)]
dm: test: Add a test for DM_UC_FLAG_NO_AUTO_SEQ

Check that this flag operates as expected. This patch is not earlier in
this series since is uses the new behaviour of dev_seq().

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodm: Switch over to use new sequence number for dev_seq()
Simon Glass [Thu, 17 Dec 2020 04:20:26 +0000 (21:20 -0700)]
dm: Switch over to use new sequence number for dev_seq()

Update this function to use the new sequence number and fix up the test
that deals with this.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agopinctrl: Update for new sequence numbers
Simon Glass [Thu, 17 Dec 2020 04:20:25 +0000 (21:20 -0700)]
pinctrl: Update for new sequence numbers

Use the dev_seq() sequence number in all cases.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agogpio: Update for new sequence numbers
Simon Glass [Thu, 17 Dec 2020 04:20:24 +0000 (21:20 -0700)]
gpio: Update for new sequence numbers

Use the dev_seq() sequence number in all cases.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agox86: Simplify acpi_device_infer_name()
Simon Glass [Thu, 17 Dec 2020 04:20:23 +0000 (21:20 -0700)]
x86: Simplify acpi_device_infer_name()

There is no-longer any need to check if sequence numbers are valid, since
this is ensured by driver model. Drop the unwanted logic.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agox86: Drop unnecessary mp_init logic
Simon Glass [Thu, 17 Dec 2020 04:20:22 +0000 (21:20 -0700)]
x86: Drop unnecessary mp_init logic

Now that sequence numbers are set up when devices are bound, this code is
not needed. Also, we should use dev_seq() instead of req_seq. Update the
whole file accordingly.

Also fix up APL cpu while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agousb: Update for new sequence numbers
Simon Glass [Thu, 17 Dec 2020 04:20:21 +0000 (21:20 -0700)]
usb: Update for new sequence numbers

Use the new sequence number in all cases. Since all devices are assigned
a number when bound, this hack should not be needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agousb: ehci-mx6: Drop assignment of sequence number
Simon Glass [Thu, 17 Dec 2020 04:20:20 +0000 (21:20 -0700)]
usb: ehci-mx6: Drop assignment of sequence number

This hack cannot work in the new sequence-numbering scheme. Remove it
while we wait for the maintainer to complete DM conversion as noted in
the existing comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agospi: Update for new sequence numbers
Simon Glass [Thu, 17 Dec 2020 04:20:19 +0000 (21:20 -0700)]
spi: Update for new sequence numbers

Use the new sequence number in all cases. Drop the rockchip case because
the sequence number should be 0 anyway, and assigning to the sequence
number is not permitted.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agopci: Update to use new sequence numbers
Simon Glass [Thu, 17 Dec 2020 04:20:18 +0000 (21:20 -0700)]
pci: Update to use new sequence numbers

Now that we know the sequence number at bind time, there is no need for
special-case code in dm_pci_hose_probe_bus().

Note: the PCI_CAP_ID_EA code may need a look, but there are no test
failures so I have left it as is.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodm: core: Allow manual sequence numbering
Simon Glass [Thu, 17 Dec 2020 04:20:17 +0000 (21:20 -0700)]
dm: core: Allow manual sequence numbering

Some buses have their own rules which require assigning sequence numbers
with a bus-specific algorithm. For example, PCI requires that sub-buses
are numbered higher than their parent buses, meaning effectively that
parent buses must be numbered only after all of their child buses have
been numbered.

Add a uclass flag to indicate that driver model should not assign sequence
numbers. In this case, the uclass must do it.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agonet: Update to use new sequence numbers
Simon Glass [Thu, 17 Dec 2020 04:20:16 +0000 (21:20 -0700)]
net: Update to use new sequence numbers

Checking for seq == -1 is effectively checking that the device is
activated. The new sequence numbers are never -1 for a bound device, so
update the check.

Also drop the note about valid sequence numbers so it is accurate with the
new approach.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agoi2c: Update for new sequence numbers
Simon Glass [Thu, 17 Dec 2020 04:20:15 +0000 (21:20 -0700)]
i2c: Update for new sequence numbers

Use the new sequence number in all cases. Drop the logic to check for a
valid number in designware_i2c, since it will always be valid.

Also drop the numbering in the uclass, since we can rely on driver
model giving us the right sequence numbers.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agoocteon: Don't attempt to set the sequence number
Simon Glass [Thu, 17 Dec 2020 04:20:14 +0000 (21:20 -0700)]
octeon: Don't attempt to set the sequence number

Several Octeon drivers operate by setting the sequence number of their
device. This should not be needed with the new sequence number setup. Also
it is not permitted. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>
3 years agodm: test: Drop assumptions of no sequence numbers
Simon Glass [Thu, 17 Dec 2020 04:20:13 +0000 (21:20 -0700)]
dm: test: Drop assumptions of no sequence numbers

Drop code in a few tests which assumes that sequence numbers are only
valid when a device is probed.

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