4062 Commits

Author SHA1 Message Date
Simon Glass
cc99cd2bcd Revert "lib: Add CONFIG_LIB_KMEM_CACHE for full kmem_cache support"
The memory leaks were in fact not coming from the kmem cache, so let's
drop this unnecessary feature.

This reverts commit e63fc511c3.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2026-01-01 14:27:30 -07:00
Simon Glass
104ee92c32 lib: linux: Add find_bit from Linux
Add lib/find_bit.c and include/linux/find.h from Linux v6.19, trimmed
to include only the functions needed for ext4l: find_first_bit(),
find_first_zero_bit(), find_next_bit(), find_next_zero_bit() and
find_last_bit()

The following items are removed from the Linux originals:
- find.h: _and_bit, _andnot_bit, _or_bit, _nth_bit variants, wrap
  functions, clump8 functions, big-endian support, most for_each_...
  macros
- find_bit.c: Corresponding implementations, random.h include

Add wrapper functions matching sandbox's asm/bitops.h declarations
(int return type, void* addr) that call the _find_* implementations.

Build find_bit.o only for sandbox for now.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-30 15:48:36 -07:00
Simon Glass
e63fc511c3 lib: Add CONFIG_LIB_KMEM_CACHE for full kmem_cache support
Add a Kconfig option to control whether full kmem_cache_free() and
kmem_cache_destroy() implementations are provided in lib/linux_compat.c

Most boards do not need these functions, so they can use simple inline
stubs in slab.h. Subsystems like ext4 that require proper cache
management can select CONFIG_LIB_KMEM_CACHE.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-30 15:47:04 -07:00
Evgeny Bachinin
110afc1552 fdtdec: dtb_dt_embedded: replace ifdefs by IS_ENABLED()
Patch fixes the checkpatch warnings like:
```
  WARNING: Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef'
  #94: FILE: lib/fdtdec.c:102:
  +#ifdef CONFIG_OF_EMBED
```

Signed-off-by: Evgeny Bachinin <EABachinin@salutedevices.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
(cherry picked from commit e2f0e9a320)
2025-12-24 05:17:05 -07:00
Evgeny Bachinin
94e9d64ffc fdtdec: encapsulate dtb_dt_embedded() within
Patch keeps the access to dtb_dt_embedded() within fdtdec API,
by means of new API function introduction. This new function is a
common place for updating appropriate global_data fields for
OF_EMBED case.

  Also, the consequence of the patch is movement of '___dtb_dt_*begin'
symbols' declaration from header file, because nobody used symbols
outside the lib/fdtdec.c.

Signed-off-by: Evgeny Bachinin <EABachinin@salutedevices.com>
Suggested-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
(cherry picked from commit 623f5cf517)
2025-12-24 05:17:05 -07:00
Ilias Apalodimas
9c37f9ccbe lmb: Rename _lmb_alloc_addr() to lmb_alloc_addr_flags()
lmb_alloc_addr_flags() is a wrapper for _lmb_alloc_addr() and it's the
only function using it. Rename _lmb_alloc_addr() to lmb_alloc_addr_flags()
and remove the wrapper.

Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
Tested-by: Sam Protsenko <semen.protsenko@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
(cherry picked from commit 1a25191bc1)
2025-12-24 05:17:05 -07:00
Ilias Apalodimas
c20372170e lmb: Remove lmb_alloc_base_flags()
lmb_alloc_base() is just calling lmb_alloc_base_flags() with LMB_NONE.
There's not much we gain from this abstraction, so let's remove the
former add the flags argument to lmb_alloc_base() and make the code
a bit easier to follow.

Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
Tested-by: Sam Protsenko <semen.protsenko@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
(cherry picked from commit 3075708017)
2025-12-24 05:17:05 -07:00
Ilias Apalodimas
e005799d8f lmb: Remove lmb_alloc_addr_flags()
lmb_alloc_addr() is just calling lmb_alloc_addr_flags() with LMB_NONE
There's not much we gain from this abstraction, so let's remove the
latter, add a flags argument to lmb_alloc_addr() and make the code a
bit easier to follow.

Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
Tested-by: Sam Protsenko <semen.protsenko@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
(cherry picked from commit 15e0c5e390)
2025-12-24 05:17:05 -07:00
Ilias Apalodimas
b42d3ffb5f lmb: Remove lmb_add_region()
There's no point defining a function that's called only once just to
avoid passing the flags. Remove the wrapper and just call
lmb_add_region_flags().

