summaryrefslogtreecommitdiff
path: root/lib
Commit message (Collapse)AuthorAgeFilesLines
* charset: Add support for calculating bytes occupied by a u16 stringSughosh Ganu2020-05-091-0/+5
| | | | | | | | | | The current code uses 'u16_strlen(x) + 1) * sizeof(u16)' in various places to calculate the number of bytes occupied by a u16 string. Let's introduce a wrapper around this. This wrapper is used on following patches Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: variable: check a return value of uuid__str_to_bin()AKASHI Takahiro2020-05-091-1/+4
| | | | | | | | | The only error case is that a given UUID is in wrong format. So just return EFI_INVALID_PARAMETER here. Reported-by: Coverity (CID 300333) Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: image_loader: fix a Coverity check against array accessAKASHI Takahiro2020-05-091-3/+3
| | | | | | | | | | | | | | Coverity detected: Using "&opt->CheckSum" as an array. This might corrupt or misinterpret adjacent memory locations. The code should work as far as a structure, IMAGE_OPTIONAL_HEADER(64) is packed, but modify it in more logical form. Subsystem is a member next to CheckSum. Reported-by: Coverity (CID 300339) Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: crypto/pkcs7_parser.h is not a local includeHeinrich Schuchardt2020-05-071-1/+1
| | | | | | User <> and not "" for referencing a global include. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: pkcs7_parse_message() returns error pointerPatrick Wildt2020-05-071-1/+3
| | | | | | | | | | | Since pkcs7_parse_message() returns an error pointer, we must not check for NULL. We have to explicitly set msg to NULL in the error case, otherwise the call to pkcs7_free_message() on the goto err path will assume it's a valid object. Signed-off-by: Patrick Wildt <patrick@blueri.se> Add missing include linux/err.h Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: efi_variable_parse_signature() returns NULL on errorPatrick Wildt2020-05-071-2/+1
| | | | | | | | | efi_variable_parse_signature() returns NULL on error, so IS_ERR() is an incorrect check. The goto err leads to pkcs7_free_message(), which works fine on a NULL ptr. Signed-off-by: Patrick Wildt <patrick@blueri.se> Reviewed-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
* efi_loader: put device tree into EfiACPIReclaimMemoryHeinrich Schuchardt2020-05-071-2/+2
| | | | | | | | | According to the UEFI spec ACPI tables should be placed in EfiACPIReclaimMemory. Let's do the same with the device tree. Suggested-by: Ard Biesheuvel <ardb@kernel.org> Cc: Grant Likely <grant.likely@arm.com> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: do not unnecessarily use EFI_CALL()Heinrich Schuchardt2020-05-071-15/+19
| | | | | | | | | There is no need to call efi_get_variable() instead of efi_get_variable_common(). So let's use the internal function. Move forward declarations to the top of the file. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: error handling in efi_set_variable_common().Heinrich Schuchardt2020-05-071-1/+1
| | | | | | Fix unreachable code. Free memory on error. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: remove redundant assignment in dp_fill()Heinrich Schuchardt2020-05-071-1/+1
| | | | | | The value of dp is overwritten without being used. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* kbuild: efi: Avoid rebuilding efi targetsJan Kiszka2020-05-071-0/+1
| | | | | | | | | Add a couple of missing targets so that helloworld and other efi targets are not needlessly rebuilt. CC: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Tested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* rsa: fix alignment issue when getting public exponentHeiko Stuebner2020-05-071-2/+2
| | | | | | | | | | | | | | | | | | | | | | | To fill the exponent field of the rsa_public_key struct, rsa_mod_exp_sw did a cast to uint64_t of the key_prop->public_exponent field. But that alignment is not guaranteed in all cases. This came to light when in my spl-fit-signature the key-name exceeded a certain length and with it the verification then started failing. (naming it "integrity" worked fine, "integrity-uboot" failed) key_prop.public_exponent itself is actually a void-pointer, fdt_getprop() also just returns such a void-pointer and inside the devicetree the 64bit exponent is represented as 2 32bit numbers, so assuming a 64bit alignment can lead to false reads. So just use the already existing rsa_convert_big_endian() to do the actual conversion from the dt's big-endian to the needed uint64 value. Fixes: fc2f4246b4b3 ("rsa: Split the rsa-verify to separate the modular exponentiation") 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>
* efi_loader: change setup sequenceHeinrich Schuchardt2020-05-041-5/+5
| | | | | | | If we want to restore variables from disk, we need to initialize block devices before variables. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: correct comments for efi_status_tHeinrich Schuchardt2020-05-043-5/+5
| | | | | | | EFI_STATUS is unsigned (UINTN). Hence it cannot be negative. Correct comments for 'Return:'. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: eliminate efi_set_(non)volatile_variableHeinrich Schuchardt2020-05-041-104/+37
| | | | | | | Eliminate superfluous functions efi_set_volatile_variable() and efi_set_nonvolatile_variable(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: eliminate efi_get_(non)volatile_variableHeinrich Schuchardt2020-05-041-29/+3
| | | | | | | Eliminate superfluous functions efi_get_volatile_variable() and efi_get_nonvolatile_variable(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: disk: add efi_disk_is_system_part()AKASHI Takahiro2020-05-041-0/+29
| | | | | | | | | This function will check if a given handle to device is an EFI system partition. It will be utilised in implementing capsule-on-disk feature. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Add function description. Return bool. Reviewed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: factor out the common code from efi_transfer_secure_state()AKASHI Takahiro2020-05-041-130/+64
| | | | | | | | | | efi_set_secure_stat() provides the common code for each stat transition caused by efi_transfer_secure_state(). Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Correct description of return value. Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: fix unreachable statement in efi_sigstore_parse_siglistAKASHI Takahiro2020-05-041-1/+1
| | | | | | | | | | "if (left < esl->signature_size)" is not reachable in a while loop. But it is still valuable in case that a given signature database is somehow corrupted. So fix the while loop condition. Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* lib/crypto, efi_loader: move some headers to include/cryptoAKASHI Takahiro2020-05-048-135/+15
| | | | | | | | | | Pkcs7_parse.h and x509_parser.h are used in UEFI subsystem, in particular, secure boot. So move them to include/crypto to avoid relative paths. Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Don't include include x509_parser.h twice. Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* lib/crypto, efi_loader: avoid multiple inclusions of header filesAKASHI Takahiro2020-05-042-0/+8
| | | | | | | | | | By adding extra symbols, we can now avoid including x509_parser and pkcs7_parser.h files multiple times. Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Don't include include x509_parser.h twice. Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* tiny-printf: Support %iMarek Vasut2020-05-011-1/+2
| | | | | | | | | The most basic printf("%i", value) formating string was missing, add it for the sake of convenience. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Simon Glass <sjg@chromium.org> Cc: Stefan Roese <sr@denx.de>
* Merge tag 'efi-2020-07-rc2' of ↵Tom Rini2020-04-301-0/+20
|\ | | | | | | | | | | | | | | | | | | | | https://gitlab.denx.de/u-boot/custodians/u-boot-efi Pull request for UEFI sub-system for efi-2020-07-rc2 This pull request contains bug fixes needed due to the merged changes for EFI secure boot. Patches are supplied to identify EFI system partitions.
| * efi_loader: identify EFI system partitionHeinrich Schuchardt2020-04-301-0/+20
| | | | | | | | | | | | | | In subsequent patches UEFI variables shalled be stored on the EFI system partition. Hence we need to identify the EFI system partition. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* | acpi: Add an acpi commandSimon Glass2020-04-301-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | It is useful to dump ACPI tables in U-Boot to see what has been generated. Add a command to handle this. To allow the command to find the tables, add a position into the global data. Support subcommands to list and dump the tables. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com>
* | acpi: Move the xsdt pointer to acpi_ctxSimon Glass2020-04-301-6/+4
| | | | | | | | | | | | | | Put this in the context along with the other important pointers. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com>
* | acpi: Put table-setup code in its own functionSimon Glass2020-04-301-0/+82
| | | | | | | | | | | | | | | | We always write three basic tables to ACPI at the start. Move this into its own function, along with acpi_fill_header(), so we can write a test for this code. Signed-off-by: Simon Glass <sjg@chromium.org>
* | acpi: Move acpi_add_table() to generic codeSimon Glass2020-04-301-0/+61
| | | | | | | | | | | | | | | | | | | | | | | | Move this code to a generic location so that we can test it with sandbox. This requires adding a few new fields to acpi_ctx, so drop the local variables used in the original code. Also use mapmem to avoid pointer-to-address casts which don't work on sandbox. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com>
* | acpi: Convert part of acpi_table to use acpi_ctxSimon Glass2020-04-301-1/+23
| | | | | | | | | | | | | | | | | | | | | | | | The current code uses an address but a pointer would result in fewer casts. Also it repeats the alignment code in a lot of places so this would be better done in a helper function. Update write_acpi_tables() to make use of the new acpi_ctx structure, adding a few helpers to clean things up. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com>
* | acpi: Add a method to write tables for a deviceSimon Glass2020-04-301-3/+10
|/ | | | | | | | A device may want to write out ACPI tables to describe itself to Linux. Add a method to permit this. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com>
* Merge tag 'dm-pull-27apr20' of git://git.denx.de/u-boot-dmTom Rini2020-04-283-1588/+2
|\ | | | | | | | | | | Move Python tools to use absolute paths Minor buildman fixes for new features Make libfdt code more similar to upsteam
| * fdt_region: move fdt_region.c to common/ from lib/libfdt/Masahiro Yamada2020-04-262-659/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | My goal is to sync lib/libfdt/ with scripts/dtc/libfdt/, that is, make lib/libfdt/ contain only wrapper files. fdt_region.c was written only for U-Boot to implement the verified boot. So, this belongs to the same group as common/fdt_support.c, which is a collection of U-Boot own fdt helpers. Move lib/libfdt/fdt_region.c to common/fdt_region.c . This is necessary only when CONFIG_(SPL_TPL_)_FIT_SIGNATURE is enabled. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
| * libfdt: migrate fdt_ro.c to a wrapper of scripts/dtc/libfdt/fdt_ro.cMasahiro Yamada2020-04-262-929/+2
| | | | | | | | | | | | | | | | | | There is no essential difference between scripts/dtc/libfdt/fdt_ro.c and lib/libfdt/fdt_ro.c Migrate to a simple wrapper like the other files. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
* | Merge branch '2020-04-27-master-imports'WIP/27Apr2020Tom Rini2020-04-271-15/+16
|\ \ | | | | | | | | | | | | - Assorted bugfixes. - Documentation improvements including support for https://u-boot.readthedocs.io/
| * | lib: zlib: fix formatting, referenceHeinrich Schuchardt2020-04-271-15/+16
| |/ | | | | | | | | | | | | Provide a valid reference for the deflate format. Reformat the ALGORITHM and REFERENCES comments. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* | lib: enable lzma decompression support for SPL buildWeijie Gao2020-04-272-0/+6
|/ | | | | | | | This patch enables LZMA decompression support for SPL build Reviewed-by: Stefan Roese <sr@denx.de> Reviewed-by: Tom Rini <trini@konsulko.com> Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
* uuid: Use const char * where possibleSimon Glass2020-04-241-3/+5
| | | | | | | Update the arguments of these functions so they can be called from code which uses constant strings. Signed-off-by: Simon Glass <sjg@chromium.org>
* lib: Add a function to convert a string to upper caseSimon Glass2020-04-241-0/+8
| | | | | | | | Add a helper function for this operation. Update the strtoul() tests to check upper case as well. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* lib: strto: Stop detection when invalid char is usedMichal Simek2020-04-241-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This issue has been found when mtd partition are specified. Autodetection code should stop when the first invalid char is found. Here is the example of commands: setenv mtdids nand0=memory-controller@e000e000 setenv mtdparts "mtdparts=nand0:4m(boot),4m(env),64m(kernel),96m(rootfs)" mtd list Before: Zynq> mtd list List of MTD devices: * nand0 - type: NAND flash - block size: 0x20000 bytes - min I/O: 0x800 bytes - OOB size: 64 bytes - OOB available: 16 bytes - ECC strength: 1 bits - ECC step size: 2048 bytes - bitflip threshold: 1 bits - 0x000000000000-0x000010000000 : "nand0" - 0x000000000000-0x000000400000 : "boot" - 0x000000400000-0x000000800000 : "env" - 0x000000800000-0x000006c00000 : "kernel" - 0x000006c00000-0x000010000000 : "rootfs" Where it is visible that kernel partition has 100m instead of 64m After: Zynq> mtd list * nand0 - type: NAND flash - block size: 0x20000 bytes - min I/O: 0x800 bytes - OOB size: 64 bytes - OOB available: 16 bytes - ECC strength: 1 bits - ECC step size: 2048 bytes - bitflip threshold: 1 bits - 0x000000000000-0x000010000000 : "nand0" - 0x000000000000-0x000000400000 : "boot" - 0x000000400000-0x000000800000 : "env" - 0x000000800000-0x000004800000 : "kernel" - 0x000004800000-0x00000a800000 : "rootfs" Signed-off-by: Michal Simek <michal.simek@xilinx.com> Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection") Tested-by: Heiko Schocher <hs@denx.de> Tested-by: Pali Rohár <pali@kernel.org>
* lib: do not provide hexdump in SPLHeinrich Schuchardt2020-04-241-1/+1
| | | | | | | SPL should not be enlarged by building with CONFIG_HEXDUMP=y. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Tom Rini <trini@konsulko.com>
* lib: do not build OID registry in SPLHeinrich Schuchardt2020-04-241-2/+1
| | | | | | | | | The OID registry is only used by crypto functions that are not built in SPL. So we should not build it in SPL. Fixes: a9b45e6e8382 ("lib: add oid registry utility") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Tom Rini <trini@konsulko.com>
* libfdt: Make fdtdec_get_child_count() available for HOSTKever Yang2020-04-242-11/+11
| | | | | | | | | The tool need to use fdtdec_get_child_count(), make it available for HOST_CC. Signed-off-by: Kever Yang <kever.yang@rock-chips.com> Reviewed-by: Punit Agrawal <punit1.agrawal@toshiba.co.jp> Reviewed-by: Simon Glass <sjg@chromium.org>
* make env_entry::callback conditional on !CONFIG_SPL_BUILDRasmus Villemoes2020-04-241-1/+0
| | | | | | | | | | | | | | | | | | The callback member of struct env_entry is always NULL for an SPL build. Removing it thus saves a bit of run-time memory in the SPL (when CONFIG_SPL_ENV_SUPPORT=y) since struct env_entry is embedded in struct env_entry_node - i.e. about 2KB for the normal case of 512+change hash table entries. Two small fixups are needed for this, all other references to the callback member are already under !CONFIG_SPL_BUILD: Don't initialize .callback in set_flags() - hsearch_r doesn't use that value anyway. And make env_callback_init() initialize ->callback to NULL for a new entry instead of relying on an unused or deleted entry having NULL in ->callback. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk> Reviewed-by: Simon Glass <sjg@chromium.org>
* lib/hashtable.c: don't test ->callback in SPLRasmus Villemoes2020-04-241-0/+2
| | | | | | | | | In SPL, environment callbacks are not supported, so e->callback is always NULL. Removing this makes the SPL a little smaller (about 400 bytes in my ppc build) with no functional change. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk> Reviewed-by: Simon Glass <sjg@chromium.org>
* lib/hashtable.c: create helper for calling env_entry::callbackRasmus Villemoes2020-04-241-8/+15
| | | | | | | | This is preparation for compiling out the "call the callback" code and associated error handling for SPL, where ->callback is always NULL. Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk> Reviewed-by: Simon Glass <sjg@chromium.org>
* fdtdec: Fix boundary checkAtish Patra2020-04-231-1/+2
| | | | | | | | | | | | | | | | In U-Boot, the reserved memory end address is considered as a inclusive address. This notion is followed while adding a reserved memory node to the DT. For example: end_address = start_address + size - 1 Follow the same notion and fix the end address computation while checking for existing nodes. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Tested-by: Bin Meng <bmeng.cn@gmail.com>
* lib: kconfig: Add option to set BZIP2 compression methodAtish Patra2020-04-171-0/+5
| | | | | | | | | There is no way to select BZIP2 compression method. Add it under library/compression config where all other compression related configs are present. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Tom Rini <trini@konsulko.com>
* Merge tag 'efi-2020-07-rc1' of ↵WIP/16Apr2020Tom Rini2020-04-1610-135/+2227
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | https://gitlab.denx.de/u-boot/custodians/u-boot-efi Pull request for UEFI sub-system for efi-2020-07-rc1 This pull request * provides an implementation of UEFI secure booting * fixes a problem with the rsa_mod_exp driver which stops some boards from booting when CONFIG_RSA is enabled which is needed for UEFI secure booting * enables the EFI_RNG_PROTOCOL if DM_RNG is enabled * fixes some function comments
| * efi_loader: set up secure bootAKASHI Takahiro2020-04-161-0/+38
| | | | | | | | | | | | | | | | The following variable is exported as UEFI specification defines: SignatureSupport: array of GUIDs representing the type of signatures supported by the platform firmware Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
| * efi_loader: image_loader: support image authenticationAKASHI Takahiro2020-04-162-15/+457
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With this commit, image validation can be enforced, as UEFI specification section 32.5 describes, if CONFIG_EFI_SECURE_BOOT is enabled. Currently we support * authentication based on db and dbx, so dbx-validated image will always be rejected. * following signature types: EFI_CERT_SHA256_GUID (SHA256 digest for unsigned images) EFI_CERT_X509_GUID (x509 certificate for signed images) Timestamp-based certificate revocation is not supported here. Internally, authentication data is stored in one of certificates tables of PE image (See efi_image_parse()) and will be verified by efi_image_authenticate() before loading a given image. It seems that UEFI specification defines the verification process in a bit ambiguous way. I tried to implement it as closely to as EDK2 does. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>