Commit Graph

7251 Commits

Author SHA1 Message Date
Michael Brown
c1b558f59e [cmdline] Remove userptr_t from "digest" command
Simplify the implementation of the "digest" command by assuming that
the entire image data can be passed directly to digest_update().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 23:24:29 +01:00
Michael Brown
0edbc4c082 [nbi] Remove userptr_t from NBI image parsing
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 23:17:16 +01:00
Michael Brown
3cb33435f5 [sdi] Remove userptr_t from SDI image parsing
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 23:01:25 +01:00
Michael Brown
d7c94c4aa5 [pxe] Remove userptr_t from PXE NBP image parsing
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 22:46:50 +01:00
Michael Brown
2f11f466e6 [block] Remove userptr_t from block device abstraction
Simplify the block device code by assuming that all read/write buffers
are directly accessible via pointer dereferences.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 17:11:30 +01:00
Michael Brown
2742ed5d77 [uaccess] Remove now-obsolete memchr_user()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 16:35:49 +01:00
Michael Brown
4f4f6c33ec [script] Remove userptr_t from script image parsing
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 16:28:32 +01:00
Michael Brown
8923a216b0 [ucode] Remove userptr_t from microcode image parsing
Simplify microcode image parsing by assuming that all image content is
directly accessible via pointer dereferences.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 14:25:00 +01:00
Michael Brown
605cff4c84 [ucode] Remove userptr_t from microcode update mechanism
Simplify the microcode update mechanism by assuming that status
reports are accessible via direct pointer dereferences.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 13:48:57 +01:00
Michael Brown
f18c1472e3 [thunderx] Replace uses of userptr_t with direct pointer dereferences
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 13:16:50 +01:00
Michael Brown
8ac03b4a73 [exanic] Replace uses of userptr_t with direct pointer dereferences
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 10:56:21 +01:00
Michael Brown
e8ffe2cd64 [uaccess] Remove trivial uses of userptr_t
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-24 01:40:05 +01:00
Michael Brown
945df9b429 [gve] Replace uses of userptr_t with direct pointer dereferences
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-23 23:12:50 +01:00
Michael Brown
839540cb95 [umalloc] Remove userptr_t from user memory allocations
Use standard void pointers for umalloc(), urealloc(), and ufree(),
with the "u" prefix retained to indicate that these allocations are
made from external ("user") memory rather than from the internal heap.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-23 14:43:04 +01:00
Michael Brown
0bf0f8716a [smbios] Remove userptr_t from SMBIOS structure parsing
Simplify the SMBIOS structure parsing code by assuming that all
structure content is fully accessible via pointer dereferences.

In particular, this allows the convoluted find_smbios_structure() and
read_smbios_structure() to be combined into a single function
smbios_structure() that just returns a direct pointer to the SMBIOS
structure, with smbios_string() similarly now returning a direct
pointer to the relevant string.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-23 10:08:16 +01:00
Michael Brown
0b3fc48fef [acpi] Remove userptr_t from ACPI table parsing
Simplify the ACPI table parsing code by assuming that all table
content is fully accessible via pointer dereferences.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-22 14:21:06 +01:00
Michael Brown
c059b34170 [deflate] Remove userptr_t from decompression code
Simplify the deflate, zlib, and gzip decompression code by assuming
that all content is fully accessible via pointer dereferences.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-22 12:32:12 +01:00
Michael Brown
b89a34b07f [image] Remove userptr_t from image definition
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-22 12:21:26 +01:00
Michael Brown
e98b84f1b9 [crypto] Remove userptr_t from CMS verification and decryption
Simplify the CMS code by assuming that all content is fully accessible
via pointer dereferences.  This avoids the need to use fragment loops
for calculating digests and decrypting (or reencrypting) data.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-22 00:28:07 +01:00
Michael Brown
3f8937d2f3 [crypto] Remove userptr_t from ASN.1 parsers
Simplify the ASN.1 code by assuming that all objects are fully
accessible via pointer dereferences.  This allows the concept of
"additional data beyond the end of the cursor" to be removed, and
simplifies parsing of all ASN.1 image formats.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-21 23:30:13 +01:00
Michael Brown
04d0b2fdf9 [uaccess] Remove redundant read_user()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-21 18:55:30 +01:00
Michael Brown
050df80bbc [uaccess] Replace real_to_user() with real_to_virt()
Remove the intermediate concept of a user pointer from real address
conversion, leaving real_to_virt() as the directly implemented
function.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-21 18:28:56 +01:00
Michael Brown
8c31270a21 [uaccess] Remove user_to_phys() and phys_to_user()
Remove the intermediate concept of a user pointer from physical
address conversions, leaving virt_to_phys() and phys_to_virt() as the
directly implemented functions.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-21 16:17:19 +01:00
Michael Brown
4535548cba [uaccess] Remove redundant user_to_virt()
The user_to_virt() function is now a straightforward wrapper around
addition, with the addend almost invariably being zero.

