Commit Graph

1110 Commits

Author SHA1 Message Date
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
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
Nicolas Belin
ec6fc4e514 boot: android: rework bootargs concatenation
Rework the bootargs concatenation allocating more accurately
the length that is needed.
Do not forget an extra byte for the null termination byte as,
in some cases, the allocation was 1 byte short.

Fixes: 86f4695b ("image: Fix Android boot image support")
Signed-off-by: Nicolas Belin <nbelin@baylibre.com>
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Link: https://lore.kernel.org/r/20241217-fix-bootargs-concatenation-v2-3-b2fd7cf4e130@baylibre.com
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
(cherry picked from commit 9e5fad0f79)
2025-12-19 08:53:50 -07:00
Nicolas Belin
ec3cca0ae1 boot: android: free newbootargs when done
Free newbootargs when the concatenation is done and bootargs env
is set.

Fixes: 86f4695b ("image: Fix Android boot image support")
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Signed-off-by: Nicolas Belin <nbelin@baylibre.com>
Link: https://lore.kernel.org/r/20241217-fix-bootargs-concatenation-v2-2-b2fd7cf4e130@baylibre.com
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
(cherry picked from commit fd8b44a81b)
2025-12-19 08:53:43 -07:00
Nicolas Belin
e342e46bb7 boot: android: fix extra command line support
Check that the value at the address kcmdline_extra is not 0
instead of checking the address value itself keeping it
consistent with what is done for kcmdline.

Fixes: b36b227b ("android: boot: support extra command line")
Reviewed-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Signed-off-by: Nicolas Belin <nbelin@baylibre.com>
Link: https://lore.kernel.org/r/20241217-fix-bootargs-concatenation-v2-1-b2fd7cf4e130@baylibre.com
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
(cherry picked from commit 53a0ddb6d3)
2025-12-19 08:53:38 -07:00
Simon Glass
8b35dca383 boot: Use correct PHASE_ variable for expo
This patch was written before the XPL change-over. Update the Makefile
condition to the new way.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: ae3b5928d6 ("x86: coreboot: Allow building an expo for...")
Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>
(cherry picked from commit 315fd02729)
2025-12-18 16:13:40 -07:00
Sam Protsenko
c954147d94 boot: fdt: Handle already reserved memory in boot_fdt_reserve_region()
The boot_fdt_add_mem_rsv_regions() function can be called twice, e.g.
first time during the board init (as a part of LMB init), and then when
booting the OS with 'booti' command:

    lmb_add_region_flags
    lmb_reserve_flags
    boot_fdt_reserve_region
    boot_fdt_add_mem_rsv_regions
               ^
               |
               +-----------------------+
               | (1)                   | (2)
    lmb_reserve_common        image_setup_linux
    lmb_init                  ...
    initr_lmb                 do_booti
    board_init_r              'booti'

That consequently leads to the attempt of reserving the same memory
areas (described in the 'reserved-memory' dts node) in LMB. The
lmb_add_region_flags() returns -EEXIST error code in such cases, but
boot_fdt_reserve_region() handles all negative error codes as a failure
to reserve fdt memory region, printing corresponding error messages,
which are essentially harmless, but misleading. For example, this is the
output of 'booti' command on E850-96 board:

    => booti $loadaddr - $fdtaddr
    ...
    ERROR: reserving fdt memory region failed
           (addr=bab00000 size=5500000 flags=2)
    ERROR: reserving fdt memory region failed
           (addr=f0000000 size=200000 flags=4)
    ...
    Starting kernel ...

