Commit Graph

99517 Commits

Author SHA1 Message Date
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
1ecf365eab efi: Drop the message about building the EFI capsule
This message is not very useful, so drop it.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 08:40:05 -07:00
Simon Glass
e9ac6dad87 x86: Enable ulib for qemu-x86
Add support for using ulib with this board, as an example of using ulib
outside the existing sandbox and EFI options.

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
8fbcca0a85 x86: Expand the rom size for qemu-x86
The ROM is close to its limit and any main program using ulib will
overflow it. Expand the ROM size to 2MB.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 06:25:27 -07:00
Simon Glass
9b41b0fbe7 Add an option to select whether the shared library is built
The shared library is useful only with sandbox, so add an option to
allow it to be disabled, e.g. for EFI builds.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 06:23:59 -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
3a801fde21 scripts: Provide a way to use custom firmware
Update both build-efi and build-scripts to allow a -c option to provide
custom firmware. This makes the scripts more generally useful.

Drop the existing -c for --spice since it conflicts and is also is bit
hard to remember.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 06:09:52 -07:00
Simon Glass
7c1597588d scripts: build-efi: Allow including other files
Provide a way to include a directory of files in the firmware image
created by build-efi

This is useful for including a U-Boot environment, for example.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 06:09:52 -07:00
Simon Glass
69d20a8abc Merge branch 'sece-fix' into 'master'
luks: Support the AES-XTS cipher mode

See merge request u-boot/u-boot!206
2025-11-12 13:01:45 +00:00
Simon Glass
a2b25780a4 luks: Add XTS cipher mode support for LUKS2
Add support for AES-XTS cipher mode in addition to the existing
AES-CBC-ESSIV support. This is the default cipher for LUKS2 volumes.

The cipher mode (CBC/XTS) is obtained from the LUKS1 cipher_mode or
LUKS2 encryption metadata.

XTS mode uses 512-byte block numbers for IV generation (plain64),
matching dm-crypt behavior. LUKS2 typically uses 4096-byte sectors
for XTS encryption but the IV is based on 512-byte block numbers.

Fix the blkmap-size calculation to exclude the LUKS header/payload
offset.

Update the LUKSv2 test to check reading a file.

Series-to: concept
Cover-letter:
luks: Support the AES-XTS cipher mode
This series finishes off the implementation of LUKSv2, adding support
for the common cipher mode and testing that files can be read from the
disk.

It includes a fix for using the correct size when mapping the crypt, as
well as some refactoring to split up the code a little better.
END

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 05:20:11 -07:00
Simon Glass
ed94d01b71 luks: Split out crypt reading into its own function
In preparation for adding support for a new algorithm, move the
decryption part of blkmap_crypt_read() into its own function.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 05:20:11 -07:00
Simon Glass
3393e4d6ce luks: Move blkmap crypt code into a separate file
Create a new blkmap_crypt.c file to hold the LUKS code, since it is
fairly large. Add an internal header for blkmap as well.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 05:20:10 -07:00
Simon Glass
1207fde8d5 luks: test: Check file access in the decryption tests
The current tests check that decryption happens but don't go so far as
reading a file. Add the logic for this. Since this currently fails for
LUKSv2, leave the last part of that test out for now.

Use direct filesystem calls for LUKSv2 since it is easier to check for
the current error.

Add more information on the errors returned by luks_unlock() so we can
check for the correct one.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-12 05:02:47 -07:00
Simon Glass
815974c475 luks: Exclude the payload from the size calculation
Fix the blkmap-size calculation to exclude the LUKS header/payload
offset. This was missed in the initial implementation.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Fixes: 0cbfb2d490 ("luks: Provide a way to unlock and map encrypted..")
2025-11-12 05:02:37 -07:00
Simon Glass
b68c8fb93b Merge branch 'sece' into 'master'
luks: Provide support for LUKSv2

See merge request u-boot/u-boot!205
2025-11-11 19:13:29 +00:00
Simon Glass
505a3e3af8 luks: Update docs and tests for LUKSv2
Add documentation for the new LUKSv2 feature and update LUKSv1 to
mention the more common algorithm.

Update the tests to use LUKSv2 for mmc12

Series-to: concept
Series-cc: heinrich
Cover-letter:
luks: Provide support for LUKSv2
Modern systems mostly use LUKSv2 as it is more secure that v1. This
series provides an implementation of this feature, making use of the
existing 'luks unlock' command.