Remove this redundant wrapper.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-21 00:15:52 +01:00
Michael Brown
89fe788689 [uaccess] Remove redundant memcpy_user() and related string functions
The memcpy_user(), memmove_user(), memcmp_user(), memset_user(), and
strlen_user() functions are now just straightforward wrappers around
the corresponding standard library functions.

Remove these redundant wrappers.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-20 23:00:13 +01:00
Michael Brown
ef03849185 [uaccess] Remove redundant userptr_add() and userptr_diff()
The userptr_add() and userptr_diff() functions are now just
straightforward wrappers around addition and subtraction.

Remove these redundant wrappers.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-20 22:31:29 +01:00
Michael Brown
b65f67d443 [uaccess] Change userptr_t to be a pointer type
The original motivation for the userptr_t type was to be able to
support a pure 16-bit real-mode memory model in which a segment:offset
value could be encoded as an unsigned long, with corresponding
copy_from_user() and copy_to_user() functions used to perform
real-mode segmented memory accesses.

Since this memory model was first created almost twenty years ago, no
serious effort has been made to support a pure 16-bit mode of
operation for iPXE.  The constraints imposed by the memory model are
becoming increasingly cumbersome to work within: for example, the
parsing of devicetree structures is hugely simplified by being able to
use and return direct pointers to the names and property values.  The
devicetree code therefore relies upon virt_to_user(), which is
nominally illegal under the userptr_t memory model.

Drop support for the concept of a memory location that cannot be
reached through a straightforward pointer dereference, by redefining
userptr_t to be a simple pointer type.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-20 17:28:33 +01:00
Michael Brown
71174e19d8 [uaccess] Add explicit casts to and from userptr_t where needed
Allow for the possibility of userptr_t becoming a pointer type by
adding explicit casts where necessary.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-20 17:21:53 +01:00
Michael Brown
63d27c6311 [uaccess] Rename userptr_sub() to userptr_diff()
Clarify the intended usage of userptr_sub() by renaming it to
userptr_diff() (to avoid confusion with userptr_add()), and fix the
existing call sites that erroneously use userptr_sub() to subtract an
offset from a userptr_t value.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-20 17:20:30 +01:00
Michael Brown
453acba7dc [time] Use currticks() to provide the null system time
For platforms with no real-time clock (such as RISC-V SBI) we use the
null time source, which currently just returns a constant zero.

Switch to using currticks() to provide a clock that does not represent
the real current time, but does at least advance at approximately the
correct rate.  In conjunction with the "ntp" command, this allows
these platforms to use time-dependent features such as X.509
certificate verification for HTTPS connections.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-19 13:35:23 +01:00
Michael Brown
423cdbeb39 [riscv] Map DEL to backspace on the SBI debug console
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-19 12:20:59 +01:00
Michael Brown
1291dc39fd [cgem] Add a driver for the Cadence GEM NIC
Add a basic driver for the Cadence GEM network interface as emulated
by QEMU when using the RISC-V "sifive_u" machine type.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-19 11:54:08 +01:00
Michael Brown
0c482060d5 [undi] Work around broken ASUSTeK KNPA-U16 server PXE ROM
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-17 15:53:28 +01:00
Michael Brown
758a504860 [efi] Inhibit calls to Shutdown() for wireless SNP devices
The UEFI model for wireless network configuration is somewhat
underdefined.  At the time of writing, the EDK2 "UEFI WiFi Connection
Manager" driver provides only one way to configure wireless network
credentials, which is to enter them interactively via an HII form.
Credentials are not stored (or exposed via any protocol interface),
and so any temporary disconnection from the wireless network will
inevitably leave the interface in an unusable state that cannot be
recovered without user intervention.

Experimentation shows that at least some wireless network drivers
(observed with an HP Elitebook 840 G10) will disconnect from the
wireless network when the SNP Shutdown() method is called, or if the
device is not polled sufficiently frequently to maintain its
association to the network.  We therefore inhibit calls to Shutdown()
and Stop() for any such SNP protocol interfaces, and mark our network
device as insomniac so that it will be polled even when closed.

Note that we need to inhibit not only our own calls to Shutdown() and
Stop(), but also those that will be attempted by MnpDxe when we
disconnect it from the SNP handle.  We do this by patching the
installed SNP protocol interface structure to modify the Shutdown()
and Stop() method pointers, which is ugly but unavoidable.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-17 14:42:18 +01:00
Michael Brown
b07cc851f0 [netdevice] Add the concept of an insomniac network device
Some network devices (observed with the SNP interface to the wireless
network card on an HP Elitebook 840 G10) will stop working if they are
left for too long without being polled.