The mentioned false positive error messages are observed starting with
commit 1d9aa4a283 ("lmb: Fix the allocation of overlapping memory
areas with !LMB_NONE"), which removes the check for the already added
memory regions in lmb_add_region_flags(), making it return -1 for
!LMB_NONE cases. Another commit 827dee587b ("fdt: lmb: add reserved
regions as no-overwrite") changes flags used for reserving memory in
boot_fdt_add_mem_rsv_regions() from LMB_NONE to LMB_NOOVERWRITE. So
together with the patch mentioned earlier, it makes
lmb_add_region_flags() return -1 when called from
boot_fdt_reserve_region().

Since then, the different patch was implemented, returning -EEXIST error
code in described cases, which is:

   lmb: Return -EEXIST in lmb_add_region_flags() if region already added

Handle -EEXIST error code as a normal (successful) case in
lmb_reserve_flags() and don't print any messages.

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 5a6aa7d591)
2025-12-17 14:02:30 -07:00
Simon Glass
a23e4407d5 luks: Correct condition for calling handle_encrypted()
Use CONFIG_BLK_LUKS instead of CONFIG_LUKS, which does not exist. This
allows the test to pass.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-08 05:22:18 -07:00
Simon Glass
cf8ce64138 bootctl: Allow unlocking LUKS2 partitions
Switch away from a pre-derived key so that LUKS2 partitions can be
unlocked. Update the ulock message to be more generic.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 17:18:57 -07:00
Simon Glass
29e684deda bootctl: Add the logic for disk unlock using a TKey
The unlock process is quite different with a TKey, since we need to load
the signing app with the user's passphrase as the USS. If the TKey is
not already in firmware mode we must prompt the user to remove and
re-insert it.

The easiest way to implement this is via a state machine. Add the
required logic:

- detect key presence and absence
- prompt for removal and insertion
- send the app, while keeping the UI responsive
- unlock the disk once the TKey provides a key
- report success or failure to the user

Ensure that the logic is only used if CONFIG_TKEY and CONFIG_LUKS are
both enabled.

Co-developed-by: Claude <claude@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 17:18:57 -07:00
Simon Glass
40be1fd57d bootctl: Clean up some unwanted debugging in the logic
Tidy up the code style for checking the result of read_images() and drop
some commented-out debug lines.

Also fix a shadowed variable while we are here.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 17:18:57 -07:00
Simon Glass
9bdd221a14 bootctl: Provide an extra poll between select and booting
Selecting an OS may cause the UI to change, so give it a chance to show
those changes before booting.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 17:18:57 -07:00
Simon Glass
4eaef8aa12 bootctl: Enhance the UI to support a TKey
When unlocking an encrypted disk with a TKey we need a few more UI
operations:

- allow the password-entry textline to be shown/hidden
- allow showing instructions to the user, as well as unlock result
- obtain the password entered by the user

Add these to the API and implement them in the multi UI.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 17:18:57 -07:00
Simon Glass
14544da18d bootctl: Provide passphrase and message objects in the expo
Set up a textline object to allow the user to enter a passphrase and a
text object to display messages for the user.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 17:18:57 -07:00
Simon Glass
4fb40b79a6 bootctl: Show a lock symbol for locked disks
When an OS is using disk encryption, show a lock symbol next to it.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 17:18:57 -07:00
Simon Glass
ceab1d8010 bootctl: Allow switching between logos
The bootctl tests are currently disabled due to some image
incompatibilities: the multi UI uses one image and the simple UI uses a
different one.

Update the logic to switch between these logos when the layout changes.
For now, use the U-Boot logo in both cases.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 17:18:57 -07:00
Simon Glass
e47ca5518a bootctl: Bring in another image
Add an image for the Canonical logo, so we can see how the screen layout
looks.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 17:18:57 -07:00
Simon Glass
0b73c9a73a bootctl: Set the password flag on the passphrase edit text
The SCENEOF_PASSWORD flag is set on the textline object, but the
rendering code checks the flag on the text object being rendered. Set
the flag on the edit text object so the passphrase renders as asterisks
instead of showing the actual characters.

Mark the textline object as hidden while we are here, so it disappears
when switching to the simple bootmenu.

Co-developed-by: Claude <claude@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 17:18:57 -07:00
Simon Glass
2bd1cbe740 bootctl: Drop unnecessary calls to calculate dimensions
Since scene_calc_dims() is done by scene_arrange(), we don't need to do
an explicit call to scene_calc_dims() first. Drop it from both UIs.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 17:18:57 -07:00
Simon Glass
6f3b890455 expo: Consider an item selected when a password is entered
When the user types in an unlock password then presses 'enter', select
the item containing the password. This avoids needing to click on an
item as well.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 12:01:57 -07:00
Simon Glass
3e75f480ef expo: Always send keys to highlighted textline
Move textline key handling outside the loop so keys are always sent
to the highlighted textline, regardless of whether it is open. This
allows the textline to respond to keyboard input even if not in a popup
expo.

Otherwise continue to send keys to menus as now.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 11:57:04 -07:00
Simon Glass
21f4b4d8dc expo: Correct rendering of textlines when open
When a textline is open, we must render the edit string and show the
cursor. The easiest way to do this is to draw the string again, then
move the cursor back to the correct place.

There is no need to change the font, since the rendering function
handles this.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 11:56:48 -07:00
Simon Glass
7c059e682e expo: Add scene_render_obj() to render by object ID
Add a function to render a single object by its ID. This provides a
convenient way to render individual objects without needing to look up
the object pointer first.

Assume that text mode is not used.

Co-developed-by: Claude <claude@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 11:53:55 -07:00
Simon Glass
ce66b13ea3 expo: Refactor scene_send_key() to use a current object
The highlight_id needs to be considered for non-popup expos as well. As
a first step, use the variable 'cur' for the current object, i.e. the
one that is highlighted.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 11:53:55 -07:00
Simon Glass
f2278377be expo: Fix textline edit text not updating in bootflow menu
The edit text object for the passphrase textline is created with an
empty string literal "", rather than pointing to the textline's buffer.
This means that when the user types, tline->buf is updated but the text
object still displays the original empty string.

Fix this by creating the edit text object with abuf_data(&tline->buf) so
it points to the textline's buffer. This matches how expo_build.c
creates textlines for cedit.

Co-developed-by: Claude <claude@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 11:53:55 -07:00
Simon Glass
7e8bf42d2d expo: Use better names for objects in bootflow_menu_add()
Use descriptive names like "item0.label", "item0.desc", "item0.pass"
instead of generic "label", "desc", "passphrase". This makes debugging
easier when multiple bootflow items exist.

Co-developed-by: Claude <claude@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 11:53:55 -07:00
Simon Glass
4ce003192f expo: Use better names for child objects in expo_build
Use the parent object name as a prefix for child objects, so they
have descriptive names like "cpu-speed.title" instead of generic
"title". This makes debugging easier when multiple objects exist.

Update add_txt_str() and add_txt_str_list() to take separate
property name and object name parameters.

Also set the scene's prompt_id when building from devicetree.

Co-developed-by: Claude <claude@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 11:53:55 -07:00
Simon Glass
9b0bd72935 expo: Add prompt_id to struct scene
Add a prompt_id field to struct scene to track the prompt text object.
Update cedit_arange() to use title_id and prompt_id directly instead
of looking up objects by name, which is more robust.

Co-developed-by: Claude <claude@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 11:53:55 -07:00
Simon Glass
4564d85794 expo: Use hex format when dumping the expo
Change expo_dump() to output object IDs in hex format. This matches the
normal convention in U-Boot.

Also add key_id and preview_id to the menu item dump output while we are
here.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-07 11:53:55 -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
9aa0a53db6 fit: Use the libfdt subnode iterator
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>
2025-11-19 19:51:46 -07:00
Simon Glass
a1429a036a fit: Add a helper to iterate through hash/signature nodes
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>
2025-11-19 19:51:46 -07:00
Simon Glass
b6674168b9 fit: Use a boolean to simplify type checks
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>
2025-11-19 19:51:46 -07:00
Simon Glass
8f5e311f3b fit: Add a helper for address printing
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>
2025-11-19 19:51:46 -07:00
Simon Glass
47953a00bb fit: Add a helper for printing descriptions
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>
2025-11-19 19:51:46 -07:00
Simon Glass
0d5a23344d fit: Add a helper for stringlist properties
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>
2025-11-19 19:51:46 -07:00
Simon Glass
b0a3ebd1fd fit: Add a helper for timestamp printing
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>
2025-11-19 19:51:46 -07:00
Simon Glass
79388f8fe8 fit: Add a helper to output optional properties
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>
2025-11-19 19:51:46 -07:00
Simon Glass
6329055745 fit: Use emit_label_val() where possible
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>
2025-11-19 19:51:46 -07:00
Simon Glass
819ef32f87 fit: Move values one column to the right
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>
2025-11-19 19:51:46 -07:00
Simon Glass
192c586a5d fit: Change indent from string to int
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>
2025-11-19 19:51:46 -07:00
Simon Glass
e18f514654 fit: Add a a function to print labels with values
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>
2025-11-19 19:51:46 -07:00
Simon Glass
4669924871 fit: Use emit_label() helper in fit_conf_print()
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>
2025-11-19 19:51:46 -07:00
Simon Glass
9515fa96e6 fit: Use emit_label() helper in fit_image_print()
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>
2025-11-19 19:51:45 -07:00
Simon Glass
9b875f54ef fit: Create some helpers for printing
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>
2025-11-19 19:50:10 -07:00
Simon Glass
62a4c7e10a fit: Put the indent string into print context
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>
2025-11-19 19:50:10 -07:00
Simon Glass
6b6f03c388 fit: Add a context struct for FIT-printing
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>
2025-11-19 19:50:10 -07:00
Simon Glass
5cb5809acd fit: Drop showing an unused 'required' property
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>
2025-11-19 19:50:10 -07:00
Simon Glass
0b51f99bf0 fit: Move printing code to its own file
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>
2025-11-19 19:50:09 -07:00