Acked-by: Sughosh Ganu <sughosh.ganu@linaro.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
Tested-by: Sam Protsenko <semen.protsenko@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
(cherry picked from commit c207d6e3e3)
2025-12-24 05:17:05 -07:00
Ilias Apalodimas
8692e10965 lmb: Rename free_mem to available_mem
free_mem is a misnomer. We never update it with the free memory for
LMB. Instead, it describes all available memory and is checked against
used_mem to decide whether an area is free or not.

So let's rename this field to better match its usage.

Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
Tested-by: Sam Protsenko <semen.protsenko@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
(cherry picked from commit 400c34db89)
2025-12-24 05:17:04 -07:00
Ilias Apalodimas
8e54e97f09 lmb: Remove lmb_reserve_flags()
lmb_reserve() is just calling lmb_reserve_flags() with LMB_NONE.
There's not much we gain from this abstraction.
So let's remove the latter, add the flags argument to lmb_reserve()
and make the code a bit easier to follow.

Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
Tested-by: Sam Protsenko <semen.protsenko@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
(cherry picked from commit 900a8951c3)
2025-12-24 05:17:04 -07:00
Ilias Apalodimas
65a9881993 lmb: Move enum lmb_flags to a u32
LMB flags is not an enum anymore. It's currently used as a bitmask
in various places of our code. So make it a u32 which is more
appropriate when dealing with masks.

Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
Tested-by: Sam Protsenko <semen.protsenko@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
(cherry picked from commit 3d56c06551)
2025-12-24 05:17:04 -07:00
Ilias Apalodimas
bfd75a7f81 lmb: Remove lmb_align_down()
We already have a macro for this. Use it instead of adding yet another
variant for alignment.

Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
Tested-by: Sam Protsenko <semen.protsenko@linaro.org>
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
(cherry picked from commit 6c9f27505a)
2025-12-24 05:17:04 -07:00
Sam Protsenko
2a47acca5b lmb: Improve kernel-doc comments
Fix warnings from kernel-doc script. Improve and unify overall style of
kernel-doc comments in lmb source files. Move all kernel-doc comments
for public functions into the header, as recommended in U-Boot
documentation [1]:

    Non-trivial functions should have a comment which describes what
    they do. If it is an exported function, put the comment in the
    header file so the API is in one place. If it is a static function,
    put it in the C file.

This also takes care of existing duplication. While at it, do a bit of
cosmetic cleanups as well.

No functional change.

[1] doc/develop/codingstyle.rst

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
(cherry picked from commit 22db5b2137)
Added back #if CONFIG_IS_ENABLED(LMB) guard:
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-24 05:17:04 -07:00
Sam Protsenko
c454a6ddb0 lmb: Improve coding style
Fix checkpatch warnings. No functional change.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
(cherry picked from commit 85ebda86fa)
2025-12-24 05:17:04 -07:00
Sam Protsenko
08e0c6af06 lmb: Make const flag_str[] in lmb_print_region_flags() more const
flag_str[] is a pointer to const. Make it also a const pointer. Improve
a style a bit while a it, to make this line fit 80 characters limit.