Add the concept of an insomniac network device, that must continue to
be polled even when closed.

Note that drivers are already permitted to call netdev_rx() et al even
when closed: this will already be happening for USB devices since
polling operates at the level of the whole USB bus, rather than at the
level of individual USB devices.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-17 10:42:22 +01:00
Michael Brown
c88ebf2ac6 [efi] Allow for custom methods for disconnecting existing drivers
Allow for greater control over the process used to disconnect existing
drivers from a device handle, by converting the "exclude" field from a
simple protocol GUID to a per-driver method.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-17 10:08:54 +01:00
Michael Brown
eeec6442d9 [dt] Provide dt_ioremap() to map device registers
Devicetree devices encode register address ranges within the "reg"
property, with the number of cells used for addresses and for sizes
determined by the #address-cells and #size-cells properties of the
immediate parent device.

Record the number of address and size cells for each device, and
provide a dt_ioremap() function to allow drivers to map a specified
range without having to directly handle the "reg" property.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-15 20:39:28 +01:00
Michael Brown
99322fd3b3 [fdt] Add fdt_cells() to read cell-based properties such as "reg"
Add fdt_cells() to read scalar values encoded within a cell array,
reimplement fdt_u64() as a wrapper around this, and add fdt_u32() for
completeness.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-15 20:24:19 +01:00
Michael Brown
2c406ec0b1 [netdevice] Add missing bus type identifier for devicetree devices
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-15 14:02:14 +01:00
Michael Brown
424839c58a [crypto] Allow for explicit control of external trust sources
We currently disable all external trust sources (such as the UEFI
TlsCaCertificate variable) if an explicit TRUST=... parameter is
provided on the build command line.

Define an explicit TRUST_EXT build parameter that can be used to
explicitly disable external trust sources even if no TRUST=...
parameter is provided, or to explicitly enable external trust sources
even if an explicit TRUST=... parameter is provided.  For example:

   # Default trusted root certificate, disable external sources
   make TRUST_EXT=0

   # Explicit trusted root certificate, enable external sources
   make TRUST=custom.crt TRUST_EXT=1

If no TRUST_EXT parameter is specified, then continue to default to
disabling external trust sources if an explicit TRUST=... parameter is
provided, to maintain backwards compatibility with existing build
command lines.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-15 13:22:00 +01:00
Michael Brown
37e9f785ba [dt] Add basic concept of a devicetree bus
Add a basic model for devices instantiated by parsing the system
flattened device tree, with drivers matched via the "compatible"
property for any non-root node.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-14 14:52:51 +01:00
Michael Brown
d462aeb0ca [fdt] Remove concept of a device tree cursor
Refactor device tree traversal to operate on the basis of describing
the token at a given offset, with no separate notion of a device tree
cursor.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-14 14:38:40 +01:00
Michael Brown
b1125007ca [fdt] Add basic tests for reading values from a flattened device tree
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-14 14:20:31 +01:00
Michael Brown
db49346177 [fdt] Avoid temporarily modifying path during path lookup
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-14 13:53:09 +01:00
Michael Brown
c887de208f [fdt] Provide fdt_strings() to read string list properties
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-14 11:32:17 +01:00
Michael Brown
69af6f0c30 [fdt] Allow for trailing slashes in path lookups
Using fdt_path() to find the root node "/" currently fails, since it
will attempt to find a child node with the empty name "" within the
root node.

Fix by changing fdt_path() to ignore any trailing slashes in a device
tree path.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-14 11:26:49 +01:00
Michael Brown
96dfaa7e7a [crypto] Switch to using python-asn1crypto instead of python-asn1
Version 3.0.0 of python-asn1 has a serious defect that causes it to
generate invalid DER.

Fix by switching to the asn1crypto module, which also allows for
simpler code to be used.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-11 12:40:22 +01:00
Michael Brown
7e64e9b670 [fdt] Populate boot arguments in constructed device tree
When creating a device tree to pass to a booted operating system,
ensure that the "chosen" node exists, and populate the "bootargs"
property with the image command line.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-01 16:55:28 +01:00
Michael Brown
d853448887 [fdt] Identify free space (if any) at end of parsed tree
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-04-01 13:08:41 +01:00
Michael Brown
0a48bb3214 [x509] Ensure certificate remains valid during x509_append()
The allocation of memory for the certificate chain link may cause the
certificate itself to be freed by the cache discarder, if the only
current reference to the certificate is held by the certificate store
and the system runs out of memory during the call to malloc().

Ensure that this cannot happen by taking out a temporary additional
reference to the certificate within x509_append(), rather than
requiring the caller to do so.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2025-03-31 18:05:11 +01:00