Commit Graph

6240 Commits (7b8d48197b82b9a27c61d7d4c6f02f00a08fef2d)
 

Author SHA1 Message Date
Joshua M. Clulow 7b8d48197b [multiboot] try other regions for large modules
Multiboot modules are placed immediately after the primary executable
image.  If the memory region where the executable is placed is not very
large, modules may not fit in that region.  Try skipping over holes to
see if the module will fit in a subsequent region.
2021-05-01 15:33:25 -07:00
Michael Brown 3efdbef2f0 [efi] Always map full length of coherent DMA buffer allocation
The EFI PCI API takes a page count as the input to AllocateBuffer()
but a byte count as the input to Map().  There is nothing in the UEFI
specification that requires us to map exactly the allocated length,
and no systems have yet been observed that will fail if the map length
does not exactly match the allocated length.  However, it is plausible
that some implementations may fail if asked to map a length that does
not match the length of the corresponding allocation.

Avoid potential future problems by always mapping the full allocated
length.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-04-20 14:37:08 +01:00
Matya e4afaa2246 [build] Fix genfsimg to build ISO with long filenames
Commit 79c0173 ("[build] Create util/genfsimg for building
filesystem-based images") introduced the new genfsimg, which lacks the
-l option when building ISO files.  This option is required to build
level 2 (long plain) ISO9660 filenames, which are required when using
the .lkrn extensions on older versions of ISOLINUX.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-04-20 13:39:39 +01:00
Michael Brown 614d99eba1 [xen] Avoid infinite loop on allocation failure in xenstore_response()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-04-20 13:28:57 +01:00
Michael Brown 85d179f2c6 [xen] Support scatter-gather to allow for jumbo frames
The use of jumbo frames for the Xen netfront virtual NIC requires the
use of scatter-gather ("feature-sg"), with the receive descriptor ring
becoming a list of page-sized buffers and the backend using as many
page buffers as required for each packet.

Since iPXE's abstraction of an I/O buffer does not include any sort of
scatter-gather list, this requires an extra allocation and copy on the
receive datapath for any packet that spans more than a single page.

This support is required in order to successfully boot an AWS EC2
virtual machine (with non-enhanced networking) via iSCSI if jumbo
frames are enabled, since the netback driver used in EC2 seems not to
allow "feature-sg" to be renegotiated once the Linux kernel driver
takes over.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-04-14 16:33:41 +01:00
Michael Brown 8ca43ccbc1 [int13] Do not report INT 13 extension support for emulated floppies
The INT 13 extensions provide a mechanism for accessing disks using
linear (LBA) rather than C/H/S addressing.  SAN protocols such as
iSCSI invariably support only linear addresses and so iPXE currently
provides LBA access to all SAN disks (with autodetection and emulation
of an appropriate geometry for C/H/S accesses).

Most BIOSes will not report support for INT 13 extensions for floppy
disk drives, and some operating systems may be confused by a floppy
drive that claims such support.

Minimise surprise by reporting the existence of support for INT 13
extensions only for non-floppy drive numbers.  Continue to provide
support for all drive numbers, to avoid breaking operating systems
that may unconditionally use the INT 13 extensions without first
checking for support.

Reported-by: Valdo Toost <vtoost@hot.ee>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-04-13 20:42:55 +01:00
Michael Brown 3ae83222ce [cloud] Enable "poweroff" command in cloud images
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-04-10 20:03:32 +01:00
Michael Brown 78749542fc [netdevice] Ensure driver transmit() and poll() will not be re-entered
When CONSOLE_SYSLOG is used, a DBG() from within a network device
driver may cause its transmit() or poll() methods to be unexpectedly
re-entered.  Since these methods are not intended to be re-entrant,
this can lead to undefined behaviour.

Add an explicit re-entrancy guard to both methods.  Note that this
must operate at a per-netdevice level, since there are legitimate
circumstances under which the netdev_tx() or netdev_poll() functions
may be re-entered (e.g. when using VLAN devices).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-04-10 16:53:52 +01:00
Michael Brown 0be8491b71 [pci] Avoid scanning nonexistent buses when using PCIAPI_DIRECT
There is no method for obtaining the number of PCI buses when using
PCIAPI_DIRECT, and we therefore currently scan all possible bus
numbers.  This can cause a several-second startup delay in some
virtualised environments, since PCI configuration space access will
necessarily require the involvement of the hypervisor.

Ameliorate this situation by defaulting to scanning only a single bus,
and expanding the number of PCI buses to accommodate any subordinate
buses that are detected during enumeration.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-04-10 15:05:05 +01:00
Tyler J. Stachecki c0346dbb49 [intel] Add additional PCI device ID to table
Adding this missing identifier allows the X557-AT2 chipset seen on (at
least) Super Micro A2SDI-H-TF motherboards to function with iPXE.

Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
2021-04-10 14:56:00 +01:00
Marvin Häuser 94245624e4 [efi] Mark PE .reloc and .debug sections as discardable
After a PE image is fully loaded and relocated, the loader code may
opt to zero discardable sections for security reasons.  This includes
relocation and debug information, as both contain hints about specific
locations within the binary.  Mark both generated sections as
discardable, which follows the PE specification.

Signed-off-by: Marvin Häuser <mhaeuser@posteo.de>
2021-04-10 14:13:05 +01:00
Marvin Häuser f1e9e2b062 [efi] Align EFI image sections by page size
For optimal memory permission management, PE sections need to be
aligned by the platform's minimum page size.  Currently, the PE
section alignment is fixed to 32 bytes, which is below the typical 4kB
page size.  Align all sections to 4kB and adjust ELF to PE image
conversion accordingly.

Signed-off-by: Marvin Häuser <mhaeuser@posteo.de>
2021-04-10 13:43:47 +01:00
Marvin Häuser 1cc8756511 [efi] Discard .pci_devlist.* sections for EFI images
As per https://github.com/ipxe/ipxe/pull/313#issuecomment-816018398,
these sections are not required for EFI execution.  Discard them to
avoid implementation-defined alignment malforming binaries.

Signed-off-by: Marvin Häuser <mhaeuser@posteo.de>
2021-04-10 13:22:31 +01:00
Michael Brown 1192edf394 [dhcp] Handle DHCPNAK by returning to discovery state
Handle a DHCPNAK by returning to the discovery state to allow iPXE to
attempt to obtain a replacement IPv4 address.

Reuse the existing logic for deferring discovery when the link is
blocked: this avoids hammering a misconfigured DHCP server with a
non-stop stream of requests and allows the DHCP process to eventually
time out and fail.

Originally-implemented-by: Blake Rouse <blake.rouse@canonical.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-03-11 16:04:19 +00:00
Michael Brown 7c8fc2cae8 [linux] Fail at link time if building slirp.linux without libslirp
The iPXE build system is constructed for a standalone codebase with no
external dependencies, and does not have any equivalent of the
standard userspace ./configure script.  We currently check for the
ability to include slirp/libslirp.h and conditionalise portions of
linux_api.c on its presence.  The actual slirp driver code is built
unconditionally, as with all iPXE drivers.

This currently leads to a silent runtime failure if attempting to use
slirp.linux built on a system that was missing slirp/libslirp.h.

Convert this to a link-time failure by deliberately omitting the
relevant symbols from linux_api.c when slirp/libslirp.h is not
present.  This allows other builds (e.g. tap.linux or tests.linux) to
succeed: the link-time failure will occur only if the slirp driver is
included within the build target.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-03-11 15:25:33 +00:00
Michael Brown 65bd5c05db [linux] Do not assume that stat() works on sysfs files
Linux kernel 3.12 and earlier report a zero size via stat() for all
ACPI table files in sysfs.  There is no way to determine the file size
other than by reading the file until EOF.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-03-03 02:26:42 +00:00
Michael Brown 1c4917b6a7 [linux] Validate length of ACPI table read from sysfs
Consumers of acpi_find() will assume that returned structures include
a valid table header and that the length in the table header is
correct.  These assumptions are necessary when dealing with raw ACPI
tables, since there exists no independent source of length
information.

Ensure that these assumptions are also valid for ACPI tables read from
sysfs.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-03-03 01:55:07 +00:00
Michael Brown 50d13907c4 [linux] Place -lslirp at end of linker search list
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-03-03 01:09:33 +00:00
Michael Brown 69ecab2634 [linux] Use fstat() rather than statx()
The statx() system call has a clean header file and a consistent
layout, but was unfortunately added only in kernel 4.11.

Using stat() or fstat() directly is extremely messy since glibc does
not necessarily use the kernel native data structures.  However, as
the only current use case is to obtain the length of an open file, we
can merely provide a wrapper that does precisely this.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-03-03 01:01:58 +00:00
Michael Brown 2a2909cd1f [linux] Use generic sysfs mechanism to read SMBIOS table
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-03-02 23:59:48 +00:00
Michael Brown 6816006808 [linux] Use generic sysfs mechanism to read ACPI tables
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-03-02 23:59:46 +00:00
Michael Brown 5c8a9905ce [linux] Add a generic function for reading files from sysfs
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-03-02 23:59:30 +00:00
Michael Brown 976839ae4c [linux] Free cached ACPI tables on shutdown
Free any cached ACPI tables for the sake of neatness (and a clean
report from Valgrind).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-03-02 23:59:27 +00:00
Michael Brown 3a58400121 [dns] Reduce debug verbosity for DNS server list
The DNS server list is currently printed as a debug message whenever
settings are applied.  This can result in some very noisy debug logs
when a script makes extensive use of settings.

Move the DNS server list debug messages to DBGLVL_EXTRA.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-03-02 20:03:21 +00:00
Michael Brown 7b963310aa [linux] Allow arbitrary settings to be applied to Linux devices
Allow arbitrary settings to be specified on the Linux command line.
For example:

    ./bin-x86_64-linux/slirp.linux \
          --net slirp,testserver=qa-test.ipxe.org

This can be useful when using the Linux userspace build to test
embedded scripts, since it allows arbitrary parameters to be passed
directly on the command line.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-03-02 19:35:11 +00:00
Michael Brown 8055d5c48b [linux] Add missing pci_num_bus() stub
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-03-02 18:02:33 +00:00
Michael Brown 3b8aff94bf [build] Fix building on older versions of gcc
Versions of gcc prior to 9.1 do not support the single-argument form
of static_assert().  Fix by unconditionally defining a compatibility
macro for the single file that uses this.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-03-02 16:47:22 +00:00
Michael Brown 2b5d3f582f [slirp] Add libslirp driver for Linux
Add a driver using libslirp to provide a virtual network interface
without requiring root permissions on the host.  This simplifies the
process of running iPXE as a Linux userspace application with network
access.  For example:

  make bin-x86_64-linux/slirp.linux
  ./bin-x86_64-linux/slirp.linux --net slirp

libslirp will provide a built-in emulated DHCP server and NAT router.
Settings such as the boot filename may be controlled via command-line
options.  For example:

  ./bin-x86_64-linux/slirp.linux \
      --net slirp,filename=http://192.168.0.1/boot.ipxe

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-03-02 11:09:57 +00:00
Michael Brown 916ebef198 [build] Allow __asmcall to be used as a type attribute
The "used" attribute can be applied only to functions or variables,
which prevents the use of __asmcall as a type attribute.

Fix by removing "used" from the definition of __asmcall for i386 and
x86_64 architectures, and adding explicit __used annotations where
necessary.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-03-02 10:15:23 +00:00
Michael Brown c09b627973 [linux] Provide ACPI settings via /sys/firmware/acpi/tables
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-03-01 01:38:54 +00:00
Michael Brown 9776f6ece1 [acpi] Allow for platforms that provide ACPI tables individually
The ACPI API currently expects platforms to provide access to a single
contiguous ACPI table.  Some platforms (e.g. Linux userspace) do not
provide a convenient way to obtain the entire ACPI table, but do
provide access to individual tables.

All iPXE consumers of the ACPI API require access only to individual
tables.

Redefine the internal API to make acpi_find() an API method, with all
existing implementations delegating to the current RSDT-based
implementation.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-03-01 00:08:23 +00:00
Michael Brown d175936b78 [acpi] Eliminate redundant acpi_find_rsdt() in acpi_sx()
The result from acpi_find_rsdt() is used only for the debug message.
Simplify the debug message and remove the otherwise redundant call to
acpi_find_rsdt().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-02-28 23:59:15 +00:00
Michael Brown 0956fb52c4 [acpi] Use a fixed colour for debug messages
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-02-28 23:58:06 +00:00
Michael Brown f309d7a7b7 [linux] Use host glibc system call wrappers
When building as a Linux userspace application, iPXE currently
implements its own system calls to the host kernel rather than relying
on the host's C library.  The output binary is statically linked and
has no external dependencies.

This matches the general philosophy of other platforms on which iPXE
runs, since there are no external libraries available on either BIOS
or UEFI bare metal.  However, it would be useful for the Linux
userspace application to be able to link against host libraries such
as libslirp.

Modify the build process to perform a two-stage link: first picking
out the requested objects in the usual way from blib.a but with
relocations left present, then linking again with a helper object to
create a standard hosted application.  The helper object provides the
standard main() entry point and wrappers for the Linux system calls
required by the iPXE Linux drivers and interface code.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-02-28 23:28:23 +00:00
Michael Brown 040cdd0c65 [linux] Add a prefix to all symbols to avoid future name collisions
Allow for the possibility of linking to platform libraries for the
Linux userspace build by adding an iPXE-specific symbol prefix.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-02-27 19:25:02 +00:00
Michael Brown 16d95227a4 [bitops] Provide an explicit operand size for bit test instructions
Recent versions of the GNU assembler (observed with GNU as 2.35 on
Fedora 33) will produce a warning message

  Warning: no instruction mnemonic suffix given and no register
  operands; using default for `bts'

The operand size affects only the potential range for the bit number.
Since we pass the bit number as an unsigned int, it is already
constrained to 32 bits for both i386 and x86_64.

Silence the assembler warning by specifying an explicit 32-bit operand
size (and thereby matching the choice that the assembler would
otherwise make automatically).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-02-27 15:45:31 +00:00
Michael Brown b76281a885 [efi] Compress EFI ROM images
Use the reference implementation of the EFI compression algorithm
(taken from the EDK2 codebase, with minor bugfixes to allow
compilation with -Werror) to compress EFI ROM images.

Inspired-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-02-19 19:58:04 +00:00
Michael Brown 900f1f98d3 [librm] Test for FXSAVE/FXRSTOR instruction support
Assume that preservation of the %xmm registers is unnecessary during
installation of iPXE into memory, since this is an operation that by
its nature substantially disrupts large portions of the system anyway
(such as the E820 memory map).  This assumption allows us to utilise
the existing CPUID code to check that FXSAVE/FXRSTOR are supported.

Test for support during the call to init_librm and store the flag for
use during subsequent calls to virt_call.

Reduce the scope of TIVOLI_VMM_WORKAROUND to affecting only the call
to check_fxsr(), to reduce #ifdef pollution in the remaining code.

Debugged-by: Johannes Heimansberg <git@jhe.dedyn.io>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-02-18 15:38:56 +00:00
Michael Brown e63b8c3302 [librm] Add missing __asmcall on init_idt()
The __asmcall declaration has no effect on a void function with no
parameters, but should be included for completeness since the function
is called directly from assembly code.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-02-18 14:52:25 +00:00
Michael Brown 22bb29eabc [prefix] Add a generic raw image prefix
Provide a generic raw image prefix, which assumes that the iPXE image
has been loaded in its entirety on a paragraph boundary.

The resulting .raw image can be loaded via RPL using an rpld.conf file
such as:

    HOST {
        ethernet = 00:00:00:00:00:00/6;
        FILE {
            path="ipxe.raw";
            load=0x2000;
        };
        execute=0x2000;
    };

Debugged-by: Johannes Heimansberg <git@jhe.dedyn.io>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-02-18 13:53:26 +00:00
Michael Brown 8446a439b3 [initrd] Allow for zero-length initrd files
A zero-length initrd file will currently cause an endless loop during
reshuffling as the empty image is repeatedly swapped with itself.

Fix by terminating the inner loop before considering an image as a
candidate to be swapped with itself.

Reported-by: Pico Mitchell <pico@randomapplications.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-02-18 01:49:23 +00:00
Michael Brown 4039b54ba3 [cloud] Do not enable serial console on EFI platforms
Most EFI firmware builds (including those found on ARM64 instances in
AWS EC2) will already send console output to the serial port.

Do not enable direct serial console output in EFI builds using
CONFIG=cloud.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-02-17 22:38:38 +00:00
Michael Brown cd3de55ea5 [efi] Record cached DHCPACK from loaded image's device handle, if present
Record the cached DHCPACK obtained from the EFI_PXE_BASE_CODE_PROTOCOL
instance installed on the loaded image's device handle, if present.

This allows a chainloaded UEFI iPXE to reuse the IPv4 address and DHCP
options previously obtained by the built-in PXE stack, as is already
done for a chainloaded BIOS iPXE.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-02-17 18:11:43 +00:00
Michael Brown d562339fca [efi] Defer autoboot link-layer address and autoexec script probing
The code to detect the autoboot link-layer address and to load the
autoexec script currently runs before the call to initialise() and so
has to function without a working heap.

This requirement can be relaxed by deferring this code to run via an
initialisation function.  This gives the code a normal runtime
environment, but still invokes it early enough to guarantee that the
original loaded image device handle has not yet been invalidated.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-02-17 17:14:19 +00:00
Michael Brown e39cd79a00 [efi] Split out autoexec script portions of efi_autoboot.c
The "autoboot device" and "autoexec script" functionalities in
efi_autoboot.c are unrelated except in that they both need to be
invoked by efiprefix.c before device drivers are loaded.

Split out the autoexec script portions to a separate file to avoid
potential confusion.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-02-17 17:14:19 +00:00
Michael Brown 057674bb1f [pxe] Split out platform-independent portions of cachedhcp.c
Split out the portions of cachedhcp.c that can be shared between BIOS
and UEFI (both of which can provide a buffer containing a previously
obtained DHCP packet, and neither of which provide a means to
determine the length of this DHCP packet).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-02-17 15:59:52 +00:00
Bruce Rogers 19d0fab40f [ath5k] Add missing AR5K_EEPROM_READ in ath5k_eeprom_read_turbo_modes
The GCC11 compiler pointed out something that apparently no previous
compiler noticed: in ath5k_eeprom_pread_turbo_modes, local variable
val is used uninitialized. From what I can see, the code is just
missing an initial AR5K_EEPROM_READ. Add it right before the switch
statement.

Signed-off-by: Bruce Rogers <brogers@suse.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-02-16 23:35:24 +00:00
Michael Brown fa012dd020 [cloud] Enable IPv6 and HTTPS in cloud boot images
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-02-16 10:58:42 +00:00
Michael Brown d16535aa4f [cloud] Add utility for importing images to AWS EC2
Add a utility that can be used to upload an iPXE disk image to AWS EC2
as an Amazon Machine Image (AMI).  For example:

  make CONFIG=cloud EMBED=config/cloud/aws.ipxe bin/ipxe.usb

  ../contrib/cloud/aws-import -p -n "iPXE 1.21.1" bin/ipxe.usb

Uploads are performed in parallel across all regions, and use the EBS
direct APIs to avoid the need to store temporary files in S3 or to run
VM import tasks.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-02-16 00:27:40 +00:00
Michael Brown 1b99ba2a93 [build] Work around stray sections introduced by some binutils versions
Some versions of GNU ld (observed with binutils 2.36 on Arch Linux)
introduce a .note.gnu.property section marked as loadable at a high
address and with non-empty contents.  This adds approximately 128MB of
garbage to the BIOS .usb disk images.

Fix by using a custom linker script for the prefix-only binaries such
as the USB disk partition table and MBR, in order to allow unwanted
sections to be explicitly discarded.

Reported-by: Christian Hesse <mail@eworm.de>
Tested-by: Christian Hesse <mail@eworm.de>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2021-02-15 10:02:32 +00:00