No functional change.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
(cherry picked from commit 8ab61628b8)
2025-12-24 05:17:04 -07:00
Sam Protsenko
4b07407f94 lmb: Fix flags data type in lmb_add_region_flags()
rgnflags variable in lmb_add_region_flags() has incorrect type: it's
declared as phys_size_t when it should be enum lmb_flags. That
copy-paste mistake was firstly introduced in commit 59c0ea5df3 ("lmb:
Add support of flags for no-map properties"), and then copied further
into commit ed17a33fed ("lmb: make LMB memory map persistent and
global"). Fix it by using the correct type to match struct lmb_region
field.

No functional change.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Acked-by: Sughosh Ganu <sughosh.ganu@linaro.org>
(cherry picked from commit a59887d251)
2025-12-24 05:17:04 -07:00
Peng Fan
1c5a0d2c48 smbios: address build warning
include display_options.h to address build warning:
lib/smbios.c: In function ‘smbios_update_version’:
lib/smbios.c:305:9: warning: implicit declaration of function ‘print_buffer’
[-Wimplicit-function-declaration]
         print_buffer((ulong)ptr, ptr, 1, old_len + 1, 0);
         ^~~~~~~~~~~~

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
(cherry picked from commit 3b3c7280b8)
2025-12-24 05:17:00 -07:00
Christoph Niedermaier
11b72277b0 lib: hashtable: Prevent recursive calling of callback functions
In case there are two variables which each implement env callback
that performs env_set() on the other variable, the callbacks will
call each other recursively until the stack runs out. Prevent such
a recursion from happening.

Example which triggers this behavior:
static int on_foo(...) { env_set("bar", 0); ... }
static int on_bar(...) { env_set("foo", 0); ... }
U_BOOT_ENV_CALLBACK(foo, on_foo);
U_BOOT_ENV_CALLBACK(bar, on_bar);

Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
Suggested-by: Marek Vasut <marex@denx.de>
(cherry picked from commit 86f58ea539)
2025-12-24 05:16:58 -07:00
Benedikt Spranger
7bf9e26c94 tiny-printf: Handle NULL pointer argument to %s
A NULL pointer argument to %s causes a NULL pointer dereference in the
fixed width numerical printout code, since p is overwritten with NULL.
In case of %s width is 0. Check width before dereferencing the pointer.

Signed-off-by: Benedikt Spranger <b.spranger@linutronix.de>
Reviewed-by: John Ogness <john.ogness@linutronix.de>
(cherry picked from commit f0dab28915)
2025-12-24 05:16:56 -07:00
Sam Protsenko
23525e545d lmb: Return -EEXIST in lmb_add_region_flags() if region already added
An attempt to add the already added LMB region using
lmb_add_region_flags() ends up in lmb_addrs_overlap() check, which
eventually leads to either returning 0 if 'flags' is LMB_NONE, or -1
otherwise. It makes it impossible for the user of this function to catch
the case when the region is already added and differentiate it from
regular errors. That in turn may lead to incorrect error handling in the
caller code, like reporting misleading errors or interrupting the normal
code path where it could be treated as the normal case. An example is
boot_fdt_reserve_region() function, which might be called twice (e.g.
during board startup in initr_lmb(), and then during 'booti' command
booting the OS), thus trying to reserve exactly the same memory regions
described in the device tree twice, which produces an error message on
second call.

Return -EEXIST error code in case when the added region exists and it's
not LMB_NONE; for LMB_NONE return 0, to conform to unit tests
(specifically test_alloc_addr() in test/lib/lmb.c) and the preferred
behavior described in commit 1d9aa4a283 ("lmb: Fix the allocation of
overlapping memory areas with !LMB_NONE"). The change of
lmb_add_region_flags() return values is described in the table below:

    Return case                        Pre-1d9   1d9    New
    -----------------------------------------------------------
    Added successfully                    0      0      0
    Failed to add                         -1     -1     -1
    Already added, flags == LMB_NONE      0      0      0
    Already added, flags != LMB_NONE      0      -1     -EEXIST

Rework all affected functions and their documentation. Also fix the
corresponding unit test which checks reserving the same region with the
same flags to account for the changed return value.

No functional change is intended (by this patch itself).

Fixes: 1d9aa4a283 ("lmb: Fix the allocation of overlapping memory areas with !LMB_NONE")
Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Tested-by: Michal Simek <michal.simek@amd.com>
(cherry picked from commit 8b8b35a4f5)
2025-12-17 14:02:26 -07:00
Heinrich Schuchardt
4a99a84173 net: disable MBEDTLS in SPL
Building SPL fails with MBEDTLS enabled.
Currently we don't need it there.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
(cherry picked from commit c7401fc1d9)

[Conflict resolved: kept PHASE_ macro syntax instead of XPL_, kept mbedtls_options.h include instead of inline MBEDTLS_ALLOW_PRIVATE_ACCESS, sha256_csum_wd already exists in sha256_common.c]
2025-12-17 10:51:23 -07:00
Sughosh Ganu
d3f2f8a772 lmb: prohibit allocations above ram_top even from same bank
There are platforms which set the value of ram_top based on certain
restrictions that the platform might have in accessing memory above
ram_top, even when the memory region is in the same DRAM bank. So,
even though the LMB allocator works as expected, when trying to
allocate memory above ram_top, prohibit this by marking all memory
above ram_top as reserved, even if the said memory region is from the
same bank.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
Tested-by: Andreas Schwab <schwab@suse.de>
(cherry picked from commit 1a48b0be93)
2025-12-17 10:51:23 -07:00
Simon Glass
5029b8c91b ext4l: Add stubs from various other linux headers
Add stub headers for various Linux kernel interfaces that ext4 code
expects:

- sched.h: scheduler stubs (task_struct, cond_resched, yield)
- wait.h: wait queue stubs
- rwsem.h: read-write semaphore stubs
- percpu_counter.h: percpu counter implementation (single-threaded)
- random.h: random number stubs
- quotaops.h: disk quota operation stubs
- part_stat.h: partition statistics stubs
- prefetch.h: prefetch operation stubs
- sort.h: sort wrapper using stdlib qsort
- swap.h: swap/memory management stubs

Update compat.h to include new headers and remove duplicate
definitions.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>

Series-to: concept
Cover-letter:
ext4l: Add Linux compatibility headers
This series extracts Linux kernel compatibility declarations from
include/linux/compat.h into their own header files, matching the
Linux kernel's organization. This makes it easier to port Linux
filesystem code to U-Boot and keeps the compatibility layer
maintainable.

The headers come from Linux v6.18

Headers added:
- export.h: EXPORT_SYMBOL macros
- stddef.h: sizeof_field() macro
- uaccess.h: copy_to/from_user stubs
- capability.h, cred.h, file.h, path.h, security.h, seq_file.h
- freezer.h: process freezer stubs
- slab.h, vmalloc.h: memory allocation
- module.h: kernel module stubs
- init.h: initcall macros
- kthread.h: kernel thread stubs
- timer.h, workqueue.h: timer and workqueue stubs
- sched.h, wait.h, rwsem.h: scheduler and synchronization
- percpu_counter.h, random.h, quotaops.h, part_stat.h, prefetch.h,
  sort.h, swap.h

All headers include appropriate copyright/author information from
the original Linux sources.
END
Series-links: 1:77
Series-version: 2

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-17 14:01:22 +00:00
Simon Glass
43f6682069 ext4l: Extract alloc declarations into their own file
Create include/linux/slab.h and include/linux/vmalloc.h with memory
allocation functions:

slab.h:
- GFP flags (GFP_KERNEL, GFP_ATOMIC, etc.)
- kmalloc(), kzalloc(), kcalloc(), kmalloc_array()
- kfree(), krealloc(), kmemdup()
- kmem_cache_* functions

vmalloc.h:
- vmalloc(), vzalloc(), vfree()
- __vmalloc()

Update compat.h to include these headers and remove duplicate
definitions.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-17 14:01:22 +00:00
Simon Glass
6c01706217 ext4l: Extract uaccess.h declarations into their own file
Create include/linux/uaccess.h with stub implementations for user-space
access functions. In U-Boot there's no user/kernel separation, so these
are simple memory copies.

Includes:
- copy_from_user()
- copy_to_user()
- get_user() / put_user()
- access_ok()

Update compat.h to include uaccess.h and remove the duplicate
declaration.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-17 14:01:22 +00:00
Ilias Apalodimas
38a2583258 lmb: Fix the allocation of overlapping memory areas with !LMB_NONE
At the moment the LMB allocator will return 'success' immediately on two
consecutive allocations if the second one is smaller and the flags match
without resizing the reserved area.

This is problematic for two reasons, first of all the new updated
allocation won't update the size and we end up holding more memory than
needed, but most importantly it breaks the EFI SCT tests since EFI
now allocates via LMB.

More specifically when EFI requests a specific address twice with the
EFI_ALLOCATE_ADDRESS flag set, the first allocation will succeed and
update the EFI memory map. Due to the LMB behavior the second allocation
will also succeed but the address ranges are already in the EFI memory
map due the first allocation. EFI will then fail to update the memory map,
returning EFI_OUT_OF_RESOURCES instead of EFI_NOT_FOUND which break EFI
conformance.

So let's remove the fast check with is problematic anyway and leave LMB
resize and calculate address properly. LMB will now
- try to resize the reservations for LMB_NONE
- return -1 if the memory is not LMB_NONE and already reserved

The LMB code needs some cleanup in that part, but since we are close to
2025.01 do the easy fix and plan to refactor it later.
Also update the dm tests with the new behavior.

Fixes: commit 22f2c9ed9f ("efi: memory: use the lmb API's for allocating and freeing memory")
Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
(cherry picked from commit 1d9aa4a283)
2025-12-16 20:38:21 -07:00
Simon Glass
2ddc96ae88 vsprintf: Add support for the %pV format-specifier
Add support for the %pV format-specifier which allows printing a
struct va_format. This is used by the Linux kernel for recursive
printf() formatting and is needed by the ext4l filesystem driver.

Add the struct to include/linux/printk.h to match the kernel location.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-13 16:28:53 -07:00
Simon Glass
0cf38dc8c8 backtrace: Add backtrace_str() for condensed backtrace output
Add a new function backtrace_str() that returns a condensed backtrace
string containing function names and line numbers separated by " <-".

For example: "func_a:123 <-func_b:456 <-func_c:789"

This is useful for logging and debugging where a compact representation
of the call stack is needed. The depth is controlled by the new
CONFIG_BACKTRACE_DEPTH option (default 3).

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-10 05:53:03 -07:00
Simon Glass
e1e95b2887 backtrace: Use a static buffer in backtrace_ctx for symbols
Replace the dynamic allocation in os_backtrace_symbols() with a static
buffer embedded in struct backtrace_ctx. This avoids malloc recursion
when backtrace is called from within dlmalloc (e.g., for the upcoming
mcheck caller-tracking).

The API gets a complete rework as part of this:

- Combine addrs[] and syms[] arrays into struct backtrace_frame with
  addr and sym fields
- Store the strings in a unified buffer, with pointers from an array
- Change os_backtrace_symbols() to take ctx pointer and fill sym_buf
- Remove os_backtrace_symbols_free() as nothing needs freeing
- Rename BACKTRACE_MAX to BACKTRACE_MAX_FRAMES

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-10 05:53:03 -07:00
Simon Glass
bf72ede55e lib: Add format_size() to format sizes as strings
Refactor print_size() to use a new format_size() helper that formats
a size into a buffer. This allows callers to get the formatted string
without printing it directly.

The format_size() function is only exported in U-Boot proper (controlled
by CONFIG_LIB_FORMAT_SIZE) to avoid code-size impact in SPL/TPL where it
remains static.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-10 05:53:03 -07:00
Simon Glass
1996f558e5 tpm: Fix missing log size when using bloblist
tcg2_platform_get_log() fails to set *sizep when returning a TPM
event log from bloblist. This causes tcg2_log_prepare_buffer() to
receive a log size of 0, which then causes all tcg2_log_append_check()
calls to fail with "log too large" errors since any event size exceeds
the zero-sized buffer.

This manifests when running measurement tests after other tests that
use the TPM event log bloblist (e.g. bootctl tests), as the bloblist
entry exists but its size is not properly returned.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-07 17:18:57 -07:00
Simon Glass
be5644b176 treewide: Add missing string.h includes
Add string.h to files that use string functions like strdup, strcmp,
strcpy, etc. These are implicitly available through the malloc.h header
but that will soon change.

For bouncebuf, take this opportunity to sort the headers correctly.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-01 15:57:27 +00:00
Simon Glass
cee822e941 backtrace: Strip the source tree prefix from filenames
Display relative paths instead of absolute paths in backtrace output,
making the output cleaner and more portable across different build
environments.

This works by adding a SRCTREE define to lib/backtrace.c and stripping
it from filenames when printing.

Series-to: concept
Series-cc: heinrich
Cover-letter:
backtrace: Add runtime support for looking at the backtrace
In some cases the backtrace contains useful information, such as whether
a particular function was called earlier in the stack.

This series provides a very simple backtrace library, along with some
sandbox-specific functions to allow it to work. It is designed such that
another arch could implement it.

A new 'backtrace' command provides access to the backtrace.
END

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-01 15:42:04 +00:00
Simon Glass
cdde93a9e3 backtrace: Add a library to access the backtrace
Provide an API to access the backtrace, in an arch-neutral way.

The backtrace can be retrieved, examined and printed.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-01 15:42:04 +00:00
Simon Glass
76aa68ed86 aes: Use const pointers for read-only parameters
Update AES function signatures to use const pointers for parameters that
are not modified. This improves type safety and makes it easier to see
which parameters are read-only.

Fix the Nuvoton npcm_ae driver as well since it implements the API.
Really that should be handled by a driver, but leave that for now.

Functions updated:
- aes_expand_key(): key parameter
- aes_encrypt(): in and expkey parameters
- aes_decrypt(): in and expkey parameters
- aes_apply_cbc_chain_data(): cbc_chain_data and src parameters
- aes_cbc_encrypt_blocks(): key_exp, iv, and src parameters
- aes_cbc_decrypt_blocks(): key_exp, iv, and src parameters
- add_round_key(): key parameter (internal)
- debug_print_vector(): data parameter (internal)

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-14 11:28:34 -07:00
Simon Glass
5ea9e69b82 efi: Add a flag to enable ulib
When running as an EFI app we should set the ulib flag early so as to
avoid printing unwanted output on start. Add a parameter to
efi_startup() to control whether ulib is used.

Drop the starting message in this case.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 08:40:05 -07:00
Simon Glass
dc475d0c11 efi: Allow init messages to be optional
Add a 'verbose' argument to efi_init() so that the init messages can be
suppressed if desired.

For now, keep them as they are.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 08:40:05 -07:00
Simon Glass
93ce7858e3 efi: Allow memory messages to be optional
Add a 'verbose' argument to setup_memory() so that the memory messages
can be suppressed if desired.

For now, keep them as they are.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 08:40:05 -07:00
Simon Glass
89611203f0 efi: Use EVT_RESERVE_BOARD to reserve memory for efi_priv
Use the EVT_RESERVE_BOARD event handler to allocate the efi_priv struct
in the normal memory area. This avoids the caller needing to keep it on
the stack.

Copy the struct to the new place and start using it there.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 08:40:05 -07:00
Simon Glass
7477fe4d9b efi: Allow excluding efi_main()
In some cases this function may be provided outside the library, e.g. by
a Rust main program. Add a Kconfig to control this and refactor the code
so that it is optional.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 08:40:05 -07:00
Simon Glass
0f97a71491 efi: Add missing mmc and net checks from device_path
The MMC and network subsystems must be present to use device paths for
them. Add the missing checks.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 08:40:05 -07:00
Simon Glass
ef9b8d95c1 efi: Adjust condition for runtime relocation
Even if CONFIG_ULIB is enabled it may not actually be in use. If not,
we still need the EFI-runtime relocation to happen. Adjust the condition
in efi_runtime_relocate() to fix this.

For static linking with ulib examples, provide weak symbol definitions
for __efi_runtime_rel_start and __efi_runtime_rel_stop. These symbols
are normally defined in linker scripts but need fallback definitions
when linking statically against libu-boot.a.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 08:39:49 -07:00
Simon Glass
d798b2e9ef sandbox: Move ulib_init_with_data() declaration to init.h
To avoid needing an #ifdef in the C code, move this sandbox-specific
declaration to the common init.h header.

Update ulib.c to include init.h to avoid warnings. Fix the ordering
while we are here.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 06:12:02 -07:00
Simon Glass
7bd184c0c5 lib: Plumb in argon2 library
Add a Kconfig optiion to enable this library and add it to the lib/
Makefile, being careful to avoid a conflict with the existing blake2b
implementation.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-11 04:09:41 -07:00
Simon Glass
f1514752a5 lib: Adapt argon2 library for U-Boot
Rename argon.c to argon_wrapper.c so we can use 'argon' as the library
name. Move the include file into the normal place.

Add SPDX tags but otherwise keep the files as is. The code style uses
spaces instead of tabs and has other differences with U-Boot

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-11 04:09:41 -07:00
Simon Glass
3c7c70b0d2 lib: Bring in argon2 library
This library is used for full-disk encryption with LUKS, so bring it in
from https://github.com/P-H-C/phc-winner-argon2 commit:

   f57e61e Merge pull request #321 from bittorf/fix-spelling-mistakes

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-11 04:09:41 -07:00
Simon Glass
5da98448d8 json: Provide a way to convert JSON to FDT
JSON is a rather more free format than devicetree, so it is sometimes
better to parse it into dtb format. This is widely used in U-Boot and we
can use the ofnode interface to access it.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-11 04:09:40 -07:00
Simon Glass
58f610d0ae mbedtls: Allow use of base64
Add a configuration and a Makefile rule to provide access to the mbedtls
base64 support.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-11 03:38:01 -07:00
Simon Glass
5830ac688e mbedtls: Allow use of XTS functions
Add a few Kconfig options to support XTS (XEX Tweakable Block Ciphertext
Stealing).

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-11 03:37:10 -07:00