david/ipxe
david
/
ipxe
Archived
1
0
Fork 0
Commit Graph

5709 Commits

Author SHA1 Message Date
Michael Brown 6ee62eb242 [hermon] Avoid potential integer overflow when calculating memory mappings
When the area to be mapped straddles the 2GB boundary, the expression
(high+size) will overflow on the first loop iteration.  Fix by using
(end-size), which cannot underflow.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-21 12:01:51 +02:00
Michael Brown de2c6fa240 [dhcp] Allow vendor class to be changed in DHCP requests
Allow the DHCPv4 vendor class to be specified via the "vendor-class"
setting.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-20 13:58:59 +02:00
Michael Brown 7692a8ff02 [undi] Move PXE API caller back into UNDI driver
As of commit 10d19bd ("[pxe] Always retrieve cached DHCPACK and apply
to relevant network device"), the UNDI driver has been the only user
of pxeparent_call().  Remove the unnecessary layer of abstraction by
refactoring this code back into undinet.c, and fix the ability of
undiisr.S to fall back to chaining to the original handler if we were
unable to unhook our own ISR.

This effectively reverts commit 337e1ed ("[pxe] Separate parent PXE
API caller from UNDINET driver").

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-19 15:57:24 +00:00
Michael Brown 6324227dca [efi] Skip cable detection at initialisation where possible
We currently request cable detection in PXE_OPCODE_INITIALIZE to work
around buggy Emulex drivers (see commit c0b61ba ("[efi] Work around
bugs in Emulex NII driver")).

This causes problems with some other NII drivers (e.g. Mellanox),
which may time out if the underlying link is intrinsically slow to
come up.

Attempt to work around both problems simultaneously by requesting
cable detection only if the underlying NII driver does not support
link status reporting via PXE_OPCODE_GET_STATUS.  (This is based on a
potentially incorrect assumption that the buggy Emulex drivers do not
claim to report link status via PXE_OPCODE_GET_STATUS.)

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-19 13:30:27 +00:00
Michael Brown fdcdc5203b [efi] Provide ACPI table description for SAN devices
Provide a basic proof of concept ACPI table description (e.g. iBFT for
iSCSI) for SAN devices in a UEFI environment, using a control flow
that is functionally identical to that used in a BIOS environment.

Originally-implemented-by: Vishvananda Ishaya Abrams <vish.ishaya@oracle.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-13 12:18:46 +00:00
Michael Brown 553f485734 [efi] Add EFI_ACPI_TABLE_PROTOCOL header and GUID definition
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-10 21:58:05 +00:00
Michael Brown 0463ec32c7 [efi] Update to current EDK2 headers
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-10 21:18:03 +00:00
Michael Brown afdebdc163 [build] Provide common ARRAY_SIZE() definition
Several files define the ARRAY_SIZE() macro as used in Linux.  Provide
a common definition for this in include/compiler.h.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-10 15:44:11 +00:00
Vishvananda Ishaya Abrams 4524cc11bf [iscsi] Don't close when receiving NOP-In
Some iSCSI targets send NOP-In.  Rather than closing the connection
when we receive one, it is more user friendly to log a debug message
and keep the connection open.  Eventually, it would be nice if iPXE
supported replying to NOP-Ins, but we might as well keep the
connection open until the target disconnects us.

Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-09 14:23:22 +00:00
Vishvananda Ishaya 1d04900262 [intel] Reset all virtual function settings
Some VF data is not cleared with reset, so make sure to return all the
settings to default before configuring the VF.

This fixes an issue where network packets would fail to be received if
the VF was previously used by the linux ixgbevf driver.

Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-09 13:56:22 +00:00
Michael Brown 9db9221ea0 [scsi] Avoid duplicate calls to scsicmd_close()
When a SCSI device is closed in error, the shutdown of the device's
block data interface will probably lead to any outstanding commands
being closed (by whichever object is currently connected to the block
data interface).  However, commands remain in the list of outstanding
commands until the final reference is dropped.  The result is that
scsidev_close() will make a second call to scsicmd_close() for each
command.  This is harmless, but produces confusing debug messages.

Fix by treating the outstanding command list as holding an explicit
reference to each command, and removing the command from the list of
outstanding commands in scsicmd_close().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-09 13:07:57 +00:00
Michael Brown 9423a85f71 [block] Use intfs_shutdown() when shutting down multiple interfaces
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-09 12:16:56 +00:00
Michael Brown 7ff3fc7c72 [scsi] Use intfs_shutdown() when shutting down multiple interfaces
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-09 12:16:35 +00:00
Michael Brown a29bdb3a92 [iscsi] Use intfs_shutdown() when shutting down multiple interfaces
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-09 12:16:15 +00:00
Michael Brown d9886f1961 [block] Retry any SAN device operation
The SCSI layer currently implements a retry loop in order to retry
commands that fail due to spurious "error" conditions such as "power
on occurred".  Move this retry loop to the generic SAN device layer:
this allow for retries due to other transient error conditions such as
an iSCSI target having dropped the connection due to inactivity.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-07 16:11:22 +00:00
Michael Brown 23d388418e [efi] Refactor to use centralised SAN device abstraction
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-07 13:40:35 +00:00
Michael Brown e790366c7c [int13] Refactor to use centralised SAN device abstraction
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-07 13:40:35 +00:00
Michael Brown e7ee2eda4b [block] Centralise "san-drive" setting
The concept of the SAN drive number is meaningful only in a BIOS
environment, where it represents the INT13 drive number (0x80 for the
first hard disk).  We retain this concept in a UEFI environment to
allow for a simple way for iPXE commands to refer to SAN drives.

Centralise the concept of the default drive number, since it is shared
between all supported environments.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-07 13:40:35 +00:00
Michael Brown 4adc7b0290 [block] Centralise SAN device abstraction
Create a central SAN device abstraction to be shared between BIOS and
UEFI.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-07 13:40:35 +00:00
Michael Brown 530ec83011 [block] Remove spurious comments
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-07 13:40:35 +00:00
Michael Brown 0e0e0321a5 [efi] Add missing SANBOOT_PROTO_HTTP to EFI default configuration
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-03-07 13:39:55 +00:00
Konrad Adamczyk 30f96c9f41 [thunderx] Don't disable NIC when exiting from iPXE
According to ThunderX Errata G-17560, NIC_PF_CFG[ENA] bit should not
be cleared at exit.  This allows other drivers to access the NIC regs
correctly.

Signed-off-by: Konrad Adamczyk <konrad.adamczyk@cavium.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-02-07 12:05:00 +00:00
Bartosz Szczepanek ed864feb3a [thunderx] Fix hardware deinitialization
It is required to reset BGX context state for the LMAC using
BGX_CMR_CONFIG register.

This solves problem with network connectivity in Linux booted from
iPXE.

Signed-off-by: Bartosz Szczepanek <bartosz.szczepanek@cavium.com>
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-02-07 11:54:57 +00:00
Michael Brown 4a4da573dd [http] Cleanly shut down potentially looped interfaces
Use intfs_shutdown() and intfs_restart() to cleanly shut down multiple
interfaces that may loop back to the same object.

This fixes a regression introduced by commit daa8ed9 ("[interface]
Provide intf_reinit() to reinitialise nullified interfaces") which
broke the use of HTTP Basic and Digest authentication.

Reported-by: murmansk <murmansk@hotmail.com>
Reported-by: Brett Waldo <brettwaldo@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-02-02 16:58:00 +00:00
Michael Brown 23b788e5cd [interface] Provide the ability to shut down multiple interfaces
Shutting down (and optionally restarting) multiple interfaces is
fraught with problems if there are loops in the interface connectivity
(e.g. the HTTP content-decoded and transfer-decoded interfaces, which
will generally loop back to each other).  Various workarounds
currently exist across the codebase, generally involving preceding
calls to intf_nullify() to avoid problems due to known loops.

Provide intfs_shutdown() and intfs_restart() to allow all of an
object's interfaces to be shut down (or restarted) in a single call,
without having to worry about potential external loops.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-02-02 15:49:21 +00:00
Michael Brown a8f80a75d2 [time] Report attempts to use timers before initialisation
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-02-01 15:30:41 +00:00
Michael Brown 41f786cc0a [settings] Add "unixtime" builtin setting to expose the current time
Expose the current wall-clock time (in seconds since the Epoch), since
this is often useful in captured boot logs and can also be useful when
checking unexpected X.509 certificate validation failures.

Use a :uint32 setting to avoid Y2K38 rollover, thereby ensuring that
this will eventually be somebody else's problem.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-26 12:26:54 +00:00
Christian Nilsson 0bfe9f5342 [intel] Add INTEL_NO_PHY_RST for I219-LM (2)
Originally-implemented-by: Malte zu Klampen <malte@pclab.ifg.uni-kiel.de>
Originally-implemented-by: Richard Moore <rich@richud.com>
Tested-by: Esben Storgaard Nielsen <esn@solar.dk>
Signed-off-by: Christian Nilsson <nikize@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-26 12:26:54 +00:00
Michael Brown f8cf3ceb0b [int13] Test correct return status from INT 13 calls
INT 13 calls return a status value via %ah, with CF set if %ah is
non-zero (indicating an error).  Our wrappers zero the whole of %ax if
CF is clear, to allow C code (which has no easy access to CF) to
simply test for a non-zero status to detect an error.

The current code assigns the returned status to a uint8_t, effectively
testing %al rather than %ah.  Fix by treating the returned status as a
uint16_t instead.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-26 09:45:19 +00:00
Michael Brown fcf7751565 [int13] Avoid potential division by zero
Avoid using a zero sector count to guess the disk geometry, since that
would result in a division by zero when calculating the number of
cylinders.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-26 09:31:40 +00:00
Michael Brown f3ba0fb5fd [hyperv] Provide timer based on the 10MHz time reference count MSR
When running on AMD platforms, the legacy hardware emulation is
extremely unreliable.  In particular, the IRQ0 timer interrupt is
likely to simply stop working, resulting in a total failure of any
code that relies on timers (such as DHCP retransmission attempts).

Work around this by using the 10MHz time counter provided by Hyper-V
via an MSR.  (This timer can be tested in KVM via the command-line
option "-cpu host,hv_time".)

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-26 08:19:26 +00:00
Michael Brown 302f1eeb80 [time] Allow timer to be selected at runtime
Allow the active timer (providing udelay() and currticks()) to be
selected at runtime based on probing during the INIT_EARLY stage of
initialisation.

TICKS_PER_SEC is now a fixed compile-time constant for all builds, and
is independent of the underlying clock tick rate.  We choose the value
1024 to allow multiplications and divisions on seconds to be converted
to bit shifts.

TICKS_PER_MS is defined as 1, allowing multiplications and divisions
on milliseconds to be omitted entirely.  The 2% inaccuracy in this
definition is negligible when using the standard BIOS timer (running
at around 18.2Hz).

TIMER_RDTSC now checks for a constant TSC before claiming to be a
usable timer.  (This timer can be tested in KVM via the command-line
option "-cpu host,+invtsc".)

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-26 08:17:37 +00:00
Michael Brown d37e025b81 [cpuid] Provide cpuid_supported() to test for supported functions
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-25 20:57:18 +00:00
Michael Brown 70fc25ad6e [netdevice] Limit MTU by hardware maximum frame length
Separate out the concept of "hardware maximum supported frame length"
and "configured link MTU", and limit the latter according to the
former.

In networks where the DHCP-supplied link MTU is inconsistent with the
hardware or driver capabilities (e.g. a network using jumbo frames),
this will result in iPXE advertising a TCP MSS consistent with a size
that can actually be received.

Note that the term "MTU" is typically used to refer to the maximum
length excluding the link-layer headers; we adopt this usage.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-25 14:55:09 +00:00
Michael Brown f450c75dad [interface] Unplug interface before calling intf_close() in intf_shutdown()
The call to intf_close() may result in the original interface being
reopened.  For example: when reading the capacity of a 2TB+ disk via
iSCSI, the SCSI layer will respond to the intf_close() from the READ
CAPACITY (10) command by immediately issuing a READ CAPACITY (16)
command.  The iSCSI layer happens to reuse the same interface for the
new command (since it allows only a single concurrent command).

Currently, intf_shutdown() unplugs the interface after the call to
intf_close() returns.  In the above scenario, this results in
unplugging the just-reopened interface.

Fix by transferring the interface destination (and its reference) to a
temporary interface, and so effectively performing the unplug before
making the call to intf_close().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-25 11:29:29 +00:00
Michael Brown 5ff13830ec [interface] Remove misleading comment
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-25 10:17:48 +00:00
Michael Brown 8ef4e7c572 [interface] Avoid unnecessary reference counting in intf_unplug()
The null interface does not have a reference counter, so the call to
intf_get() is always redundant.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-25 10:16:36 +00:00
Michael Brown 941c53a3bf [efi] Fix building elf2efi.c when -fpic is enabled by default
The x86_64 EDK2 headers include a #pragma to mark all subsequent
symbol declarations and references as hidden if position-independent
code is being generated.  Since libgen.h is currently included only
after the EDK2 headers, this results in __xpg_basename() being
erroneously marked as having hidden visibility (if the compiler
defaults to building position-independent code); this eventually
results in a failure to link the elf2efi binary.

Fix by including libgen.h prior to including the EDK2 headers.

Originally-fixed-by: Doug Goldstein <cardoe@cardoe.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-25 08:15:21 +00:00
Michael Brown bd6255c7be [pic8259] Fix definitions for "read IRR" and "read ISR" commands
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-25 07:37:04 +00:00
Michael Brown 321af68b72 [hyperv] Ignore unsolicited VMBus messages
In some high-end Azure instances (e.g. NC6) we may receive an
unsolicited VMBUS_OFFER_CHANNEL message for a PCIe pass-through device
some time after completing the bus enumeration.  This currently causes
apparently random failures due to unexpected VMBus message types.

Fix by ignoring any unsolicited VMBus messages.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-24 15:03:10 +00:00
Michael Brown 90fc2f273a [cloud] Show CPU vendor and model in example cloud boot scripts
Some problems arise only when running on a specific CPU type (e.g.
non-functional timer interrupts as observed in Azure AMD instances).
Include the CPU vendor and model within the sample cloud boot scripts,
to assist in debugging such problems.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-24 13:47:03 +00:00
Michael Brown 16aed6e5ce [netdevice] Allow MTU to be changed at runtime
Provide a settings applicator to modify netdev->max_pkt_len in
response to changes to the "mtu" setting (DHCP option 26).

Note that as with MAC address changes, drivers are permitted to
completely ignore any changes in the MTU value.  The net result will
be that iPXE effectively uses the smaller of either the hardware
default MTU or the software configured MTU.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-23 17:47:28 +00:00
Michael Brown 4e85b2708f [virtio] Use host-specified MTU when available
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-23 16:32:54 +00:00
Michael Brown de85336abb [cloud] Add ability to retrieve Google Compute Engine metadata
For some unspecified "security" reason, the Google Compute Engine
metadata server will refuse any requests that do not include the
non-standard HTTP header "Metadata-Flavor: Google".

Attempt to autodetect such requests (by comparing the hostname against
"metadata.google.internal"), and add the "Metadata-Flavor: Google"
header if applicable.

Enable this feature in the CONFIG=cloud build, and include a sample
embedded script allowing iPXE to boot from a script configured as
metadata via e.g.

  # Create shared boot image
  make bin/ipxe.usb CONFIG=cloud EMBED=config/cloud/gce.ipxe

  # Configure per-instance boot script
  gcloud compute instances add-metadata <instance> \
         --metadata-from-file ipxeboot=boot.ipxe

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-23 14:43:20 +00:00
Michael Brown 0dc4814ca8 [virtio] Use separate RX and TX empty header buffers
Some host implementations (notably Google Compute Platform) are known
to unconditionally write back VIRTIO_NET_HDR_F_DATA_VALID to
header->flags for received packets, regardless of the features
negotiated by the driver.  This breaks the transmit datapath by
effectively setting an illegal flag for all subsequent transmitted
packets.

Work around this problem by using separate empty header buffers for
the receive and transmit queues.

Debugged-by: Ladi Prosek <lprosek@redhat.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-23 13:27:26 +00:00
David Decotigny b6f524388b [af_packet] Add new AF_PACKET driver for Linux
This code largely inspired by tap.c.  Allows for testing iPXE on real
NICs from within Linux.  For example:

  make bin-x86_64-linux/af_packet.linux
  valgrind ./bin-x86_64-linux/af_packet.linux --net af_packet,if=eth3

Tested as x86_64 and i386 binary.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-22 14:02:54 +00:00
David Decotigny 04c7befa73 [build] Return const char * from uuid_ntoa()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-22 13:45:00 +00:00
Ladi Prosek fba3b39900 [virtio] Remove queue size limit in legacy virtio
Virtio 0.9 implementation was limited to the maximum virtqueue size of
MAX_QUEUE_NUM and the virtio-net driver would fail to initialize on hosts
exceeding this limit.

This commit lifts the restriction by allocating the queue memory based on
the actual queue size instead of using a fixed maximum. Note that virtio
1.0 still uses the MAX_QUEUE_NUM constant to cap the size (unfortunately
this functionality is not available in virtio 0.9).

Signed-off-by: Ladi Prosek <lprosek@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-22 13:22:19 +00:00
Ladi Prosek b782a56be7 [virtio] Simplify virtqueue shutdown
This commit introduces virtnet_free_virtqueues called on all virtqueue
error and shutdown paths. vpm_find_vqs no longer cleans up after itself
and instead expects virtnet_free_virtqueues to be always called to undo
its effect.

Signed-off-by: Ladi Prosek <lprosek@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-22 13:20:42 +00:00
Ladi Prosek e45451c699 [virtio] Cap queue size to MAX_QUEUE_NUM
vpm_find_vqs incorrectly accepted the host provided queue size with no
regard to iPXE's internal limitations. Virtio 1.0 makes it possible for
the driver to override the queue size to reduce memory requirements and
iPXE is a great use case for this feature.

Also removing the extra vq->vring.num assignment which is already
handled in vring_init.

Signed-off-by: Ladi Prosek <lprosek@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-22 13:18:28 +00:00
Michael Brown dfbbc16ae3 [build] Add %.vhd target for building VM bootable disk images
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-22 11:22:11 +00:00
Michael Brown 43b2d8eafb [ipv4] Accept unicast packets for the local network broadcast address
The ISC Kea DHCP server transmits its DHCPOFFER as a unicast packet
with a broadcast IPv4 destination address (255.255.255.255).  This
combination is currently rejected by iPXE.

Fix by explicitly accepting the local network broadcast address
(255.255.255.255) as a valid unicast destination address.

Reported-by: Roy Ledochowski <roy.ledochowski@hpe.com>
Tested-by: Roy Ledochowski <roy.ledochowski@hpe.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2017-01-22 09:12:52 +00:00
Raed Salem 26050fd4c8 [golan] Update Connect-IB, ConnectX-4 and ConnectX-4 Lx (Infiniband) support
Updates:
- Nodnic: Support for arm cq doorbell via the UAR BAR
- Ensure hardware is quiescent when no interface is open - WinPE WA
- Support for clear interrupt via BAR
- Nodnic: Support for send TX doorbells via the UAR BAR
- Added ConnectX-5EX device
- Added ConnectX-5 device

Signed-off-by: Raed Salem <raeds@mellanox.com>
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-12-08 09:35:52 +00:00
Michael Brown 5cf5ffea28 [efi] Work around temporal anomaly encountered during ExitBootServices()
EFI provides no clean way for device drivers to shut down in
preparation for handover to a booted operating system.  The platform
firmware simply doesn't bother to call the drivers' Stop() methods.
Instead, drivers must register an EVT_SIGNAL_EXIT_BOOT_SERVICES event
to be signalled when ExitBootServices() is called, and clean up
without any reference to the EFI driver model.

Unfortunately, all timers silently stop working when ExitBootServices()
is called.  Even more unfortunately, and for no discernible reason,
this happens before any EVT_SIGNAL_EXIT_BOOT_SERVICES events are
signalled.  The net effect of this entertaining design choice is that
any timeout loops on the shutdown path (e.g. for gracefully closing
outstanding TCP connections) may wait indefinitely.

There is no way to report failure from currticks(), since the API
lazily assumes that the host system continues to travel through time
in the usual direction.  Work around EFI's violation of this
assumption by falling back to a simple free-running monotonic counter.

Debugged-by: Maor Dickman <maord@mellanox.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-12-07 13:46:37 +00:00
Michael Brown e09331a4c6 [undi] Try matching UNDI ROMs in BIOS enumeration order
When searching for an UNDI ROM to match against a PCI device, search
in order of increasing ROM address (within the 128kB BIOS option ROM
area).  This is likely (though not guaranteed) to match the order of
the original enumeration performed by the BIOS, which is in turn
likely to match the order of enumeration on the PCI bus.

Since we load at most one UNDI ROM, the net result is that we increase
our chances of loading the ROM corresponding to the selected PCI
device (rather than loading a ROM corresponding to a higher-numbered
PCI device with the same vendor and device IDs.)

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-12-07 07:25:44 +00:00
Michael Brown 80c482c0ed [prefix] Include diagnostic information within progress messages
Include some relevant diagnostic infomation within the progress
messages generated via DEBUG=libprefix.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-12-06 09:38:33 +00:00
Michael Brown ce81601181 [prefix] Remove impossible progress message
The "progress" macro can be used only from within the .prefix section.
At the point of calling relocate(), we are running in .text16 and so
the near call to print_message() will end up calling a random function
somewhere in .text16.

Interestingly, this problem has remained unnoticed for some time.  It
is rare to build with DEBUG=libprefix.  In the few cases that it has
been used during development, the randomly selected function in
.text16 seems to have been a harmless no-op with no visible
side-effects (beyond the unnoticed failure to print the "relocate"
progress message).

Fix by removing the futile attempt to print a progress message before
calling relocate().

Reported-by: Raed Salem <raeds@mellanox.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-12-06 07:44:10 +00:00
Michael Brown 6997d3c2fa [undi] Clean up driver and device name information
Fix the <NULL> driver name reported by "ifstat" when using the undipci
driver (due to the unnecessary extra device node inserted as a child
of the PCI device).

Remove the "UNDI-" prefix from device names since the driver name is
also now visible via "ifstat", and tidy up the device name to match
the format used by standard PCI devices.

The output from "ifstat" now resembles:

  iPXE> ifstat
  net0: 52:54:00:12:34:56 using undipci on 0000:00:03.0

  iPXE> ifstat
  net0: 52:54:00:12:34:56 using undionly on 0000:00:03.0

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-12-05 15:48:37 +00:00
Michael Brown cc40fcbf8b [romprefix] Avoid using PMM-allocated memory in UNDI loader entry point
The UNDI loader entry point is very likely to be called after POST,
when there is a high chance that the PMM-allocated image source area
and decompression area have been reused by something else.

In particular, using an iPXE .iso to test a separate iPXE ROM's UNDI
loader entry point in a qemu VM is likely to crash.  SeaBIOS allocates
PMM blocks from close to the top of memory and so these blocks have a
high chance of colliding with the runtime addresses subsequently
chosen by the non-ROM iPXE by scanning the INT 15,e820 memory map.

The standard romprefix.S has no choice about relying on the
PMM-allocated image source area, since it has no other way to retrieve
its compressed payload.

In mromprefix.S, the image source area functions only as an optional
buffer used to avoid repeated reads from the (potentially slow)
expansion ROM BAR by the decompression code.  We can therefore always
set %esi=0 when calling install_prealloc from the UNDI loader entry
point, and simply fall back to reading directly from the expansion ROM
BAR.

We can always set %edi=0 when calling install_prealloc from the UNDI
loader entry point.  This will behave as though the decompression area
PMM allocation failed, and will therefore use INT 15,88 to find a
temporary decompression area somewhere close to 64MB.  This is by no
means guaranteed to be safe from collisions, but it's probably safer
on balance than the PMM-allocated address.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-12-05 15:21:45 +00:00
Michael Brown 8138ea190d [undi] Allocate base memory before calling UNDI loader entry point
Allocate base memory (by decreasing the free base memory counter)
before calling the UNDI loader entry point, to minimise surprises for
the UNDI loader code.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-12-05 08:53:44 +00:00
Michael Brown fd95c780b6 [efi] Add basic EFI SAN booting capability
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-11-16 23:03:37 +00:00
Michael Brown 81fceaec6e [iscsi] Avoid potential infinite loops during shutdown
The command and data interfaces may be connected to the same object.
Nullify the data interface before shutting down the control interface
to avoid potential infinite loops.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-11-16 23:03:37 +00:00
Michael Brown daa8ed9274 [interface] Provide intf_reinit() to reinitialise nullified interfaces
Provide an abstraction intf_reinit() to restore the descriptor of a
previously nullified interface.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-11-16 22:22:13 +00:00
Laszlo Ersek b991c67c1d [build] Disable TIVOLI_VMM_WORKAROUND in the qemu configuration
This prevents KVM guests from crashing that run iPXE on host CPUs
without "unrestricted_guest" support.

Once KVM gets the FXSAVE / FXRSTOR emulation feature (*), and the
feature becomes widely available to users, we can back out this change
from iPXE.

(*) Already in progress by Radim:

    [PATCH 0/2] KVM: x86: emulate fxsave and fxrstor

    https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1258895.html
    https://www.spinics.net/lists/kernel/msg2370327.html

Cc: Bandan Das <bsd@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Greg <rollenwiese@yahoo.com>
Cc: Michael Brown <mcb30@ipxe.org>
Cc: Michael Prokop <launchpad@michael-prokop.at>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Pickford <arch@netremedies.ca>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Ref: https://bugs.archlinux.org/task/50778
Ref: https://bugs.launchpad.net/qemu/+bug/1623276
Ref: https://bugzilla.proxmox.com/show_bug.cgi?id=1182
Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1356762
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-11-08 17:40:01 +00:00
Laszlo Ersek dd9a14de35 [librm] Conditionalize the workaround for the Tivoli VMM's SSE garbling
Commit 71560d1 ("[librm] Preserve FPU, MMX and SSE state across calls
to virt_call()") added FXSAVE and FXRSTOR instructions to iPXE.  In
KVM virtual machines, these instructions execute fine as long as the
host CPU supports the "unrestricted_guest" feature (that is, it can
virtualize big real mode natively).  On older host CPUs however, KVM
has to emulate big real mode, and it currently doesn't implement
FXSAVE emulation.

Upstream QEMU rebuilt iPXE at commit 0418631 ("[thunderx] Fix
compilation with older versions of gcc") which is a descendant of
commit 71560d1 (see above).

This was done in QEMU commit ffdc5a2 ("ipxe: update submodule from
4e03af8ec to 041863191").  The resultant binaries were bundled with
the QEMU v2.7.0 release; see QEMU commit c52125a ("ipxe: update
prebuilt binaries").

This distributed the iPXE workaround for the Tivoli VMM bug to a
number of KVM users with old host CPUs, causing KVM emulation failures
(guest crashes) for them while netbooting.

Make the FXSAVE and FXRSTOR instructions conditional on a new feature
test macro called TIVOLI_VMM_WORKAROUND.  Define the macro by default.

There is prior art for an assembly file including config/general.h:
see arch/x86/prefix/romprefix.S.  Also, TIVOLI_VMM_WORKAROUND seems to
be a good fit for the "Obscure configuration options" section in
config/general.h.

Cc: Bandan Das <bsd@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Greg <rollenwiese@yahoo.com>
Cc: Michael Brown <mcb30@ipxe.org>
Cc: Michael Prokop <launchpad@michael-prokop.at>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Pickford <arch@netremedies.ca>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Ref: https://bugs.archlinux.org/task/50778
Ref: https://bugs.launchpad.net/qemu/+bug/1623276
Ref: https://bugzilla.proxmox.com/show_bug.cgi?id=1182
Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1356762
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-11-08 17:37:59 +00:00
Michael Brown aa11f5deda [bzimage] Fix page alignment of initrd images
The initrd_addr_max field represents the highest byte address that may
be used to hold initrd images, and is therefore almost certainly not
aligned to a page boundary: a typical value might be 0x7fffffff.

Fix the address calculations to ensure that the initrd images are
always aligned to a page boundary.

Reported-by: Sitsofe Wheeler <sitsofe@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-10-29 00:32:33 +01:00
Michael Brown 0be77e959e [efi] Add EFI_BLOCK_IO2_PROTOCOL header and GUID definition
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-10-16 23:27:50 +01:00
Michael Brown f796d5b6b6 [efi] Update to current EDK2 headers
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-10-16 17:08:02 +01:00
Michael Brown 54dcfed375 [efi] Mark AppleNetBoot.h as a native iPXE header
AppleNetBoot.h is not taken from the EDK2 codebase and so cannot be
imported using include/ipxe/efi/import.pl.  Mark as a native iPXE
header (by changing the include guard) to avoid breaking the import
process.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-10-16 17:08:02 +01:00
Michael Brown 827dd1bfee [crypto] Mark permanent certificates as permanent
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-08-31 17:23:42 +01:00
Michael Brown eed1258038 [cmdline] Add certificate management commands
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-08-31 17:11:14 +01:00
Michael Brown 1e277ab062 [crypto] Add certstat() to display basic certificate information
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-08-31 15:41:15 +01:00
Michael Brown 9a1a42f283 [crypto] Allow certificates to be marked as having been added explicitly
Allow certificates to be marked as having been added explicitly at run
time.  Such certificates will not be discarded via the certificate
store cache discarder.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-08-31 15:41:02 +01:00
Michael Brown 534eae4d92 [crypto] Expose certstore_del() to explicitly remove stored certificates
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-08-31 15:17:31 +01:00
Michael Brown 161c80af5b [list] Add list_next_entry() and list_prev_entry()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-08-31 15:06:36 +01:00
Michael Brown ff28b22568 [crypto] Generalise X.509 "valid" field to a "flags" field
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-08-25 15:41:57 +01:00
Michael Brown e564a4e7d6 [crypto] Add image_x509() to extract X.509 certificates from image
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-08-25 15:41:25 +01:00
Michael Brown 2afd66eb55 [pixbuf] Enable PNG format by default
Enable IMAGE_PNG (but not IMAGE_PNM) by default, and drag in the
relevant objects only when image_pixbuf() is present in the binary.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-29 16:04:09 +01:00
Michael Brown 1090839b94 [build] Remove more obsolete explicit object requirements
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-29 15:56:10 +01:00
Michael Brown 942b798c8d [crypto] Enable both DER and PEM formats by default
Enable both IMAGE_DER and IMAGE_PEM by default, and drag in the
relevant objects only when image_asn1() is present in the binary.

This allows "imgverify" to transparently use either DER or PEM
signature files.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-29 15:40:39 +01:00
Michael Brown b7e43b0335 [build] Remove obsolete explicit object requirements
As of commit b1caa48 ("[crypto] Support SHA-{224,384,512} in X.509
certificates"), the list of supported cryptographic algorithms is
controlled by config/crypto.h.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-29 15:18:35 +01:00
Michael Brown 829fedafcb [image] Use image_asn1() to extract data from CMS signature images
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-29 15:03:20 +01:00
Michael Brown 84add97ce9 [crypto] Add PEM image format
Add PEM-encoded ASN.1 as an image format.  We accept as PEM any image
containing a line starting with a "-----BEGIN" boundary marker.

We allow for PEM files containing multiple ASN.1 objects, such as a
certificate chain produced by concatenating individual certificate
files.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-29 01:13:27 +01:00
Michael Brown eb7188d04b [crypto] Add DER image format
Add DER-encoded ASN.1 as an image format.  There is no fixed signature
for DER files.  We treat an image as DER if it comprises a single
valid SEQUENCE object covering the entire length of the image.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-29 01:12:58 +01:00
Michael Brown ef50608029 [image] Add image_asn1() to extract ASN.1 objects from image
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-29 00:41:36 +01:00
Michael Brown 296670a648 [crypto] Allow for parsing of partial ASN.1 cursors
Allow code to create a partial ASN.1 cursor containing only the type
and length bytes, so that asn1_start() may be used to determine the
length of a large ASN.1 blob without first allocating memory to hold
the entire blob.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-28 15:02:15 +01:00
Michael Brown 5846ce2e9e [crypto] Remove obsolete extern declaration for asn1_invalidate_cursor()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-28 15:00:26 +01:00
Michael Brown 145aae3998 [hyperv] Use instance UUID in device name
The Windows drivers for VMBus devices are enumerated using the
instance UUID rather than the channel number.  Include the instance
UUID within the iPXE device name to allow an iPXE network device to be
more easily associated with the corresponding Windows network device
when debugging.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-26 16:27:12 +01:00
Michael Brown a4c4f72297 [ipv6] Allow for multiple routers
Select the IPv6 source address and corresponding router (if any) using
a very simplified version of the algorithm from RFC6724:

- Ignore any source address that has a smaller scope than the
  destination address.  For example, do not use a link-local source
  address when sending to a global destination address.

- If we have a source address which is on the same link as the
  destination address, then use that source address.

- If we are left with multiple possible source addresses, then choose
  the address with the smallest scope.  For example, if we are sending
  to a site-local destination address and we have both a global source
  address and a site-local source address, then use the site-local
  source address.

- If we are still left with multiple possible source addresses, then
  choose the address with the longest matching prefix.

For the purposes of this algorithm, we treat RFC4193 Unique Local
Addresses as having organisation-local scope.  Since we use only
link-local scope for our multicast transmissions, this approximation
should remain valid in all practical situations.

Originally-implemented-by: Thomas Bächler <thomas@archlinux.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-25 15:20:22 +01:00
Michael Brown a454baaf11 [test] Update IPv6 tests to use okx()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-25 13:44:16 +01:00
Michael Brown daa1a59310 [ipv6] Rename ipv6_scope to ipv6_settings_scope
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-21 15:47:45 +01:00
Michael Brown c34d1518eb [ipv6] Create routing table based on IPv6 settings
Use the IPv6 settings to construct the routing table, in a matter
analogous to the construction of the IPv4 routing table.

This allows for manual assignment of IPv6 addresses via e.g.

  set net0/ip6 2001:ba8:0:1d4::6950:5845
  set net0/len6 64
  set net0/gateway6 fe80::226:bff:fedd:d3c0

The prefix length ("len6") may be omitted, in which case a default
prefix length of 64 will be assumed.

Multiple IPv6 addresses may be assigned manually by implicitly
creating child settings blocks.  For example:

  set net0/ip6 2001:ba8:0:1d4::6950:5845
  set net0.ula/ip6 fda4:2496:e992::6950:5845

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-20 13:02:44 +01:00
Michael Brown 4ad3c73b30 [ipv6] Match user expectations for IPv6 settings priorities
A reasonable user expectation is that ${net0/ip6} should show the
"highest-priority" of the IPv6 addresses, even when multiple IPv6
addresses are active.  The expected order of priority is likely to be
manually-assigned addresses first, then stateful DHCPv6 addresses,
then SLAAC addresses, and lastly link-local addresses.

Using ${priority} to enforce an ordering is undesirable since that
would affect the priority assigned to each of the net<N> blocks as a
whole, so use the sibling ordering capability instead.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-19 17:07:53 +01:00
Michael Brown f5cf4f706e [settings] Allow settings blocks to specify a sibling ordering
Allow settings blocks to provide an explicit default ordering between
siblings, with lower precedence than the existing ${priority} setting.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-19 17:07:53 +01:00
Michael Brown 1fdc7da435 [ipv6] Expose IPv6 link-local address settings
Originally-implemented-by: Hannes Reinecke <hare@suse.de>
Originally-implemented-by: Marin Hannache <git@mareo.fr>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-19 14:35:30 +01:00
Michael Brown 03d19cf14d [dhcpv6] Expose IPv6 address setting acquired through DHCPv6
Originally-implemented-by: Hannes Reinecke <hare@suse.de>
Originally-implemented-by: Marin Hannache <git@mareo.fr>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-19 01:20:34 +01:00
Michael Brown 3b783d7fd2 [ipv6] Expose IPv6 settings acquired through NDP
Expose the IPv6 address (or prefix) as ${ip6}, the prefix length as
${len6}, and the router address as ${gateway6}.

Originally-implemented-by: Hannes Reinecke <hare@suse.de>
Originally-implemented-by: Marin Hannache <git@mareo.fr>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-19 00:13:00 +01:00
Michael Brown ee54ab5be6 [ipv6] Allow settings to comprise arbitrary subsets of NDP options
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-19 00:13:00 +01:00
Michael Brown 0ac874242b [settings] Correctly mortalise autovivified child settings blocks
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-19 00:13:00 +01:00
Michael Brown 129206f476 [ipv6] Rename ipv6_scope to dhcpv6_scope
The settings scope ipv6_scope refers specifically to IPv6 settings
that have a corresponding DHCPv6 option.  Rename to dhcpv6_scope to
more accurately reflect this purpose.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-16 12:42:08 +01:00
Michael Brown ecfc81d76f [settings] Create space for IPv6 in settings display order
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-15 17:39:49 +01:00
Michael Brown c53a209a42 [ipv6] Perform SLAAC only during autoconfiguration
We currently perform IPv6 stateless address autoconfiguration (SLAAC)
in response to any router advertisement with the relevant flags set.
This can result in the local IPv6 source address changing midway
through a TCP connection, since our connections bind only to a local
port number and do not store a local network address.

In addition, this behaviour for SLAAC is inconsistent with that for
DHCPv4 and stateful DHCPv6, both of which will be performed only as a
result of an explicit autoconfiguration action (e.g. via the default
autoboot sequence, or the "ifconf" command).

Fix by ignoring router advertisements arriving outside the context of
an ongoing autoconfiguration attempt.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-15 15:58:47 +01:00
Michael Brown 517d234031 [intel] Remove duplicate intelvf_mbox_queues() function
Commit db34436 ("[intel] Strip spurious VLAN tags received by virtual
function NICs") accidentally introduced two copies of the
intel[x]vf_mbox_queues() function.  Remove the unintended copy.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-14 13:51:07 +01:00
Michael Brown db3443608f [intel] Strip spurious VLAN tags received by virtual function NICs
The physical function may be configured to transparently insert a VLAN
tag into all transmitted packets.  Unfortunately, it does not
equivalently strip this same VLAN tag from all received packets.  This
behaviour may be observed in some Amazon EC2 instances with Enhanced
Networking enabled: transmissions work as expected but all packets
received by iPXE appear to have a spurious VLAN tag.

We can configure the receive queue to strip VLAN tags via the
RXDCTL.VME bit.  We need to find out from the PF driver whether or not
we should do so.

There exists a "get queue configuration" mailbox message which
contains a field labelled IXGBE_VF_TRANS_VLAN in the Linux driver.

A comment in the Linux PF driver describes this field as "notify VF of
need for VLAN tag stripping, and correct queue".  It will be filled
with a non-zero value if the PF is enforcing the use of a single VLAN
tag.  It will also be filled with a non-zero value if the PF is using
multiple traffic classes.

The Linux VF driver seems to treat this field as being simply the
number of traffic classes, and gives it no VLAN-related
interpretation.  The Linux VF driver instead handles the VLAN tag
stripping by simply assuming that any unrecognised VLAN tag ought to
be silently dropped.

We choose to strip and ignore the VLAN tag if the IXGBE_VF_TRANS_VLAN
field has a non-zero value.

Reported-by: Leonid Vasetsky <leonidv@velostrata.com>
Tested-by: Leonid Vasetsky <leonidv@velostrata.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-12 09:14:41 +01:00
Michael Brown 45dd627689 [ipv4] Send gratuitous ARPs whenever a new IPv4 address is applied
In a busy network (such as a public cloud), IPv4 addresses may be
recycled rapidly.  When this happens, unidirectional traffic (such as
UDP syslog) will succeed, but bidirectional traffic (such as TCP
connections) may fail due to stale ARP cache entries on other nodes.
The remote ARP cache expiry timeout is likely to exceed iPXE's
connection timeout, meaning that boot attempts can fail before the
problem is automatically resolved.

Fix by sending gratuitous ARPs whenever an IPv4 address is changed, to
attempt to update stale remote ARP cache entries.  Note that this is
not a guaranteed fix, since ARP is an unreliable protocol.

We avoid sending gratuitous ARPs unconditionally, since otherwise any
unrelated settings change (e.g. "set dns 192.168.0.1") would cause
unexpected gratuitous ARPs to be sent.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-12 09:01:01 +01:00
Lukas Grossar 23c275bd1e [intel] Add PCI device ID for I219-V/LM
Signed-off-by: Lukas Grossar <lukas.grossar@adfinis-sygroup.ch>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-12 05:51:10 +01:00
Michael Brown df85901768 [acpi] Allow time for ACPI power off to take effect
The ACPI power off sequence may not take effect immediately.  Delay
for one second, to eliminate potentially confusing log messages such
as "Could not power off: Error 0x43902001 (http://ipx".

Reported-by: Leonid Vasetsky <leonidv@velostrata.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-11 21:23:03 +01:00
Michael Brown e19c0a8fd2 [acpi] Add support for ACPI power off
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-11 14:05:18 +01:00
Michael Brown 74222cd2c1 [rng] Check for functioning RTC interrupt
On some platforms (observed in a small subset of Microsoft Azure
(Hyper-V) virtual machines), the RTC appears to be incapable of
generating an interrupt via the legacy PIC.  The RTC status registers
show that a periodic interrupt has been asserted, but the PIC IRR
shows that IRQ8 remains inactive.

On such systems, iPXE will currently freeze during the "iPXE
initialising devices..." message.

Work around this problem by checking that RTC interrupts are being
raised before returning from rtc_entropy_enable().  If no interrupt is
seen within 100ms, then we assume that the RTC interrupt mechanism is
broken.  In these circumstances, iPXE will continue to initialise but
any subsequent attempt to generate entropy will fail.  In particular,
HTTPS connections will fail with an error indicating that no entropy
is available.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-10 20:42:53 +01:00
Laszlo Ersek d6817943d1 [efi] Install the HII config access protocol on a child of the SNP handle
In edk2, there are several drivers that associate HII forms (and
corresponding config access protocol instances) with each individual
network device.  (In this context, "network device" means the EFI
handle on which the SNP protocol is installed, and on which the device
path ending with the MAC() node is installed also.)  Such edk2 drivers
are, for example: Ip4Dxe, HttpBootDxe, VlanConfigDxe.

In UEFI, any given handle can carry at most one instance of a specific
protocol (see e.g. the specification of the InstallProtocolInterface()
boot service).  This implies that the class of drivers mentioned above
can't install their EFI_HII_CONFIG_ACCESS_PROTOCOL instances on the
SNP handle directly -- they would conflict with each other.
Accordingly, each of those edk2 drivers creates a "private" child
handle under the SNP handle, and installs its config access protocol
(and corresponding HII package list) on its child handle.

The device path for the child handle is traditionally derived by
appending a Hardware Vendor Device Path node after the MAC() node.
The VenHw() nodes in question consist of a GUID (by definition), and
no trailing data (by choice).  The purpose of these VenHw() nodes is
only that all the child nodes can be uniquely identified by device
path.

At the moment iPXE does not follow this pattern.  It doesn't run into
a conflict when it installs its EFI_HII_CONFIG_ACCESS_PROTOCOL
directly on the SNP handle, but that's only because iPXE is the sole
driver not following the pattern.  This behavior seems risky (one
might call it a "latent bug"); better align iPXE with the edk2 custom.

Cc: Michael Brown <mcb30@ipxe.org>
Cc: Gary Lin <glin@suse.com>
Cc: Ladi Prosek <lprosek@redhat.com>
Ref: http://thread.gmane.org/gmane.comp.bios.edk2.devel/13494/focus=13532
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Ladi Prosek <lprosek@redhat.com>
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-08 14:16:32 +01:00
Michael Brown 5430465185 [profile] Allow profiling to be globally enabled or disabled
As with assertions, profiling is enabled for objects built with any
debug level (including an explicit debug level of zero).

Allow profiling to be globally enabled or disabled by adding PROFILE=1
or PROFILE=0 respectively to the build command line.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-05 13:49:51 +01:00
Michael Brown 46719f2264 [libc] Allow assertions to be globally enabled or disabled
Assertions are enabled for objects built with any debug level
(including an explicit debug level of zero).  It is sometimes useful
to be able to enable assertions across all objects; this currently
requires manually hacking include/assert.h.

Allow assertions to be globally enabled by adding ASSERT=1 to the
build command line.  For example:

  make bin/8086100e.mrom ASSERT=1

Similarly, allow assertions to be globally disabled by adding ASSERT=0
to the build command line.  If no ASSERT=... is specified on the
build command line, then only objects mentioned in DEBUG=... will have
assertions enabled (as is currently the case).

Note than globally enabling assertions imposes a relatively heavy
runtime penalty, primarily due to the various sanity checks performed
by list_add(), list_for_each_entry(), etc.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-05 13:28:51 +01:00
Michael Brown 6e1ce52d14 [debug] Allow debug messages to be initially disabled at runtime
Extend the DEBUG=... syntax to allow debug messages to be compiled in
but disabled by default.  For example:

  make bin/undionly.kpxe DEBUG=netdevice:3:1

would compile in the messages as for DEBUG=netdevice:3, but would set
the debug level mask so that only the DEBUG=netdevice:1 messages would
be displayed.

This allows for external code to selectively enable the additional
debug messages at runtime, without being overwhelmed by unwanted
initial noise.  For example, a developer of a new protocol may want to
temporarily enable tracing of all packets received: this can be done
by building with DEBUG=netdevice:3:1 and using

  // temporarily enable per-packet messages
  DBG_ENABLE_OBJECT ( netdevice, DBGLVL_EXTRA );
  ...
  // disable per-packet messages
  DBG_DISABLE_OBJECT ( netdevice, DBGLVL_EXTRA );

Note that unlike the usual DBG_ENABLE() and DBG_DISABLE() macros,
DBG_ENABLE_OBJECT() and DBG_DISABLE_OBJECT() will not be removed via
dead code elimination if debugging is disabled in the specified
object.  In particular, this means that using either of these macros
will always result in a symbol reference to the specified object.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-05 12:34:15 +01:00
Michael Brown e2c0a20d60 [debug] Allow per-object runtime enabling/disabling of debug messages
The DBG_ENABLE() and DBG_DISABLE() macros currently affect the debug
level of all objects that were built with debugging enabled.  This is
undesirable, since it is common to use different debug levels in each
object.

Make the debug level mask a per-object variable.  DBG_ENABLE() and
DBG_DISABLE() now control only the debug level for the containing
object (which is consistent with the intended usage across the
existing codebase).  DBG_ENABLE_OBJECT() and DBG_DISABLE_OBJECT() may
be used to control the debug level for a specified object.  For
example:

  // Enable DBG() messages from tcpip.c
  DBG_ENABLE_OBJECT ( tcpip, DBGLVL_LOG );

Note that the existence of debug messages continues to be gated by the
DEBUG=... list specified on the build command line.  If an object was
built without the relevant debug level, then DBG_ENABLE_OBJECT() will
have no effect on that object at runtime (other than to explicitly
drag in the object via a symbol reference).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-05 10:27:22 +01:00
Michael Brown 55f7a675d6 [iscsi] Treat redirection failures as fatal
Debugged-by: Robin Smidsrød <robin@smidsrod.no>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-04 16:20:07 +01:00
Michael Brown 89c6db838f [downloader] Treat redirection failures as fatal
Debugged-by: Robin Smidsrød <robin@smidsrod.no>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-04 16:20:01 +01:00
Michael Brown 5e2a7481ad [xfer] Send intf_close() if redirection fails
A redirection failure is fatal, but provides no opportunity for the
caller of xfer_[v]redirect() to report the failure since the interface
will already have been disconnected.  Fix by sending intf_close() from
within the default xfer_vredirect() handler.

Debugged-by: Robin Smidsrød <robin@smidsrod.no>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-04 16:14:46 +01:00
Michael Brown aeb6203811 [dhcp] Automatically generate vendor class identifier string
The vendor class identifier strings in DHCP_ARCH_VENDOR_CLASS_ID are
out of sync with the (correct) client architecture values in
DHCP_ARCH_CLIENT_ARCHITECTURE.

Fix by removing all definitions of DHCP_ARCH_VENDOR_CLASS_ID, and
instead generating the vendor class identifier string automatically
based on DHCP_ARCH_CLIENT_ARCHITECTURE and DHCP_ARCH_CLIENT_NDI.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-04 15:07:05 +01:00
Michael Brown d7f1834b5e [dhcpv6] Include vendor class identifier option in DHCPv6 requests
RFC3315 defines DHCPv6 option 16 (vendor class identifier) but does
not define any direct relationship with the roughly equivalent DHCPv4
option 60.

The PXE specification predates IPv6, and the UEFI specification is
expectedly vague on the subject.  Examination of the reference EDK2
codebase suggests that the DHCPv6 vendor class identifier will be
formatted in accordance with RFC3315, using a single vendor-class-data
item in which the opaque-data field is the string as would appear in
DHCPv4 option 60.

RFC3315 requires the vendor class identifier to specify an IANA
enterprise number, as a way of disambiguating the vendor-class-data
namespace.  The EDK2 code uses the value 343, described as:

    // TODO: IANA TBD: temporarily using Intel's

Since this "TODO" has been present since at least 2010, it is probably
safe to assume that it has now become a de facto standard.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-04 14:08:26 +01:00
Michael Brown fda8916c83 [dhcpv6] Include RFC5970 client architecture options in DHCPv6 requests
RFC5970 defines DHCPv6 options 61 (client system architecture type)
and 62 (client network interface identifier), with contents equivalent
to DHCPv4 options 93 and 94 respectively.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-04 13:18:49 +01:00
Michael Brown 3d9f094022 [dhcp] Allow for variable encapsulation of architecture-specific options
DHCPv4 and DHCPv6 share some values in common for the architecture-
specific options (such as the client system architecture type), but
use different encapsulations: DHCPv4 has a single byte for the option
length while DHCPv6 has a 16-bit field for the option length.

Move the containing DHCP_OPTION() and related wrappers from the
individual dhcp_arch.h files to dhcp.c, thus allowing for the
architecture-specific values to be reused in dhcpv6.c.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-04 13:15:05 +01:00
Michael Brown 3bb61c33c2 [pxe] Disable interrupts on the PIC before starting NBP
Some BIOSes (observed with an HP Gen9) seem to spuriously enable
interrupts at the PIC.  This causes problems with NBPs such as GRUB
which use the UNDI API (thereby enabling interrupts on the NIC)
without first hooking an interrupt service routine.  In this
situation, the interrupt will end up being handled by the default BIOS
ISR, which will typically just send an EOI and return.  Since nothing
in this handler causes the NIC to deassert the interrupt, this will
result in an interrupt storm.

Entertainingly, some BIOSes are immune to this problem because the
default ISR sends the EOI only to the slave PIC; this effectively
disables the interrupt.

Work around this problem by disabling the interrupt on the PIC before
invoking the PXE NBP.  An NBP that expects to make use of interrupts
will need to be configuring the PIC anyway, so it is probably safe to
assume that it will explicitly reenable the interrupt.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-03 12:52:20 +01:00
Michael Brown c22da4b8ba [bios] Do not enable interrupts when printing to the console
There seems to be no reason for the sti/cli pair used around each call
to INT 10.  Remove these instructions, so that printing debug messages
from within an ISR does not temporarily reenable interrupts.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-07-03 12:50:19 +01:00
Michael Brown c9f6a86059 [efi] Fix uninitialised data in HII IFR structures
The HII IFR structures are allocated via realloc() rather than
zalloc(), and so are not automatically zeroed.  This results in the
presence of uninitialised and invalid data, causing crashes elsewhere
in the UEFI firmware.

Fix by explicitly zeroing the newly allocated portion of any IFR
structure in efi_ifr_op().

Debugged-by: Laszlo Ersek <lersek@redhat.com>
Debugged-by: Gary Lin <glin@suse.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-29 15:17:12 +01:00
Michael Brown 0418631918 [thunderx] Fix compilation with older versions of gcc
Remove redundant duplicate typedef which causes a build failure on
older gcc versions.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-22 12:07:55 +01:00
Michael Brown 632e57f0f3 [efi] Do not copy garbage bytes into SNP device path MAC address
The SNP device path includes the network device's MAC address within
the MAC_ADDR_DEVICE_PATH.MacAddress field.  We check that the
link-layer address will fit within this field, and then perform the
copy using the length of the destination buffer.

At 32 bytes, the MacAddress field is actually larger than the current
maximum iPXE link-layer address.  The copy therefore overflows the
source buffer, resulting in trailing garbage bytes being appended to
the device path's MacAddress.  This is invisible in debug messages,
since the DevicePathToText protocol will render only the length
implied by the interface type.

Fix by copying only the actual length of the link-layer address (which
we have already verified will not overflow the destination buffer).

Debugged-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-22 09:07:20 +01:00
Michael Brown 694c18addc [efi] Report failures to stop the EFI timer tick event
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-20 16:08:17 +01:00
Michael Brown c9176878ef [smsc75xx] Allow up to 100ms for reset to complete
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-20 14:26:37 +01:00
Ladi Prosek 040aa980d6 [virtio] Fix virtio-pci logging
iPXE debug logging doesn't support %u.  This commit replaces it with
%d in virtio-pci debug format strings.

Signed-off-by: Ladi Prosek <lprosek@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-20 14:23:53 +01:00
Ladi Prosek fbbc895442 [virtio] Renumber virtio_pci_region flags
Some of the regions may end up being unmapped, either because they are
optional or because the attempt to map them has failed.  Region types
starting at 0 didn't make it easy to test for this condition.

This commit bumps all valid region types up by 1 with 0 having the
implicit 'unmapped' meaning.

Signed-off-by: Ladi Prosek <lprosek@redhat.com>
Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-20 14:20:21 +01:00
Michael Brown 25ae251dd9 [thunderx] Retrieve base MAC address via EFI_THUNDER_CONFIG_PROTOCOL
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-18 19:28:38 +01:00
Michael Brown 8f0bec4346 [efi] Include VLAN in SNP device path if applicable
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-18 18:45:18 +01:00
Christian Nilsson ec992b97c2 [intel] Add PCI device ID for another I219-LM
Tested-by: Kuniyasu Suzaki <k.suzaki@aist.go.jp>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-16 11:42:24 +01:00
Michael Brown cf52436c71 [thunderx] Fix channel configuration for VNICs 1-7
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-15 20:32:06 +01:00
Michael Brown 4775dd3835 [thunderx] Add driver for Cavium ThunderX SoC NICs
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-13 18:41:26 +01:00
Michael Brown 3c61e11fe1 [cmdline] Add "ntp" command
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-13 15:57:16 +01:00
Michael Brown fce6117ad9 [ntp] Add simple NTP client
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-13 15:55:49 +01:00
Michael Brown e6111c1517 [time] Allow system clock to be adjusted at runtime
Provide a mechanism to allow an arbitrary adjustment to be applied to
all subsequent calls to time().

Note that the underlying clock source (e.g. the RTC clock) will not be
changed; only the time as reported within iPXE will be affected.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-13 15:29:05 +01:00
Leendert van Doorn 02d5cfff22 [tg3] Add missing memory barrier
ARM64 has a weaker memory order model than x86.  The missing memory
barrier caused phy initialization notification to be delayed beyond
the link-wait timeout (15 secs).

Signed-off-by: Leendert van Doorn <leendert@paramecium.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-13 15:14:43 +01:00
Michael Brown 188789eb3c [tcp] Send TCP keepalives on idle established connections
In some circumstances, intermediate devices may lose state in a way
that temporarily prevents the successful delivery of packets from a
TCP peer.  For example, a firewall may drop a NAT forwarding table
entry.

Since iPXE spends most of its time downloading files (and hence purely
receiving data, sending only TCP ACKs), this can easily happen in a
situation in which there is no reason for iPXE's TCP stack to generate
any retransmissions.  The temporary loss of connectivity can therefore
effectively become permanent.

Work around this problem by sending TCP keepalives after a period of
inactivity on an established connection.

TCP keepalives usually send a single garbage byte in sequence number
space that has already been ACKed by the peer.  Since we do not need
to elicit a response from the peer, we instead send pure ACKs (with no
garbage data) in order to keep the transmit code path simple.

Originally-implemented-by: Ladi Prosek <lprosek@redhat.com>
Debugged-by: Ladi Prosek <lprosek@redhat.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-13 09:58:32 +01:00
Leendert van Doorn 5c2a959a72 [tg3] Fix address truncation bug on 64-bit machines
Signed-off-by: Leendert van Doorn <leendert@paramecium.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-10 15:45:19 +01:00
Michael Brown b42e71921f [http] Accept headers with no whitespace following the colon
Reported-by: Raphael Cohn <raphael.cohn@stormmq.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-09 12:27:04 +01:00
Michael Brown f76210961c [pci] Support systems with multiple PCI root bridges
Extend the 16-bit PCI bus:dev.fn address to a 32-bit seg🚌dev.fn
address, assuming a segment value of zero in contexts where multiple
segments are unsupported by the underlying data structures (e.g. in
the iBFT or BOFM tables).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-09 09:36:28 +01:00
Michael Brown 2c197517f2 [libc] Always use a non-zero seed for the (non-crypto) RNG
The non-cryptographic RNG implemented by random() has the property
that a seed value of zero will result in a generated sequence of
all-zero values.  This situation can arise if currticks() returns zero
at start of day.

Work around this problem by falling back to a fixed non-zero seed if
necessary.

This has no effect on the separate DRBG used by cryptographic code.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-09 08:44:32 +01:00
Vinson Lee f6e8b800be [build] Remove nested "my" declaration
Fix build error with perl >= 5.23.2:

  Can't redeclare "my" in "my" at ./util/parserom.pl line 160

Signed-off-by: Vinson Lee <vlee@freedesktop.org>
Reviewed-by: Robin Smidsrød <robin@smidsrod.no>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-06-03 18:09:54 +01:00
Michael Brown aa4b038c70 [efi] Expose DHCP packets via the Apple NetBoot protocol
Mac OS X uses non-standard EFI protocols to obtain the DHCP packets
from the UEFI firmware.

Originally-implemented-by: Michael Kuron <m.kuron@gmx.de>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-29 13:10:14 +01:00
Michael Brown af9afd0a86 [dhcp] Fix definitions for x86_64 and EFI BC client architectures
There has been a longstanding disagreement between RFC4578 and the
IANA "Processor Architecture Types" registry.  RFC4578 section 2.1
defines type 7 as "EFI BC" and type 9 as "EFI x86-64"; the IANA
registry quotes RFC4578 as its source but has these values erroneously
swapped.  The EDK2 codebase uses the IANA values.

As of March 2016, RFC4578 has been modified by an errata to match the
values as recorded in the IANA registry.

Fix our definitions to match the consensus values.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-26 13:58:37 +01:00
Michael Brown 31d4a7b8db [arm] Use correct DHCP client architecture values
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-26 13:43:33 +01:00
Michael Brown ee5dfb75aa [axge] Add driver for ASIX 10/100/1000 USB Ethernet NICs
Add driver for the AX88178A (USB2) and AX88179 (USB3) 10/100/1000
Ethernet NICs.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-26 12:52:06 +01:00
Michael Brown 8dd39b9572 [efi] Work around broken UEFI keyboard drivers
Some UEFI keyboard drivers are blissfully unaware of the existence of
either Ctrl key, and will report "Ctrl-<key>" as just "<key>".  This
breaks substantial portions of the iPXE user interface.

Work around these broken UEFI drivers by allowing "ESC <key>" to be
used as a substitute for "Ctrl-<key>".

Tested-by: Dreamcat4 <dreamcat4@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-25 23:28:41 +01:00
Michael Brown f42b2585fe [http] Ignore unrecognised "Connection" header tokens
Some HTTP/2 servers send the header "Connection: upgrade, close".  This
currently causes iPXE to fail due to the unrecognised "upgrade" token.

Fix by ignoring any unrecognised tokens in the "Connection" header.

Reported-by: Ján ONDREJ (SAL) <ondrejj@salstar.sk>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-25 15:35:43 +01:00
Michael Brown 80dd6cbcc4 [lotest] Add option to use broadcast packets for loopback testing
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-23 14:17:47 +01:00
Michael Brown 231adda40f [netdevice] Fix failure path in register_netdev()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-23 14:17:47 +01:00
Michael Brown 56c0147deb [settings] Extend numerical setting tags to "unsigned long"
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-20 16:51:56 +01:00
Michael Brown 6d2bdc4ea3 [pci] Add support for PCI Enhanced Allocation
Some embedded devices have immovable BARs, which are described via a
PCI Enhanced Allocation capability.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-20 16:51:56 +01:00
Michael Brown 276d7c31c5 [undi] Work around broken HP EliteBook 745 G3 PXE ROM
Reported-by: Arturino Mazzei <mazzeia@hotmail.com>
Tested-by: Arturino Mazzei <mazzeia@hotmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-13 13:22:06 +01:00
Christian Hesse 858f56e68b [ath9k] Fix buffer overrun for ar9287
This backport is from linux kernel upstream commit 83d6f1f ("ath9k:
fix buffer overrun for ar9287").

Signed-off-by: Christian Hesse <mail@eworm.de>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-12 14:55:13 +01:00
Michael Brown 601706688b [arm] Use CNTVCT_EL0 as profiling timestamp
The raw cycle counter at PMCCNTR_EL0 works in qemu but seems to always
read as zero on physical hardware (tested on Juno r1 and Cavium
ThunderX), even after ensuring that PMCR_EL0.E and PMCNTENSET_EL0.C
are both enabled.

Use CNTVCT_EL0 instead; this seems to count at a lower resolution
(tens of CPU cycles), but is usable for profiling.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-12 11:16:41 +01:00
Michael Brown 6164741f81 [efi] Guard against GetStatus() failing to return a NULL TX buffer
The UEFI specification requires the EFI_SIMPLE_NETWORK_PROTOCOL
GetStatus() method to set TxBuf to NULL if there are no transmit
buffers to recycle.

Some implementations (observed with Lan9118Dxe in EDK2) fill in TxBuf
only when there is a transmit buffer to recycle, which leads to large
numbers of "spurious TX completion" errors.

Work around this problem by initialising TxBuf to NULL before calling
the GetStatus() method.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-11 23:02:10 +01:00
Michael Brown 47931a4de5 [arm] Add optimised TCP/IP checksumming for 64-bit ARM
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-11 08:16:36 +01:00
Michael Brown 95716ece91 [arm] Add optimised string functions for 64-bit ARM
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-11 08:15:52 +01:00
Michael Brown a966570dce [libc] Avoid implicit assumptions about potentially-optimised memcpy()
Do not assume that an architecture-specific optimised memcpy() will
have the same properties as generic_memcpy() in terms of handling
overlapping regions.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-09 16:23:38 +01:00
Michael Brown 45cd68c0fb [efi] Allow for building with older versions of elf.h system header
Reported-by: Ahmad Mahagna <ahmhad@mellanox.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-09 16:18:10 +01:00
Michael Brown 17c6f322ee [arm] Add support for 64-bit ARM (Aarch64)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-08 00:20:20 +01:00
Michael Brown edea3a434c [arm] Split out 32-bit-specific code to arch/arm32
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-08 00:18:35 +01:00
Michael Brown 2a187f480e [arm] Avoid instruction references to symbols defined via ".equ"
When building for 64-bit ARM, some symbol references may be resolved
via an "adrp" instruction (to obtain the start of the 4kB page
containing the symbol) and a separate 12-bit offset.  For example
(taken from the GNU assembler documentation):

  adrp x0, foo
  ldr  x0, [x0, #:lo12:foo]

We occasionally refer to symbols defined via mechanisms that are not
directly visible to gcc.  For example:

  extern char some_magic_symbol[];
  __asm__ ( ".equ some_magic_symbol, some_magic_expression" );

The subsequent use of the ":lo12:" prefix on such magically-defined
symbols triggers an assertion failure in the assembler.

This problem seems to affect only "private_key_len" in the current
codebase.  Fix by storing this value as static data; this avoids the
need to provide the value as a literal within the instruction stream,
and so avoids the problematic use of the ":lo12:" prefix.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-08 00:08:48 +01:00
Michael Brown 1a16f67a28 [arm] Add support for 32-bit ARM
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-06 12:08:44 +01:00
Michael Brown 49a5bcfba6 [bitops] Fix typo in test case
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-05 23:42:57 +01:00
Michael Brown 67f539fa80 [libgcc] Provide __divmoddi4()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-05 23:42:57 +01:00
Michael Brown a5885fbc19 [legacy] Fix building with GCC 6
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-04 16:01:33 +01:00
Michael Brown 63037bdce4 [ath] Fix building with GCC 6
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-04 16:01:33 +01:00
Michael Brown 08230599ef [golan] Fix building with GCC 6
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-04 16:01:32 +01:00
Michael Brown 76ec2a0540 [skge] Fix building with GCC 6
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-04 16:01:32 +01:00
Michael Brown 65b32a0b70 [sis190] Fix building with GCC 6
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-04 16:01:32 +01:00
Vinson Lee e2f14c2f8c [mucurses] Fix GCC 6 nonnull-compare errors
Remove null checks for arguments declared as nonnull.

Signed-off-by: Vinson Lee <vlee@freedesktop.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-04 16:01:32 +01:00
Michael Brown 57d0ea7c46 [efi] Generalise EFI entropy generation to non-x86 CPUs
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-04 14:34:24 +01:00
Michael Brown 757ab98381 [efi] Use a timer event to generate the currticks() timer
We currently use the EFI_CPU_ARCH_PROTOCOL's GetTimerValue() method to
generate the currticks() timer, calibrated against a 1ms delay from
the boot services Stall() method.

This does not work on ARM platforms, where GetTimerValue() is an empty
stub which just returns EFI_UNSUPPORTED.

Fix by instead creating a periodic timer event, and using this event
to increment a current tick counter.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-04 13:38:33 +01:00
Michael Brown 1e066431a4 [tcpip] Do not fall back to using unoptimised TCP/IP checksumming
Require architecture-specific code to make a deliberate choice to use
the unoptimised generic_tcpip_continue_chksum() function, if there is
no optimised version available.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-04 13:38:25 +01:00
Michael Brown 9f91df422b [build] Remove unnecessary dependency on zlib
The dependency on zlib seems to have been introduced in commit 3dd7ce1
("[efi] Allow building with non-system libbfd") as an indirect
requirement of either libbfd or libiberty when building on Mac OS X.
Since we no longer use either of these libraries, remove the
unnecessary link against zlib.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-02 23:09:49 +01:00
Michael Brown efd5cf9aad [efi] Eliminate use of libbfd
Parse the intermediate ELF file directly instead of using libbfd, in
order to allow for cross-compiled ELF objects.

As a side bonus, this eliminates libbfd as a build requirement.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-02 22:35:14 +01:00
Michael Brown 71560d1854 [librm] Preserve FPU, MMX and SSE state across calls to virt_call()
The IBM Tivoli Provisioning Manager for OS Deployment (also known as
TPMfOSD, Rembo-ia32, or Rembo Auto-Deploy) has a serious bug in some
older versions (observed with v5.1.1.0, apparently fixed by v7.1.1.0)
which can lead to arbitrary data corruption.

As mentioned in commit 87723a0 ("[libflat] Test A20 gate without
switching to flat real mode"), Tivoli's NBP sets up a VMM and makes
calls to the PXE stack in VM86 mode.  This appears to be some kind of
attempt to run PXE API calls inside a sandbox.  The VMM is fairly
sophisticated: for example, it handles our attempts to switch into
protected mode and patches our GDT so that our protected-mode code
runs in ring 1 instead of ring 0.  However, it neglects to apply any
memory protections.  In particular, it does not enable paging and
leaves us with 4GB segment limits.  We can therefore trivially break
out of the sandbox by simply overwriting the GDT (or by modifying any
of Tivoli's VMM code or data structures).

When we attempt to execute privileged instructions (such as "lidt"),
the CPU raises an exception and control is passed to the Tivoli VMM.
This may result in a call to Tivoli's memcpy() function.

Tivoli's memcpy() function includes optimisations which use the SSE
registers %xmm0-%xmm3 to speed up aligned memory copies.

Unfortunately, the Tivoli VMM's exception handler does not save or
restore %xmm0-%xmm3.  The net effect of this bug in the Tivoli VMM is
that any privileged instruction (such as "lidt") issued by iPXE may
result in unexpected corruption of the %xmm0-%xmm3 registers.

Even more unfortunately, this problem affects the code path taken in
response to a hardware interrupt from the NIC, since that code path
will call PXENV_UNDI_ISR.  The net effect therefore becomes that any
NIC hardware interrupt (e.g. due to a received packet) may result in
unexpected corruption of the %xmm0-%xmm3 registers.

If a packet arrives while Tivoli is in the middle of using its
memcpy() function, then the unexpected corruption of the %xmm0-%xmm3
registers will result in unexpected corruption in the destination
buffer.  The net effect therefore becomes that any received packet may
result in a 16-byte block of corruption somewhere in any data that
Tivoli copied using its memcpy() function.

We can work around this bug in the Tivoli VMM by saving and restoring
the %xmm0-%xmm3 registers across calls to virt_call().  To work around
the problem, we need to save registers before attempting to execute
any privileged instructions, and ensure that we attempt no further
privileged instructions after restoring the registers.

This is less simple than it may sound.  We can use the "movups"
instruction to save and restore individual registers, but this will
itself generate an undefined opcode exception if SSE is not currently
enabled according to the flags in %cr0 and %cr4.  We can't access %cr0
or %cr4 before attempting the "movups" instruction, because access a
control register is itself a privileged instruction (which may
therefore trigger corruption of the registers that we're trying to
save).

The best solution seems to be to use the "fxsave" and "fxrstor"
instructions.  If SSE is not enabled, then these instructions may fail
to save and restore the SSE register contents, but will not generate
an undefined opcode exception.  (If SSE is not enabled, then we don't
really care about preserving the SSE register contents anyway.)

The use of "fxsave" and "fxrstor" introduces an implicit assumption
that the CPU supports SSE instructions (even though we make no
assumption about whether or not SSE is currently enabled).  SSE was
introduced in 1999 with the Pentium III (and added by AMD in 2001),
and is an architectural requirement for x86_64.  Experimentation with
current versions of gcc suggest that it may generate SSE instructions
even when using "-m32", unless an explicit "-march=i386" or "-mno-sse"
is used to inhibit this.  It therefore seems reasonable to assume that
SSE will be supported on any hardware that might realistically be used
with new iPXE builds.

As a side benefit of this change, the MMX register %mm0 will now be
preserved across virt_call() even in an i386 build of iPXE using a
driver that requires readq()/writeq(), and the SSE registers
%xmm0-%xmm5 will now be preserved across virt_call() even in an x86_64
build of iPXE using the Hyper-V netvsc driver.

Experimentation suggests that this change adds around 10% to the
number of cycles required for a do-nothing virt_call(), most of which
are due to the extra bytes copied using "rep movsb".  Since the number
of bytes copied is a compile-time constant local to librm.S, we could
potentially reduce this impact by ensuring that we always copy a whole
number of dwords and so can use "rep movsl" instead of "rep movsb".

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-02 14:02:31 +01:00
Michael Brown fe62f3c831 [tg3] Fix _tg3_flag() for 64-bit builds
Commit 86f96a4 ("[tg3] Remove x86-specific inline assembly")
introduced a regression in _tg3_flag() in 64-bit builds, since any
flags in the upper 32 bits of a 64-bit unsigned long would be
discarded when truncating to a 32-bit int.

Debugged-by: Shane Thompson <shane.thompson@aeontech.com.au>
Tested-by: Shane Thompson <shane.thompson@aeontech.com.au>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-05-02 13:25:56 +01:00
Michael Brown 2d42d3cff6 [librm] Reduce real-mode stack consumption in virt_call()
Some PXE NBPs are known to make PXE API calls with very little space
available on the real-mode stack.  For example, the Rembo-ia32 NBP
from some versions of IBM's Tivoli Provisioning Manager for Operating
System Deployment (TPMfOSD) will issue calls with the real-mode stack
placed at 0000:03d2; this is at the end of the interrupt vector table
and leaves only 498 bytes of stack space available before overwriting
the hardware IRQ vectors.  This limits the amount of state that we can
preserve before transitioning to protected mode.

Work around these challenging conditions by preserving everything
other than the initial register dump in a temporary static buffer
within our real-mode data segment, and copying the contents of this
buffer to the protected-mode stack.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-04-29 11:48:39 +01:00
Michael Brown b696a5063e [image] Skip misleading "format not recognised" error message
Return success (rather than failure) after an image format has been
correctly identified.

This has no practical effect, since the return value from
image_probe() is deliberately never used, but avoids a somewhat
surprising and misleading "format not recognised" error message when
debugging is enabled.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-04-28 12:12:50 +01:00
Michael Brown 55e409b14f [libgcc] Provide symbol to handle gcc's implicit calls to memset()
On some architectures (such as ARM), gcc will insert implicit calls to
memset().  Handle these using the same mechanism as for the implicit
calls to memcpy() used by x86.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-04-20 16:46:24 +01:00
Michael Brown 91aa188fbb [libc] Allow CPU architectures to use unoptimised string functions
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-04-19 16:30:49 +01:00
Michael Brown 40a8a5294c [ethernet] Make LACP support configurable at build time
Add a build configuration option NET_PROTO_LACP to control whether or
not LACP support is included for Ethernet devices.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-04-18 10:08:46 +01:00
Ladi Prosek 988243c93f [virtio] Add virtio-net 1.0 support
This commit makes virtio-net support devices with VEN 0x1af4 and DEV
0x1041, which is how non-transitional (modern-only) virtio-net devices
are exposed on the PCI bus.

Transitional devices supporting both the old 0.9.5 and new 1.0 version
of the virtio spec are driven using the new protocol.  Legacy devices
are driven using the old protocol, same as before this commit.

Signed-off-by: Ladi Prosek <lprosek@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-04-15 17:43:07 +01:00
Ladi Prosek 8a055a2a70 [virtio] Add virtio 1.0 PCI support
This commit adds support for driving virtio 1.0 PCI devices.  In
addition to various helpers, a number of vpm_ functions are introduced
to be used instead of their legacy vp_ counterparts when accessing
virtio 1.0 (aka modern) devices.

Signed-off-by: Ladi Prosek <lprosek@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-04-15 17:41:26 +01:00
Ladi Prosek 7b499f849e [virtio] Add virtio 1.0 constants and data structures
Virtio 1.0 introduces new constants and data structures, common to all
devices as well as specific to virtio-net.  This commit adds a subset
of these to be able to drive the virtio-net 1.0 network device.

Signed-off-by: Ladi Prosek <lprosek@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-04-15 17:28:06 +01:00
Ladi Prosek 2379494918 [pci] Add pci_find_next_capability()
PCI devices may support more capabilities of the same type (for
example PCI_CAP_ID_VNDR) and there was no way to discover all of them.
This commit adds a new API pci_find_next_capability which provides
this functionality.  It would typically be used like so:

  for (pos = pci_find_capability(pci, PCI_CAP_ID_VNDR);
       pos > 0;
       pos = pci_find_next_capability(pci, pos, PCI_CAP_ID_VNDR)) {
    ...
  }

Signed-off-by: Ladi Prosek <lprosek@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-04-15 17:27:35 +01:00
Michael Brown 5e5450c2d0 [comboot] Support COMBOOT in 64-bit builds
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-04-15 15:31:36 +01:00
Suresh Sundriyal 4afb758423 [pool] Fix check for reopenable pooled connections
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-04-12 14:18:17 +01:00
Wissam Shoukair 0eea8b5c3b [golan] Add missing iounmap()
Signed-off-by: Wissam Shoukair <wissams@mellanox.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-04-12 13:40:50 +01:00
Wissam Shoukair ffd959a1d6 [mlx_icmd] Fix compilation error in GCC versions newer than 4.6.4
Signed-off-by: Wissam Shoukair <wissams@mellanox.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-04-12 13:38:10 +01:00
Michael Brown 5238c85b62 [efi] Work around broken EFI HII specification
The EFI_HII_CONFIG_ACCESS_PROTOCOL's ExtractConfig() method is passed
a request string which includes the parameters being queried plus an
apparently meaningless blob of information (the ConfigHdr), and is
expected to include this same meaningless blob of information in the
results string.

Neither the specification nor the existing EDK2 code (including the
nominal reference implementation in the DriverSampleDxe driver)
provide any reason for the existence of this meaningless blob of
information.  It appears to be consumed in its entirety by the
EFI_HII_CONFIG_ROUTING_PROTOCOL, and to contain zero bits of
information by the time it reaches an EFI_HII_CONFIG_ACCESS_PROTOCOL
instance.  It would potentially allow for multiple configuration data
sets to be handled by a single EFI_HII_CONFIG_ACCESS_PROTOCOL
instance, in a style alien to the rest of the UEFI specification
(which implicitly assumes that the instance pointer is always
sufficient to uniquely identify the instance).

iPXE currently handles this by simply copying the ConfigHdr from the
request string to the results string, and otherwise ignoring it.  This
approach is also used by some code in EDK2, such as OVMF's PlatformDxe
driver.

As of EDK2 commit 8a45f80 ("MdeModulePkg: Make HII configuration
settings available to OS runtime"), this causes an assertion failure
inside EDK2.  The failure arises when iPXE is handled a NULL request
string, and responds (as per the specification) with a results string
including all settings.  Since there is no meaningless blob to copy
from the request string, there is no corresponding meaningless blob in
the results string.  This now causes an assertion failure in
HiiDatabaseDxe's HiiConfigRoutingExportConfig().

The same failure does not affect the OVMF PlatformDxe driver, which
simply passes the request string to the HII BlockToConfig() utility
function.  The BlockToConfig() function returns EFI_INVALID_PARAMETER
when passed a null request string, and PlatformDxe propagates this
error directly to the caller.

Fix by matching the behaviour of OVMF's PlatformDxe driver: explicitly
return EFI_INVALID_PARAMETER if the request string is NULL or empty.
This violates the specification (insofar as it is feasible to
determine what the specification actually requires), but causes
correct behaviour with the EDK2 codebase.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-04-12 12:24:14 +01:00
Michael Brown cc8824ad4e [libc] Print "<NULL>" for wide-character NULL strings
The existing code intends to print NULL strings as "<NULL>" (for the
sake of debug messages), but the logic is incorrect when handling
wide-character strings.  Fix the logic and add applicable unit tests.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-04-12 11:53:06 +01:00
Michael Brown 320488d0f9 [test] Update snprintf_ok() to use okx()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-04-12 11:45:58 +01:00
Michael Brown 597521ef53 [qib7322] Validate payload length
There is no way for the hardware to give us an invalid length in the
LRH, since it must have parsed this length field in order to perform
header splitting.  However, this is difficult to prove conclusively.

Add an unnecessary length check to explicitly reject any packets
larger than the posted receive I/O buffer.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-03-30 07:31:51 +01:00
Michael Brown c9af896314 [linda] Validate payload length
There is no way for the hardware to give us an invalid length in the
LRH, since it must have parsed this length field in order to perform
header splitting.  However, this is difficult to prove conclusively.

Add an unnecessary length check to explicitly reject any packets
larger than the posted receive I/O buffer.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2016-03-30 07:27:09 +01:00