One interesting part of this series is a converter from JSON to FDT, so
that U-Boot's existing ofnode interface can be used to access the
hierarchical data in JSON text. This obviously results in quite a bit
of new code, but it is more robust than trying to parse the text
directly using strstr(), etc. The choice of JSON for LUKS was presumably
made with larger code bases in mind, rather than a firmware
implementation.
END

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
Series-links: 1:58
2025-11-11 05:44:08 -07:00
Simon Glass
407b729bad luks: Enable LUKSv2 support in the luks command
Allow unlocking a v2 LUKS partition.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-11 04:35:08 -07:00
Simon Glass
f0d3a7d5f9 luks: Provide an implementation of luks2
Add supports for luks v2 which is a more common version used on modern
systems.

This makes use of Argon2 and also the JSON->FDT parser.

Enable this feature for sandbox, tidying up the defconfig while we are
here.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-11 04:35:08 -07:00
Simon Glass
4b2a5ac9a4 luks: Tidy up the code style in the block driver
In preparation for luks v2, make a few code-style tweaks:
- shorter vars in some cases
- 80cols in a few places
- drop an unwanted blank line
- use 'pass' instead of 'passphrase'
- unnecessary assignments to NULL

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-11 04:34:51 -07:00
Simon Glass
cc31300b5c luks: Export the af_merge() function
Provide this function through an internal header, so that luks2 will be
able to use it.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-11 04:16:43 -07:00
Simon Glass
b2e53c814d test: Switch mmc12 over to use argon2id
Use the more common argon2id algorithm for this disk so that we can test
the implementation.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-11 04:16:42 -07:00
Simon Glass
b614f6b2a7 test: Add a way to create a LUKS2 partition with XTS
For LUKS version 2, argon is normally used in preference to pbkdf2. Add
an argument to specify this when creating a filesystem.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-11 04:16:23 -07:00
Simon Glass
1dcfa2ecbb test: Shorten the encrypt_passphrase parameter for FsHelper
This is very long and the 'encrypt' part is implied by the passphrase.
Shorten it to just 'passphrase'.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-11 04:15:03 -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
2887dcf6cf test: Check for null string in assert functions
Update ut_asserteq_str() and ut_asserteq_strn() to check for NULL. This
allows tests to avoid doing this.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-11-11 04:05:55 -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
Simon Glass
39a81c884d Merge branch 'image-fix' into 'master'
scripts: Makefile.lib: Fix image .S generation for out-of-tree builds

See merge request u-boot/u-boot!204
2025-11-03 05:52:04 +00:00
Simon Glass
b9eb028294 scripts: Makefile.lib: Fix image .S generation for out-of-tree builds
The conditional filter checking for "drivers/video/images" in $(obj)
fails for out-of-tree builds where $(obj) contains the full build path.
Fix the wildcard pattern (%drivers/video/images) so files are matched
correctly.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-11-03 06:49:40 +01:00
Simon Glass
7c1b95eb13 Merge branch 'secd' into 'master'
efi: Minor improvements to QEMU and build scripts

See merge request u-boot/u-boot!203
2025-10-26 06:32:40 +00:00
Simon Glass
f1e908f4a3 efi-x86_app64: Enable environment in FAT filesystem
Enable CONFIG_ENV_IS_IN_FAT to automatically load the environment from
the uboot.env file on the FAT filesystem. This makes the build-efi
script's --bootcmd option work correctly.

Series-to: concept
Cover-letter:
efi: Minor improvements to QEMU and build scripts
This series introduces a few improvements:
- passing a boot command to the EFI app
- FPDT support for EFI app
END

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-25 18:19:23 +01:00
Simon Glass
46b43a1658 efi-x86_app64: Use bootflow scan for boot command
Switch back to the normal boot command for this app.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-25 18:19:23 +01:00
Simon Glass
a12023a01a scripts: build-efi: Write uboot.env file for bootcmd support
When running U-Boot as an EFI application under EDK2/OVMF, U-Boot doesn't
have direct access to QEMU's fw_cfg interface. To support the --bootcmd
option, write a uboot.env file to the EFI partition containing the boot
command.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-25 18:19:23 +01:00
Simon Glass
2c415606fd scripts: Support --bootcmd more generally
Add -b as a short alias for --bootcmd to build_helper so it is available
in both build-qemu and build-efi

Move the fw_cfg bootcmd logic to build_helper as well.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-25 18:19:23 +01:00
Simon Glass
ce00a8112c doc: qemu-x86: Document opt/u-boot/bootcmd feature
Add documentation explaining how to use the fw_cfg interface to specify
a boot command for QEMU x86. This feature allows automated testing and
scripting by providing the boot command directly through QEMU's
firmware configuration interface.

