summaryrefslogtreecommitdiffstats
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
...
* acpi: Add a function to get a device path and scopeSimon Glass2020-07-172-0/+84
| | | | | | | | | Add a function to build up the ACPI path for a device and another for its scope. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
* timer: Allow delays with a 32-bit microsecond timerSimon Glass2020-07-171-0/+5
| | | | | | | | | | | The current get_timer_us() uses 64-bit arithmetic on 32-bit machines. When implementing microsecond-level timeouts, 32-bits is plenty. Add a new function that uses an unsigned long. On 64-bit machines this is still 64-bit, but this doesn't introduce a penalty. On 32-bit machines it is more efficient. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
* efi_loader: pre-seed UEFI variablesHeinrich Schuchardt2020-07-165-10/+63
| | | | | | | | Include a file with the initial values for non-volatile UEFI variables into the U-Boot binary. If this variable is set, changes to variable PK will not be allowed. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: identify PK, KEK, db, dbx correctlyHeinrich Schuchardt2020-07-162-13/+41
| | | | | | | | | | To determine if a varible is on the of the authentication variables PK, KEK, db, dbx we have to check both the name and the GUID. Provide a function converting the variable-name/guid pair to an enum and use it consistently. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: configuration of variables storeHeinrich Schuchardt2020-07-161-12/+18
| | | | | | | The file based and the OP-TEE based UEFI variable store are mutually exclusive. Define them as choice options in Kconfig. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: update secure stateHeinrich Schuchardt2020-07-161-0/+10
| | | | | | | | Update the UEFI secure state when variable 'PK' is updated in the TEE variables implementation. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
* efi_loader: restructure code for TEE variablesHeinrich Schuchardt2020-07-162-159/+155
| | | | | | | When using secure boot functions needed both for file and TEE based UEFI variables have to be moved to the common code module efi_var_common.c. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: display RO attribute with TEE-backed variablesIlias Apalodimas2020-07-161-6/+136
| | | | | | | | A previous commit adds support for displaying variables RO flag. Let's add it on the TEE backed variable storage as well. Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_selftest: adjust runtime test for variablesHeinrich Schuchardt2020-07-111-7/+6
| | | | | | | As variable services are available at runtime we have to expect EFI_SUCCESS when calling the services. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: enable UEFI variables at runtimeHeinrich Schuchardt2020-07-113-5/+17
| | | | | | Enable UEFI variables at runtime. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: use memory based variable storageHeinrich Schuchardt2020-07-111-468/+94
| | | | | | | | | Saving UEFI variable as encoded U-Boot environment variables does not allow implement run-time support. Use a memory buffer for storing UEFI variables. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: memory buffer for variablesHeinrich Schuchardt2020-07-112-0/+267
| | | | | | | | | Saving UEFI variable as encoded U-Boot environment variables does not allow support at runtime. Provide functions to manage a memory buffer with UEFI variables. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: new function efi_memcpy_runtime()Heinrich Schuchardt2020-07-111-0/+19
| | | | | | Provide a memcpy() function that we can use at UEFI runtime. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: optional pointer for ConvertPointerHeinrich Schuchardt2020-07-111-0/+6
| | | | | | | If the EFI_OPTIONAL_PTR is set in DebugDisposition, a NULL pointer does not constitute an invalid parameter. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: export efi_convert_pointer()Heinrich Schuchardt2020-07-111-5/+3
| | | | | | | | | | We need ConvertPointer() to adjust pointers when implementing runtime services within U-Boot. After ExitBootServices() gd is not available anymore. So we should not use EFI_ENTRY() and EFI_EXIT(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: UEFI variable persistenceHeinrich Schuchardt2020-07-114-1/+257
| | | | | | | | | | | | Persist non-volatile UEFI variables in a file on the EFI system partition. The file is written whenever a non-volatile UEFI variable is changed after initialization of the UEFI sub-system. The file is read during the UEFI sub-system initialization to restore non-volatile UEFI variables. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: secure boot flagHeinrich Schuchardt2020-07-111-6/+2
| | | | | | | | | In audit mode the UEFI variable SecureBoot is set to zero but the efi_secure_boot flag is set to true. The efi_secure_boot flag should match the UEFIvariable SecureBoot. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: read-only AuditMode and DeployedModeHeinrich Schuchardt2020-07-111-9/+13
| | | | | | | Set the read only property of the UEFI variables AuditMode and DeployedMode conforming to the UEFI specification. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: value of VendorKeysHeinrich Schuchardt2020-07-111-60/+15
| | | | | | | | | | According to the UEFI specification the variable VendorKeys is 1 if the "system is configured to use only vendor-provided keys". As we do not supply any vendor keys yet the variable VendorKeys must be zero. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: keep attributes in efi_set_variable_intHeinrich Schuchardt2020-07-111-12/+12
| | | | | | | | | | Do not change the value of parameter attributes in function efi_set_variable_int(). This allows to use it later. Do not use variable attr for different purposes but declare separate variables (attr and old_attr). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: simplify boot managerHeinrich Schuchardt2020-07-111-16/+12
| | | | | | | | | Simplify the implementation of the UEFI boot manager: * avoid EFI_CALL for SetVariable() and GetVariable() * remove unnecessary type conversions Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: OsIndicationsSupported, PlatformLangCodesHeinrich Schuchardt2020-07-111-28/+31
| | | | | | | | | UEFI variables OsIndicationsSupported, PlatformLangCodes should be read only. Avoid EFI_CALL() for SetVariable(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: separate UEFI variable API from implemementationHeinrich Schuchardt2020-07-113-79/+94
| | | | | | | Separate the remaining UEFI variable API functions GetNextVariableName and QueryVariableInfo() from internal functions implementing them. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: prepare for read only OP-TEE variablesHeinrich Schuchardt2020-07-114-181/+148
| | | | | | | | | | | | | | | | | | We currently have two implementations of UEFI variables: * variables provided via an OP-TEE module * variables stored in the U-Boot environment Read only variables are up to now only implemented in the U-Boot environment implementation. Provide a common interface for both implementations that allows handling read-only variables. As variable access is limited to very few source files put variable related definitions into new include efi_variable.h instead of efi_loader. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: NULL dereference in efi_convert_pointerHeinrich Schuchardt2020-07-111-1/+2
| | | | | | Avoid a possible NULL pointer dereference in efi_convert_pointer(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: fix efi_get_child_controllers()Heinrich Schuchardt2020-07-111-4/+8
| | | | | | | Don't call calloc(0, ..). Consider return value of efi_get_child_controllers(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: wrong printf format in efi_image_parseHeinrich Schuchardt2020-07-111-1/+1
| | | | | | | | | | | | | | | | | Commit 1b6c08548c85 ("efi_loader: image_loader: replace debug to EFI_PRINT") leads to a build warning on 32bit systems: lib/efi_loader/efi_image_loader.c: In function ‘efi_image_parse’: include/efi_loader.h:123:8: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 8 has type ‘size_t’ {aka ‘unsigned int’} [-Wformat=] Use %zu for printing size_t. Fixes: 1b6c08548c85 ("efi_loader: image_loader: replace debug to EFI_PRINT") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: cleanup for tee backed variablesIlias Apalodimas2020-07-111-5/+3
| | | | | | | | | There's 2 variables in efi_get_next_variable_name() checking the size of the variable name. Let's get rid of the reduntant definition and simplitfy the code a bit. Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* lib: rsa: export rsa_verify_with_pkey()AKASHI Takahiro2020-07-111-4/+4
| | | | | | | | | This function will be used to implement public_key_verify_signature() in a later patch. rsa_verify() is not suitable here because calculation of message digest is not necessary. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: image_loader: add digest-based verification for signed imageAKASHI Takahiro2020-07-112-75/+97
| | | | | | | | | | | | | | | In case that a type of certificate in "db" or "dbx" is EFI_CERT_X509_SHA256_GUID, it is actually not a certificate which contains a public key for RSA decryption, but a digest of image to be loaded. If the value matches to a value calculated from a given binary image, it is granted for loading. With this patch, common digest check code, which used to be used for unsigned image verification, will be extracted from efi_signature_verify_with_sigdb() into efi_signature_lookup_digest(), and extra step for digest check will be added to efi_image_authenticate(). Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
* efi_loader: image_loader: verification for all signatures should passAKASHI Takahiro2020-07-112-150/+191
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | A signed image may have multiple signatures in - each WIN_CERTIFICATE in authenticode, and/or - each SignerInfo in pkcs7 SignedData (of WIN_CERTIFICATE) In the initial implementation of efi_image_authenticate(), the criteria of verification check for multiple signatures case is a bit ambiguous and it may cause inconsistent result. With this patch, we will make sure that verification check in efi_image_authenticate() should pass against all the signatures. The only exception would be - the case where a digest algorithm used in signature is not supported by U-Boot, or - the case where parsing some portion of authenticode has failed In those cases, we don't know how the signature be handled and should just ignore them. Please note that, due to this change, efi_signature_verify_with_sigdb()'s function prototype will be modified, taking "dbx" as well as "db" instead of outputing a "certificate." If "dbx" is null, the behavior would be the exact same as before. The function's name will be changed to efi_signature_verify() once current efi_signature_verify() has gone due to further improvement in intermediate certificates support. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
* efi_loader: signature: make efi_hash_regions more genericAKASHI Takahiro2020-07-111-29/+17
| | | | | | | There are a couple of occurrences of hash calculations in which a new efi_hash_regions will be commonly used. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
* efi_loader: signature: fix a size check against revocation listAKASHI Takahiro2020-07-111-2/+3
| | | | | | | | Since the size check against an entry in efi_search_siglist() is incorrect, this function will never find out a to-be-matched certificate and its associated revocation time in the signature list. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
* efi_loader: image_loader: retrieve authenticode only if it existsAKASHI Takahiro2020-07-111-8/+21
| | | | | | | | | Since the certificate table, which is indexed by IMAGE_DIRECTORY_ENTRY_SECURITY and contains authenticode in PE image, doesn't always exist, we should make sure that we will retrieve its pointer only if it exists. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
* efi_loader: image_loader: add a check against certificate type of authenticodeAKASHI Takahiro2020-07-111-12/+44
| | | | | | | | | | | | UEFI specification requires that we shall support three type of certificates of authenticode in PE image: WIN_CERT_TYPE_EFI_GUID with the guid, EFI_CERT_TYPE_PCKS7_GUID WIN_CERT_TYPE_PKCS_SIGNED_DATA WIN_CERT_TYPE_EFI_PKCS1_15 As EDK2 does, we will support the first two that are pkcs7 SignedData. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
* powerpc: move ADDR_MAP to KconfigMarek Szyprowski2020-07-101-0/+13
| | | | | | | | | | | | Move ADDR_MAP related config options from include/configs/*.h to the proper place in lib/Kconfig. This has been done using ./tools/moveconfig.py and manual inspection of the generated changes. This is a preparation to use ADDR_MAP helper on ARM 32bit Raspberry Pi4 board for mapping the PCIe XHCI MMIO, which is above the 4GiB identity mapping limit. Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Reviewed-by: Tom Rini <trini@konsulko.com>
* lib: rsa: function to verify a signature against a hashHeiko Stuebner2020-07-081-24/+32
| | | | | | | | | | | | | rsa_verify() expects a memory region and wants to do the hashing itself, but there may be cases where the hashing is done via other means, like hashing a squashfs rootfs. So add rsa_verify_hash() to allow verifiying a signature against an existing hash. As this entails the same verification routines we can just move the relevant code over from rsa_verify() and also call rsa_verify_hash() from there. Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
* display_options: Drop #ifdef for MEM_SUPPORT_64BIT_DATASimon Glass2020-07-081-14/+4
| | | | | | | | | | | | | | This is defined only when __lp64__ is defined. That means that ulong is 64 bits long. Therefore we don't need to use a separate u64 type on those architectures. Fix up the code to take advantage of that, removing the preprocessor conditions. Also include the missing header file that defines MEM_SUPPORT_64BIT_DATA Fixes: 09140113108 ("command: Remove the cmd_tbl_t typedef") Signed-off-by: Simon Glass <sjg@chromium.org>
* Update MEM_SUPPORT_64BIT_DATA to be always definedSimon Glass2020-07-081-3/+3
| | | | | | | | | | | Define this macro always so we don't need the preprocessor to check it. Convert the users to #if instead of #ifdef. Note that '#if MEM_SUPPORT_64BIT_DATA' does not give an error if the macro is not define. It just assumes zero. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Stefan Roese <sr@denx.de>
* lib: rsa: add documentation to padding_pss_verify to document limitationsHeiko Stuebner2020-07-081-0/+13
| | | | | | | | | | | | padding_pss_verify only works with the default pss salt setting of -2 (length to be automatically determined based on the PSS block structure) not -1 (salt length set to the maximum permissible value), which makes verifications of signatures with that saltlen fail. Until this gets implemented at least document this behaviour. Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* lib: rsa: free local arrays after use in rsa_gen_key_prop()Heiko Stuebner2020-07-081-11/+10
| | | | | | | | | | n, rr and rrtmp are used for internal calculations, but in the end the results are copied into separately allocated elements of the actual key_prop, so the n, rr and rrtmp elements are not used anymore when returning from the function and should of course be freed. Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* lib: rsa: fix allocated size for rr and rrtmp in rsa_gen_key_prop()Heiko Stuebner2020-07-081-5/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | When calculating rrtmp/rr rsa_gen_key_prop() tries to make (((rlen + 31) >> 5) + 1) steps in the rr uint32_t array and (((rlen + 7) >> 3) + 1) / 4 steps in uint32_t rrtmp[] with rlen being num_bits * 2 On a 4096bit key this comes down to to 257 uint32_t elements in rr and 256 elements in rrtmp but with the current allocation rr and rrtmp only have 129 uint32_t elements. On 2048bit keys this works by chance as the defined max_rsa_size=4096 allocates a suitable number of elements, but with an actual 4096bit key this results in other memory parts getting overwritten. So as suggested by Heinrich Schuchardt just use the actual bit-size of the key as base for the size calculation, in turn making the code compatible to any future keysizes. Suggested-by: Heinrich Schuchardt <xypron.debian@gmx.de> Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com> Reviewed-by: Simon Glass <sjg@chromium.org> rrtmp needs 2 + (((*prop)->num_bits * 2) >> 5) array elements. Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* lib: rsa: bring exp_len in line when generating a key_propHeiko Stuebner2020-07-081-1/+1
| | | | | | | | | | | | | | | | The exponent field of struct key_prop gets allocated an uint64_t, and the contents are positioned from the back, so an exponent of "0x01 0x00 0x01" becomes 0x0 0x0 0x0 0x0 0x0 0x1 0x0 0x1" Right now rsa_gen_key_prop() allocates a uint64_t but sets exp_len to the size returned from the parser, while on the other hand the when getting the key from the devicetree exp_len always gets set to sizeof(uint64_t). So bring that in line with the established code. Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* lib: rsa: take spl/non-spl into account when building rsa_verify_with_pkey()Heiko Stuebner2020-07-082-4/+4
| | | | | | | | | | | | | | Right now in multiple places there are only checks for the full CONFIG_RSA_VERIFY_WITH_PKEY option, not split into main,spl,tpl variants. This breaks when the rsa functions get enabled for SPL, for example to verify u-boot proper from spl. So fix this by using the existing helpers to distinguis between build-steps. Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* lib: rsa: distinguish between tpl and spl for CONFIG_RSA_VERIFYHeiko Stuebner2020-07-081-1/+1
| | | | | | | | | | | | | | | | | | | While the SPL may want to do signature checking this won't be the case for TPL in all cases, as TPL is mostly used when the amount of initial memory is not enough for a full SPL. So on a system where SPL uses DM but TPL does not we currently end up with a TPL compile error of: lib/rsa/rsa-verify.c:48:25: error: dereferencing pointer to incomplete type ‘struct checksum_algo’ To prevent that change the $(SPL_) to $(SPL_TPL_) to distinguish between both. If someone really needs FIT signature checking in TPL as well, a new TPL_RSA_VERIFY config symbol needs to be added. Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com> Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* tpm: add TPM2_GetRandom command supportDhananjay Phadke2020-07-081-0/+44
| | | | | | | Add support for TPM2 GetRandom command Signed-off-by: Dhananjay Phadke <dphadke@linux.microsoft.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* trace: clang compatible handling of gd registerHeinrich Schuchardt2020-07-071-4/+4
| | | | | | | | | | | On ARM systems gd is stored in register r9 or x18. When compiling with clang gd is defined as a macro calling function gd_ptr(). So we can not make assignments to gd. Use function set_gd() for setting the register on ARM. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
* Merge tag 'efi-2020-10-rc1' of ↵Tom Rini2020-07-056-141/+166
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | https://gitlab.denx.de/u-boot/custodians/u-boot-efi into next Pull request for UEFI sub-system for efi-2020-10-rc1 This series comprises error corrections for the UEFI subsystem: * correct consideration of timestamps for variable authentication * correct collection of data regions for code authentication * correct unit tests to test loading dbx * enable FAT_WRITE as required by the UEFI spec The boot manager uses log functions instead of printf() and debug(). The UEFI intialization state is exported.
| * efi_loader: imply FAT, FAT_WRITEHeinrich Schuchardt2020-07-031-0/+2
| | | | | | | | | | | | The UEFI spec requires support for the FAT file system. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
| * efi_loader: export initialization stateHeinrich Schuchardt2020-07-031-1/+1
| | | | | | | | | | | | | | Export the UEFI sub-system initialization state. This will allow to treat the setting of UEFI variables during and after initialization differently. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>