summaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)Author
2024-09-03lmb: allow for resizing lmb regionsSughosh Ganu
Allow for resizing of LMB regions if the region attributes match. The current code returns a failure status on detecting an overlapping address. This worked up until now since the LMB calls were not persistent and global -- the LMB memory map was specific and private to a given caller of the LMB API's. With the change in the LMB code to make the LMB reservations persistent, there needs to be a check on whether the memory region can be resized, and then do it if so. To distinguish between memory that cannot be resized, add a new flag, LMB_NOOVERWRITE. Reserving a region of memory with this attribute would indicate that the region cannot be resized. Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
2024-09-03lmb: make LMB memory map persistent and globalSughosh Ganu
The current LMB API's for allocating and reserving memory use a per-caller based memory view. Memory allocated by a caller can then be overwritten by another caller. Make these allocations and reservations persistent using the alloced list data structure. Two alloced lists are declared -- one for the available(free) memory, and one for the used memory. Once full, the list can then be extended at runtime. [sjg: Use a stack to store pointer of lmb struct when running lmb tests] Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> Signed-off-by: Simon Glass <sjg@chromium.org> [sjg: Optimise the logic to add a region in lmb_add_region_flags()]
2024-09-03lmb: staticize __lmb_alloc_base()Sughosh Ganu
The __lmb_alloc_base() function is only called from within the lmb module. Moreover, the lmb_alloc() and lmb_alloc_base() API's are good enough for the allocation API calls. Make the __lmb_alloc_base() function static. Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Reviewed-by: Simon Glass <sjg@chromium.org>
2024-09-03lmb: remove the unused lmb_is_reserved() functionSughosh Ganu
The lmb_is_reserved() API is not used. There is another API, lmb_is_reserved_flags() which can be used to check if a particular memory region is reserved. Remove the unused API. Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Reviewed-by: Simon Glass <sjg@chromium.org>
2024-09-02Merge tag 'v2024.10-rc4' into nextTom Rini
Prepare v2024.10-rc4
2024-08-30lib: crypto: fix ASYMMETRIC_KEY_TYPE dependencyTomas Paukrt
Fix the dependency to avoid a warning if RSA_VERIFY_WITH_PKEY is enabled. Fixes: b7463f198da6 ("Make ASYMMETRIC_KEY_TYPE depend on FIT_SIGNATURE") Signed-off-by: Tomas Paukrt <tomaspaukrt@email.cz>
2024-08-30list: use list_count_nodes() to count list entriesSughosh Ganu
Use the API function list_count_nodes() to count the number of list entries. Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> Reviewed-by: Simon Glass <sjg@chromium.org>
2024-08-27lib: move phdr increment to for loop headingMaxim Moskalets
Shifting this pointer in the loop will be more logical when working with the code later, because you can see at a glance what exactly changes at each iteration. Moreover, the code remains equivalent because this variable is not used after the loop. Signed-off-by: Maxim Moskalets <maximmosk4@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2024-08-26global_data: Remove environment members if not usedSimon Glass
If the environment is not enabled we don't need these fields in global_data. Make them conditional. Make these fields conditional. Move env_buf up one so it can share an #ifdef. Signed-off-by: Simon Glass <sjg@chromium.org>
2024-08-24efi_loader: allow EFI_LOADER_BOUNCE_BUFFER on all architecturesHeinrich Schuchardt
There not only ARM64 boards but also RISC-V boards that require a bounce buffer to read block devices. Drop the architecture restriction. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2024-08-24efi_loader: fix memory freeing in efi_get_dp_from_boot()Ilias Apalodimas
efi_get_var() allocates memory which must be freed after the variable is used. Since the device path is duplicated after we deserialize the load options free the memory used for the variable payload Fixes: db61e70e0d2a efi_loader: efi_dp_from_lo() should skip VenMedia node Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Reviewed-by: Heinric Schuchardt <heinrich.schuchardt@canonical.com>
2024-08-19Merge tag 'v2024.10-rc3' into nextTom Rini
Prepare v2024.10-rc3
2024-08-15lib: elf: Fix bootelf -p crash issueJianfengA.Zhu@sony.com
Do not load and flush segments whose program header type is not PT_LOAD to avoid crash happen. bootelf will load all program headers and then flush cache. Since PT_GNU_STACK start address is 0x0, crash happens when it flushes PT_GNU_STACK area for target that memory cannot be accessed from address 0x0. crash call stack: ==================================================================== bootelf -p |-> do_bootelf (cmd/elf.c) |-> load_elf_image_phdr (lib/elf.c) /* Load each program header */ |-> for (i = 0; i < ehdr->e_phnum; ++i) { /* e_phnum is 2 */ |-> flush_cache(start=0, size=0) (arch/arm/lib/cache.c) (*1) |-> flush_dcache_range(start=0, 0); (arch/arm/cpu/armv8/cache_v8.c) |-> __asm_flush_dcache_range(start=0, 0) (arch/arm/cpu/armv8/cache.S) |-> /* clean & invalidate data or unified cache */ |-> dc civac, x0 <<== crash happen x0:start=0 ==================================================================== *1 Here the p_paddr and p_filesz of the GNU_STACK program are 0. hello_world elf image program headers ==================================================================== Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flags Align LOAD 0x0000000000000000 0x0000000080ff0000 0x0000000080ff0000 0x0000000000010390 0x0000000000010390 R E 0x10000 GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000 RW 0x10 Section to Segment mapping: Segment Sections... 00 .text .rodata .eh_frame 01 ==================================================================== bootelf -p crash error log ==================================================================== bootelf -p 0x80f00000 "Synchronous Abort" handler, esr 0x96000147, far 0x0 elr: 000000008f6035bc lr : 000000008f66ff54 (reloc) elr: 00000000bd9475bc lr : 00000000bd9b3f54 x0 : 0000000000000000 x1 : 0000000000000000 x2 : 0000000000000040 x3 : 000000000000003f x4 : 0000000081000390 x5 : 00000000bd12da98 x6 : 0000000000000010 x7 : 0000000000000010 x8 : 000000000000000a x9 : 00000000bd156b30 x10: 00000000bd1526e0 x11: 0000000000000000 x12: 0000000000000004 x13: 00000000bda00000 x14: 00000000ffffffff x15: 00000000bd12dab7 x16: 00000000bd957b14 x17: 0000000000000000 x18: 00000000bd13fd90 x19: 0000000080f000b0 x20: 0000000080f00000 x21: 0000000000000002 x22: 0000000000000000 x23: 0000000000000003 x24: 00000000bd9eacc0 x25: 0000000000000000 x26: 0000000000000000 x27: 0000000000000000 x28: 00000000bd154c80 x29: 00000000bd12da70 Code: d2800082 9ac32042 d1000443 8a230000 (d50b7e20) ==================================================================== Signed-off-by: Jianfeng Zhu <JianfengA.Zhu@sony.com> Reviewed-by: Jacky Cao <Jacky.Cao@sony.com> Reviewed-by: Toyama, Yoshihiro <Yoshihiro.Toyama@sony.com>
2024-08-11efi_loader: correct description of efi_get_distro_fdt_nameHeinrich Schuchardt
Use the correct function name. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-08-11efi_loader: use list_count_nodes() in efi_protocols_per_handle()Heinrich Schuchardt
Simplify the code by using the list_count_nodes() function. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2024-08-09Merge patch series "Universal Payload initial series"Tom Rini
Simon Glass <sjg@chromium.org> says: Universal Payload (UPL) is an Industry Standard for firmware components[1]. UPL is designed to improve interoperability within the firmware industry, allowing mixing and matching of projects with less friction and fewer project-specific implementations. UPL is cross-platform, supporting ARM, x86 and RISC-V initially. This series provides some initial support for this, targeting 0.9.1 and sandbox only. Features still to come include: - Support for architectures - FIT validation - Handoff validation - Interoperability tests
2024-08-09fdt: Don't overwrite bloblist devicetreeSimon Glass
When the devicetree comes from a bloblist, it is currently overwritten by the appended one, if present. It should be preserved. Adjust the logic to support this. Fixes: 70fe2385943 ("fdt: Allow the devicetree to come from a bloblist") Signed-off-by: Simon Glass <sjg@chromium.org>
2024-08-07Merge patch series "alist: Implement a pointer list / array of structs"Tom Rini
Simon Glass <sjg@chromium.org> says: This data structure provides a list of pointers / array of structures. I was planning to use it for the lmb restructure, to allow it to support any number of entries, but then I gave up on it. There are quite a few places in U-Boot where such a list would be useful, since it supports growing the array. [...] Example: struct my_struct obj; struct my_struct *ptr = alist_add(&lst, &obj, struct my_struct); // now ptr is in the list [trini: Reword the cover letter slightly, do not merge the RFC portion]
2024-08-07alist: Add support for an allocated pointer listSimon Glass
In various places it is useful to have an array of structures, but allow it to grow. In some cases we work around it by setting maximum number of entries, using a Kconfig option. In other places we use a linked list, which does not provide for random access and can complicate the code. Introduce a new data structure, which is a variable-sized list of structs each of the same, pre-set size. It provides O(1) access and is reasonably efficient at expanding linearly, since it doubles in size when it runs out of space. Signed-off-by: Simon Glass <sjg@chromium.org>
2024-08-07lib: Handle a special case with str_to_list()Simon Glass
The current implementation can return an extra result at the end when the string ends with a space. Fix this by adding a special case. Signed-off-by: Simon Glass <sjg@chromium.org>
2024-08-05fdt: Correct condition for bloblist existingSimon Glass
On some boards, the bloblist is created in SPL once SDRAM is ready. It cannot be accessed until that point, so is not available early in SPL. Add a condition to avoid a hang in this case. This fixes a hang in chromebook_coral Fixes: 70fe2385943 ("fdt: Allow the devicetree to come from a bloblist") Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Raymond Mao <raymond.mao@linaro.org>
2024-07-31efi_memory: get the efi_mem_list node directlySughosh Ganu
Use the list_for_each_entry() API to get the efi_mem_list node directly, instead of making an additional call to list_entry(). Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-07-31efi_memory: avoid possible null pointer dereferenceSughosh Ganu
Populate the previous memory descriptor node pointer only after it's parent struct has been initialised. The compiler fixes this logic to do the right thing, but it is better to have correct code in place. Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-07-31efi_memory: use list_count_nodes() to count list entriesSughosh Ganu
Use the API function list_count_nodes() to count the number of EFI memory map entries. Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2024-07-31efi_loader: correct check in efi_load_option_dp_join()Heinrich Schuchardt
After assigning to *dp we must check this value and not dp. Addresses-Coverity-ID: 501792 Control flow issues (DEADCODE) Fixes: 58bef195f94e ("cmd: eficonfig: add support for setting fdt") Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-07-31smbios: add extended Extended BIOS ROM SizeHeinrich Schuchardt
U-Boot claims to create SMBIOS 3.7 tables. The type 0 table has a field Extended BIOS ROM Size since version 3.1. BIOS ROM sizes of 16 MiB or above must be written to this field. Add and fill the missing field. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2024-07-31efi_loader: add /dtbs search pathCaleb Connolly
Add an additional search path /dtbs, this is where dtbs are installed on postmarketOS and potentially other distros. Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-07-31efi_loader: require EFI boot manager for EBBR complianceHeinrich Schuchardt
A system has to support booting via the boot manager to be EBBR compliant. See the reference to variables Boot#### in the specification. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-07-31efi_loader: adjust config options for capsule updatesIlias Apalodimas
EFI_IGNORE_OSINDICATIONS is used to ignore OsIndications if setvariable at runtime is not supported and allow the platform to perform capsule updates on disk. With the recent changes boards can conditionally enable setvariable at runtime using EFI_RT_VOLATILE_STORE. Let's make that visible in our Kconfigs and enable EFI_IGNORE_OSINDICATIONS when set variable at runtime is disabled. Since EFI_RT_VOLATILE_STORE needs help from the OS to persist the variables, allow users to ignore OsIndications even if setvariable at runtime is enabled. Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2024-07-19zlib: Fix big performance regressionChristophe Leroy
Commit 340fdf1303dc ("zlib: Port fix for CVE-2016-9841 to U-Boot") brings a big performance regression in inflate_fast(), which leads to watchdog timer reset on powerpc 8xx. It looks like that commit does more than what it describe, it especially removed an important optimisation that was doing copies using halfwords instead of bytes. That unexpected change multiplied by almost 4 the time spent in inflate_fast() and increased by 40% the overall time needed to uncompress linux kernel image. So partially revert that commit but keep post incrementation as it is the initial purpose of said commit. [trini: Combine assorted patches in to this one, just restoring the performance commit] Fixes: 340fdf1303dc ("zlib: Port fix for CVE-2016-9841 to U-Boot") Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Acked-by: Michal Simek <michal.simek@amd.com> Signed-off-by: Tom Rini <trini@konsulko.com>
2024-07-19efi_loader: Fix typo in EFI_RT_VOLATILE_STORE descriptionMichal Simek
Fix typo in EFI_RT_VOLATILE_STORE description. Fixes: c28d32f946f0 ("efi_loader: conditionally enable SetvariableRT") Signed-off-by: Michal Simek <michal.simek@amd.com>
2024-07-19efi_loader: find distro device-path for media devicesHeinrich Schuchardt
The auto-generated load options for media device do not contain a partition node. We cannot expect the simple file protocol here. Get the partition device-path via the loaded image protocol. Fixes: e91b68fd6b83 ("efi_loader: load distro dtb in bootmgr") Reported-by: E Shattow <lucent@gmail.com> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Tested-by: E Shattow <lucent@gmail.com>
2024-07-15Merge patch series "api: Remove duplicate newlines"Tom Rini
This removes a number of duplicate newlines throughout the codebase.
2024-07-15lib: Remove duplicate newlinesMarek Vasut
Drop all duplicate newlines. No functional change. Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
2024-07-14efi_loader: print device-tree in dtbdump.efiHeinrich Schuchardt
The dtbdump.efi binary can be used for testing the EFI_DT_FIXUP_PROTOCOL. It provides a command to load a file and have it fixed up and a command to save the resulting file. Add a command 'dump' for displaying the device-tree. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Tested-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-07-14scripts/Makefile.lib: EFI: Use capsule CRT instead of ESL fileJonathan Humphreys
The EFI Capsule ESL file (EFI Signature List File) used for authentication is a binary generated from the EFI Capsule public key certificate. Instead of including it in the source repo, automatically generate it from the certificate file during the build process. Currently, sandbox is the only device using this, so removed its ESL file and set the (new) CONFIG_EFI_CAPSULE_CRT_FILE config to point to its public key certificate. Signed-off-by: Jonathan Humphreys <j-humphreys@ti.com>
2024-07-05Revert "Revert "Merge patch series "zlib: Address CVE-2016-9841"""Tom Rini
Now that the release has happened, bring back the update to zlib. This reverts commit bbacdd3ef7762fbdeab43ceea5205d1fd0f25bbd. Signed-off-by: Tom Rini <trini@konsulko.com>
2024-07-05Fix Kconfig coding style from spaces to tabAnand Moon
Adjust indentation from spaces to tab (+optional two spaces) as in coding style with command like: $ sed -e 's/^ /\t/' -i */Kconfig Signed-off-by: Anand Moon <linux.amoon@gmail.com>
2024-07-04smbios: Correct error handling when writing tablesSimon Glass
Since write_smbios_table() returns an address, we cannot use it to return and error number. Also, failing on sysinfo_detect() breaks existing boards, e.g. chromebook_link Correct this by logging and swallowing the error. Signed-off-by: Simon Glass <sjg@chromium.org> Fixes: a5a57562856 ("lib: smbios: Detect system properties via...")
2024-07-04initcall: Correct use of relocation offsetSimon Glass
The relocation offset can change in some initcall sequences. Handle this and make sure it is used for all debugging statements in init_run_list() Update the trace test to match. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Caleb Connolly <caleb.connolly@linaro.org>
2024-07-03Merge patch series "m68k: Implement a default flush_dcache_all"Tom Rini
Tom Rini <trini@konsulko.com> says: Prior to this series we had some de-facto required cache functions that were either unimplemented on some architectures or differently named. This would lead in some cases to having multiple "weak" functions available as well. Rework things so that an architecture must provide these functions and it is up to that architecture if a "weak" default function makes sense, or not.
2024-07-03acpi: set creator_revision in acpi_fill_headerHeinrich Schuchardt
We should have a single place where we write the default value to the creator revision field. If we ever will have any table created by another tool, we can overwrite the value afterwards. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2024-07-01Merge branch 'next'Tom Rini
2024-06-30Revert "Merge patch series "zlib: Address CVE-2016-9841""Tom Rini
This series brings our zlib code more up to date. However, it drops an important performance improvement that is required on some of our supported platforms in order to boot Linux before the watchdog resets the system. Furthermore, the "post increment" version of this performance loop was not tested, so while we can fix it, it would then require re-testing all platforms. At this point in time, we will revert updating zlib (which has had a potential security issue since 2016) and fix this in the v2024.10 release. This reverts commit 4914263c9a14315390d3ccc4816cf3a94cfd156d, reversing changes made to ef8ef5f77c9a998f76a48277a883af1645b54117. Reported-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Tom Rini <trini@konsulko.com>
2024-06-30tpm: allow the user to select the compiled algorithmsIlias Apalodimas
Simon reports that after enabling all algorithms on the TPM some boards fail since they don't have enough storage to accommodate the ~5KB growth. The choice of hash algorithms is determined by the platform and the TPM configuration. Failing to cap a PCR in a bank which the platform left active is a security vulnerability. It might allow unsealing of secrets if an attacker can replay a good set of measurements into an unused bank. If MEASURED_BOOT or EFI_TCG2_PROTOCOL is enabled our Kconfig will enable all supported hashing algorithms. We still want to allow users to add a TPM and not enable measured boot via EFI or bootm though and at the same time, control the compiled algorithms for size reasons. So let's add a function tpm2_allow_extend() which checks the TPM active PCRs banks against the one U-Boot was compiled with. We only allow extending PCRs if the algorithms selected during build match the TPM configuration. It's worth noting that this is only added for TPM2.0, since TPM1.2 is lacking a lot of code at the moment to read the available PCR banks. We unconditionally enable SHA1 when a TPM is selected, which is the only hashing algorithm v1.2 supports. Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Reviewed-by: Simon Glass <sjg@chromium.org> Tested-by: Simon Glass <sjg@chromium.org> # chromebook-link
2024-06-30tpm: Untangle tpm2_get_pcr_info()Ilias Apalodimas
This function was used on measured boot to retrieve the number of active PCR banks and was designed to work with the TCG protocols. Since we now have the need to retrieve the active PCRs outside the measured boot context -- e.g use the in the command line, decouple the function. Create one that will only adheres to TCG TSS2.0 [0] specification called tpm2_get_pcr_info() which can be used by the TPM2.0 APIs and a new one that is called from the measured boot context called tcg2_get_pcr_info() [0] https://trustedcomputinggroup.org/wp-content/uploads/TSS_Overview_Common_Structures_Version-0.9_Revision-03_Review_030918.pdf Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-06-30efi_loader: remove unneeded header filesIlias Apalodimas
efi_tcg2.h already includes tpm-v2.h. Remove it Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-06-30tpm: Move TCG functions into a separate fileIlias Apalodimas
The previous patch is moving the TPM TCG headers in their own file for a cleaner API. Move the functions in their own file as well. Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-06-30tpm: Move TCG headers into a separate fileIlias Apalodimas
commit 97707f12fdab ("tpm: Support boot measurements") moved out code from the EFI subsystem into the TPM one to support measurements when booting with !EFI. Those were moved directly into the TPM subsystem and in the tpm-v2.c library. In hindsight, it would have been better to move it in new files since the TCG2 is governed by its own spec, it's overeall cleaner and also easier to enable certain parts of the TPM functionality. So let's start moving the headers in a new file containing the TCG specific bits. Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2024-06-30efi_selftest: can't have measured device-tree with kaslr-seedHeinrich Schuchardt
Test that we don't have a /chosen/kaslr-seed property if we measure the device-tree. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>