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>
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>
Add a new 'backtrace' command which prints the current call stack, which
is useful for debugging. The command is enabled by CONFIG_CMD_BACKTRACE
Add docs and a test.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Add the -rdynamic linker flag so that backtrace_symbols() can resolve
function names. This is needed to show meaningful symbol names instead
of just addresses.
Only enable this CONFIG_BACKTRACE and CONFIG_CMDLINE are enabled, since
it causes build failures with the tools-only build and sandbox_nocmdline
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Link with libbacktrace when CONFIG_BACKTRACE is enabled. This library is
bundled with GCC and provides DWARF-based symbol resolution for
backtraces.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Add backtrace functions for sandbox, including:
- os_backtrace() to collect addresses into a caller-supplied buffer
- os_backtrace_symbols() to convert addresses to symbol strings
- os_backtrace_symbols_free() to free the symbol array
The libbacktrace library (bundled with GCC) reads DWARF debug information
to provide detailed symbol resolution including function names (even for
static functions), source file paths, and line numbers.
The sandbox backtrace implementation wraps these OS functions to implement
the generic backtrace API (backtrace_init, backtrace_get_syms, etc.).
Enable it for just the 'sandbox' board. Add the library for the Rust
example too.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
This test expects to only sese a subset of the symbols in the
executable. Disable backtrace to avoid dealing with changes in this
area.
Signed-off-by: Simon Glass <simon.glass@canonical.com>
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>
When there is no device tree there is not point in trying to find nodes,
etc. since they will all be null.
Add static inlines to skip the code in that case.
Unfortunately this makes the file a little convoluted and there are
two inlines for ofnode_is_enabled() and ofnode_first/next_subnode(). But
it seems better than the alternative.
We could also consider splitting up the header file.
Also add a rule in drivers/Makefile to compile ofnode.o when OF_REAL is
enabled but DM is not (for kontron-sl-mx6ul) and move the
ofnode_for_each_compatible_node/prop() macros outside the OF_REAL
condition, since they only use functions that have stubs.
Series-to: concept
Series-cc: heinrich
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Provide a description of the purpose of codman and some examples of how
to use it.
Series-to: concept
Cover-letter:
codman: Add a new source-code analysis tool
Add a new tool called 'codman' (code manager) for analysing source code
usage in U-Boot builds. This tool determines which files and lines of
code are actually compiled based on the build configuration.
The tool provides three analysis methods:
- unifdef: Static preprocessor analysis (default)
- DWARF: Debug information from compiled code (-w)
- (experimental) LSP: Language server analysis using clangd (-l)
Codman supports:
- File-level analysis: which files are compiled vs unused
- Line-level analysis: which lines are active vs removed by preprocessor
- Kconfig-impact analysis with -a/--adjust option
- Various output formats: stats, directories, detail, summary
Since there is quite a lot of processing involved, Codman uses parallel
processing where possible.
This tool is admittedly not quite up to my normal code quality, but it
has been an interesting experiment in using Claude to create something
from scratch.
The unifdef part of the tool benefits from some patches I created for
that tool:
- O(1) algorithm for symbol lookup, instead of O(n) - faster!
- support for IS_ENABLED(), CONFIG_IS_ENABLED()
Please get in touch if you would like the patches.
This series also includes a minor improvement to buildman and a tidy-up
of the tout library to reduce code duplication.
END
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Series-links: 1:65
It is possible to use an LSP to determine which code is used, at least
to some degree.
Make a start on this, in the hope that future work may prove out the
concept.
So far I have not found this to be particularly useful, since it does
not seem to handle IS_ENABLED() and similar macros when working out
inactive regions.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Add a way to do static preprocessor analysis using debug information
from compiled code. This reads the DWARF tables to determin which lines
produced code.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Add a way to do static preprocessor analysis using unifdef, as a way of
figuring out what code is actually used in the build.
I have modified the unifdef tool as follows:
- O(1) algorithm for symbol lookup, instead of O(n)
- support for IS_ENABLED(), CONFIG_IS_ENABLED()
The first patch was sent upstream. The others are U-Boot-specific so I
have not submitted those.
Please get in touch if you would like the patches.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Add a new tool called 'codman' (code manager) for analysing source code
usage in U-Boot builds. This tool determines which files and lines of
code are actually compiled based on the build configuration.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Allow users to specify multiple config adjustments in a single -a
argument using commas. This is more convenient than repeating -a
multiple times.
Examples:
buildman -a FOO,~BAR
buildman -a FOO,~BAR -a BAZ=123
Add tests to verify comma-separated values work correctly.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Refactor tout.py to use terminal.tprint() instead of direct print()
calls. This provides better control over output formatting and
supports the new stderr parameter. It also reduces code duplication.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Add optional stderr parameter to tprint() to allow printing to stderr
instead of stdout.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Replace fdt_next_node() with depth tracking with fdt_for_each_subnode()
which has been available for some time.
This also fixes a latent bug where the default configuration was being
read from the wrong node offset. It happened to work before because
noffset ended up at the right value after the images loop.
Series-to: concept
Series-cc: heinrich
Cover-letter:
fit: Improve and test the code to print FIT info
The code for printing information about FITs is fairly old and not that
easy to maintain. It also lacks tests.
This series adds some tests, moves the code into its own file and then
adds a series of helpers to deal with the intricacies of printing each
item.
This provides a binary-size reduction of about 320 bytes on aarch64.
END
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
The pattern for iterating through and processing hash/signature subnodes
is repeated in two places. Add a new process_subnodes() helper to reduce
code duplication.
Drop the now-unused ndepth and noffset local variables.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Add a boolean variable 'loadable' that combines the common type check
for kernel, standalone, and ramdisk images.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Add emit_addr() to handle printing load an entry addresses.
The helper takes a 'valid' boolean parameter to determine whether to
print the address value or 'unavailable'.
Combine the two separate if() blocks for the load address.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Add emit_desc() which handles getting and printing descriptions from FIT
nodes. Handle the "unavailable" case when a description is missing.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Add a emit_stringlist() helper function to simplify printing stringlist
properties in FIT configurations.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Add a new emit_timestamp() helper function to handle printing timestamps
in FITs.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Add a new emit_prop() helper function to simplify printing optional
properties in FIT configurations.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Refactor the printing of multi-line properties to use the
emit_label_val() helper function instead of custom formatting.
Update emit_label() to deal with an empty label and not show a colon in
that case.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Line up the values witht the FIT Description and Created items at the
top. This looks a little nicer.
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Change the indent field in fit_print_ctx from a string pointer to an int
number of spaces to indent.
Set the initial indent value to 3 to match IMAGE_INDENT_STRING
Drop indentation from the debug() calls since these are not visible to
users.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Add a new emit_label_val() helper function that combines emit_label()
and printf() for simple label-value pairs.
Make use of it where appropriate.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Update fit_conf_print() to use the emit_label() helper function for
printing labels.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Update fit_image_print() to use the emit_label() helper function for
printing labels. This avoids various manual printf() calls and spacing
logic.
Set ctx->tab to 19 to align values at the correct column position.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
The current code is quite fiddly with manually spaced labels. Add helper
functions for printing labels (with or without a type prefix) with a
cofigurable tab width for the value that folows.
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Move the indent string into struct fit_print_ctx so it is available to
the printing functions. This avoids having to pass it as a separate
parameter.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Create a struct fit_print_ctx to hold the FIT pointer and pass it to all
printing functions instead of passing the FIT pointer directly. This
provides a foundation for adding additional context in the future.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
This is actually not defined by the spec. The 'required' property is for
use by the verifying code. Having it in the FIT does not help size an
attacker could potentially remove it.
Signed-off-by: Simon Glass <simon.glass@canonical.com>
There is enough code here that it makes sense to put it in its own file.
Create a new fit_print.c file, before undertaking future refactoring.
Printing is only included in the main build if CONFIG_FIT_PRINT is
enabled, although it is always included in the tools build.
Add static inlines for existing callers.
Make a few small code-style adjustments, including fixing checkpatch
warnings about over-use of brackets.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Create a new fit_print() function containing the logic from
fit_print_contents(), and make fit_print_contents() call it.
This allows future callers to use fit_print() directly as we add more
features.
Tidy up the function comments so that they are in the header.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Add a new pytest to check the output of 'mkimage -l' on the test FIT.
Only check the first 80 chars as the signature lines can be very long.
The timestamps are quite annoying, since we need the test to pass on
whatever CI machine is used. Obtain the first timestamp and use that to
check the rest, after some sanity checks.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Add a test to verify that fit_print_contents() correctly handles a FIT
image with a missing description property.
To handle this a new FIT created with the description removed after
mkimage has processed it, since mkimage will fail if the description is
missing.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>