The documentation includes:
- How to create a boot command file
- The QEMU command-line syntax with -fw_cfg option
- Behavior and limitations of the feature

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-25 18:19:23 +01:00
Simon Glass
eb2dc2bac8 qfw: Silence the message when opt/u-boot/bootcmd is not found
Currently qfw_locate_file() always prints error messages when it can't
find a file. This causes unwanted error output in qemu_get_bootcmd()
when the optional "opt/u-boot/bootcmd" file doesn't exist.

Adjust qfw_locate_file() to be silent, with a new qfw_locate_file_msg()
that shows messages.

This allows callers to choose whether missing files should generate
error messages.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-25 18:19:23 +01:00
Simon Glass
9c3919f31e acpi: qfw: Add FPDT support for QEMU builds
QEMU creates ACPI tables but doesn't include FPDT (Firmware Performance
Data Table). Add FPDT generation in qfw_acpi.c following the same
pattern as BGRT.

Move the acpi_write_fpdt() function from acpi_table.c to acpi_extra.c so
that is available even when CONFIG_ACPIGEN is disabled.

This allows QEMU x86_64 builds to provide firmware boot timing
information to the operating system.

Disable this for qemu-riscv64_smode_acpi as it is near the code-size
limit.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-25 18:19:08 +01:00
Simon Glass
1002f1fc35 Merge branch 'secc' into 'master'
luks: Provide basic support for unlocking a LUKS1 partition

See merge request u-boot/u-boot!202
2025-10-25 06:26:41 +00:00
Simon Glass
dfb03773ca luks: Add detection of LUKS partition
Provide a function which can detect a LUKS partition. Add a test, using
mmc11

Series-to: concept
Cover-letter:
luks: Provide basic support for unlocking a LUKS1 partition
With full-disk encryption (FDE) it is traditional to unlock a LUKS
partition within userspace as part of the initial ramdisk passed to
Linux. The user is prompted for a passphrase and then the disk is
unlocked.

This works well but does have some drawbacks:
- firmware has no way of knowing whether the boot will success
- the 'passphrase' prompt comes quite late in the boot, which can be
  confusing for the user
- specifically it is not possible to provide an integrated 'boot' UI in
  firmware where the user can enter the passphrase
- in a VM environment, the key may be known in advance, but there is no
  way to take advantage of this
- it is not possible to use an encryted disk unless also using a ramdisk

This series makes a small step towards improving U-Boot in this area. It
allows a passphrase to be checked against a LUKS1-encrypted partition.
It also provides read-only access to the unencrypted data, so that files
can be read.
END

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-24 21:02:11 +01:00
Simon Glass
fb5cd8627a luks: Add a subcommand to unlock an encrypted partition
Provide a new 'luks unlock' command which can unlock a LUKS1 partition,
given a passphrase.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-24 21:02:11 +01:00
Simon Glass
0cbfb2d490 luks: Provide a way to unlock and map encrypted partitions
Add the logic to unlock a partition and set up a blkmap for use with it.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-24 21:02:11 +01:00
Simon Glass
1f29c19082 luks: Enhance blkmap to support LUKSv1
Enhance blkmap to support decrypting a partition encrypted with LUKS
version 1. This will allow filesystems to access files on the parition.

This will be tested once filesystems support is plumbed in.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-24 21:02:11 +01:00
Simon Glass
22826bf21f luks: Show the JSON information for LUKSv2
Extract the full information for version 2, which is JSON format. Show
this with the 'luks info' command.

Use the mmc12 disk to check this.

Require the JSON for LUKS.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-24 21:02:11 +01:00
Simon Glass
eb2ae89f55 luks: Create a disk image with LUKS2 encryption
Add a new mmc12 image which has a LUKS2-encrypted ext4 partition.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-24 21:02:11 +01:00
Simon Glass
2737bf15bf luks: Create a very simple JSON library
LUKS version 2 uses JSON as a means of communicating the key
information. Add a simple library which can print JSON in a
human-readable format.

Note that it does not fully parse the JSON fragment. That may be
considered later, if needed.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-24 21:02:10 +01:00
Simon Glass
414baddf37 luks: Add a simple command
Add a 'luks' command which allows querying a partition to see if it is
encrypted using LUKS, as well as showing information about a LUKS
partition.

Provide some documentation and a test.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
2025-10-24 20:12:40 +01:00