Commit Graph

340 Commits

Author SHA1 Message Date
Stephen J. Kiernan
5c6b397ff1 The getsecs() function is implemented in platform- and bootfw-specific
files and, in a number of these places, there were problems with how they
were declared.

Some used int return instead of time_t. On some architectures the bit
width of time_t did not naturally fit into an integer and could lead to
some unexpected behavior. (For example, 32-bit ARM builds uses a 64-bit
time_t.)

Make sure the function prototypes always specify void for the argument
list when they do not have any arguemnts, otherwise some compilers can
complain about the prototype.

Reported by:	Kevin Zheng
Reviewed by:	sjg
Approved by:	sjg (mentor)
Obtained from:	Juniper Networks, Inc.
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D7463
2016-09-22 06:24:40 +00:00
Konstantin Belousov
67330db0bb Simple post-mortem reporter for amd64 loader.efi.
There is no way to see anything about the faults occuring in
loader.efi. Some intel BIOSes do output a line into serial port at
115200/8/1 regardless of the current port settings with the EFI error
number, but this is too little, and not always available, esp. if the
user does not know where to look.

The patch adds a simple facility to grab exceptions and at least dump
generic registers and some exception details.  Due to the relative
complexity of correctly taking over the BIOS IDT setup, only install
the facility on user request.

Two new commands, 'grab_faults' and 'ungrab_faults' are provided,
first one takes over, second undoes the first. It is supposed that
user would execute 'grab' by the developer direction of collecting the
debugging data.  The 'fault' command generates exception to test the
setup.

Fault handlers use dedicated stack to improve chances of catching
stack/TSS exceptions.  Due to this, BIOS IDT is duplicated into a
private copy, and debugger needs to find a free GDT slot for TSS. This
is done in somewhat complicated efi_redirect_exceptions().

Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
Differential revision:	https://reviews.freebsd.org/D7935
2016-09-21 10:22:46 +00:00
Ed Maste
ac7715e39e revert unintended change from r305994 2016-09-19 18:45:57 +00:00
Ed Maste
df4336ddfa Catch up to sys/capability.h rename to sys/capsicum.h in r263232
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
2016-09-19 18:44:43 +00:00
Konstantin Belousov
2fb709ef75 Add comment for the closing guard.
Requested by:	tsoome
MFC after:	1 week
2016-09-18 18:40:27 +00:00
Konstantin Belousov
7d144ba6dc Utilize pmap.h names for constants and types used to construct EFI
trampoline page table.  Also do some style cleanup.

Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D7934
2016-09-18 17:41:16 +00:00
Konstantin Belousov
35a22bcbf7 Add double-inclusion protection.
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2016-09-18 17:35:24 +00:00
Ed Maste
487b46173d Use arch-specific .text padding fill value in EFI loaders
The fill pattern was previously an ia64 instruction sequence. Presumably
ia64's linker script was copied as a starting point.

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2016-09-16 01:38:22 +00:00
Will Andrews
d945328992 loader.efi: Bump the staging size to 64M.
This is required on my system, which loads nvidia, vmm, and zfs, and 48M is
no longer enough for that.  nvidia-driver's recent update increased its size
by several megabytes.

Reviewed by:	jhb
MFC after:	1 week
2016-09-06 17:58:58 +00:00
Ed Maste
5462b0052b Set UEFI boot loader PE/COFF timestamps to known value for reproducible builds
Reviewed by:	rpokala
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D7633
2016-08-31 21:35:38 +00:00
Baptiste Daroussin
6a695123b0 Netboot: allow both tftpfs and nfs in both pxeboot and loader.efi
Add a new 'netproto' variable which can be set for now to
NET_TFTP or NET_NFS (default to NET_NONE)

From the dhcp options if one sets the root-path option to:
"ip:path", the loader will consider it is booting over NFS
(meaning same behaviour as the default current behaviour)

if the dhcp option "tftp server address" is set (option 150)
the loader will consider it is booting over tftpfs, it will then
consider the root-path options with 2 possible case
1. "path" then the IP of the tftp server will be the one passed by
the option 150, and the files will be retrieved under "path" on the tftp
server
2. "ip:path" then the IP of the tftp server will be the one passed in
the option "overwritting the IP from the option 150.

We could not "abuse" the rootpath option in the form or tftp://ip:path because
this is already used for other purpose by iPXE preventing any chainload from
iPXE to the FreeBSD loader.

Given at each open(), the loader loops over all available filesystems and keep
the "best" error, we needed to prevent tftpfs to fallback on nfs and vice versa.
the tftpfs and nfs implementation in libstand now return EINVAL early if
'netproto' for that purpose.

Reviewed by:	tsoome
Relnotes:	yes
Sponsored by:	Gandi.net
Differential Revision:	https://reviews.freebsd.org/D7628
2016-08-31 13:16:40 +00:00
Jared McNeill
704fa4fd26 When the EFI implementation (like U-Boot) does not support WaitForKey, we
can emulate efi_cons_poll(0 with a flag and caching the last key read with
ReadKeyStroke. This fixes the loader.efi countdown timer on Pine64 (and
other U-Boot + EFI using platforms).

Reviewed by:		imp, manu
Differential Revision:	https://reviews.freebsd.org/D7670
2016-08-29 20:01:53 +00:00
Andrew Turner
ef63b26a5f Don't set *dev in the zfs root case, it may be NULL and will correctly be
set later in the function. This fixes a potential NULL pointer dereference
found on arm64.

Obtained from:	ABT Systems Ltd
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2016-08-25 12:42:41 +00:00
Baptiste Daroussin
add3a4c20d EFI loader: only open/close on the net device with tftpfs
It prevents issuing a dhcp request before each file open
As a consequence netbooting over tftpfs is significantly faster

Sponsored by:	Gandi.net
2016-08-23 13:53:38 +00:00
Baptiste Daroussin
fb22f749b3 Add tftpfs support for the EFI loader
Allow netbooting on efi without having to setup any NFS server by rebuilding the
loader with LOADER_TFTP_SUPPORT like for the i386 pxeloader

Sponsored by:	Gandi.net
2016-08-23 13:35:48 +00:00
Toomas Soome
5b6123e31d loader is filling fixed length command_errbuf with sprintf() and is trusting
strings provided by user/config files. This update is replacing sprintf with
snprintf for cases the command_errbuf is built from dynamic content.

PR:		211958
Reported by:	ecturt@gmail.com
Reviewed by:	imp, allanjude
Approved by:	imp (mentor), allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D7563
2016-08-20 16:23:19 +00:00
Toomas Soome
2c55d0903d Add SHA512, skein, large blocks support for loader zfs.
Updated sha512 from illumos.
Using skein from freebsd crypto tree.
Since loader itself is using 64MB memory for heap, updated zfsboot to
use same, and this also allows to support zfs large blocks.

Note, adding additional features does increate zfsboot code, therefore
this update does increase zfsboot code to 128k, also I have ported gptldr.S
update to zfsldr.S to support 64k+ code.

With this update, boot1.efi has almost reached the current limit of the size
set for it, so one of the future patches for boot1.efi will need to
increase the limit.

Currently known missing zfs features in boot loader are edonr and gzip support.

Reviewed by:	delphij, imp
Approved by:	imp (mentor)
Obtained from:	sha256.c update and skein_zfs.c stub from illumos.
Differential Revision:	https://reviews.freebsd.org/D7418
2016-08-18 00:37:07 +00:00
Toomas Soome
88fb7b56ea boot1.efi Free() should check for NULL to provide consistent behavior
with libstand Free().

Reviewed by:	imp
Approved by:	imp (mentor)
Differential Revision:	https://reviews.freebsd.org/D7497
2016-08-17 21:29:57 +00:00
Emmanuel Vadot
393fb50cbc Correctly print and cast u_int64_t and off_t.
Reported by:	ed, imp
MFC after:	1 week
2016-08-17 08:29:30 +00:00
Emmanuel Vadot
858a3f496f Only use WaitForKeys event if it exists, this is not the case in u-boot efi implementation.
Reviewed by:	jhb, emaste
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D6781
2016-08-16 14:33:25 +00:00
Emmanuel Vadot
5f306327fe Use %ju modifier for u_int64_t and %jd modifier for off_t.
off_t is long long on arm32 and long on amd64

MFC after:	1 week
2016-08-16 14:23:35 +00:00
John Baldwin
0e4c843ab4 Add defines needed to export SMBIOS serial numbers
Some defines needed for exporting serial numbers from the SMBIOS were
missed during integration of SMBIOS support in the EFI boot loader (r281138).
This is needed for getting the hostid set from the system hardware UUID.

PR:		206031
Submitted by:	Thomas Eberhardt <sneakywumpus@gmail.com>
MFC after:	1 week
2016-08-12 19:47:20 +00:00
Mark Johnston
15f6139cc2 Fix a few cosmetic issues in boot1.efi.
- Use ANSI function signatures.
- Remove unneeded checks for a NULL boot module.
- Use nitems().

MFC after:	1 week
Sponsored by:	EMC / Isilon Storage Division
2016-08-03 17:17:01 +00:00
Emmanuel Vadot
ddda1a9c2f Do not use TERM_EMU on arm and arm64 as it doesn't behave well with serial console.
Reviewed by:	andrew, emaste
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D6783
2016-07-19 19:00:22 +00:00
Ed Maste
0f3454e465 boot1.efi: fix assignment / comparison expression
PR:		210706
Submitted by:	David Binderman <dcb314@hotmail.com>
Approved by:	re (kib)
MFC after:	1 week
2016-07-04 16:50:21 +00:00
Emmanuel Vadot
e40bf91460 Print a message when disks are found but no logical partition are
reported by EFI implementation. This address comment on r301714.

Approved by:	re (gjb), andrew (mentor)
Differential Revision:	https://reviews.freebsd.org/D6787
2016-06-17 17:09:22 +00:00
Emmanuel Vadot
e644b7c5a5 Print a message when the efi disk isn't a logical partition.
Approved by:	andrew (mentor)
Differential Revision:	https://reviews.freebsd.org/D6782
2016-06-09 02:02:50 +00:00
Andrew Turner
103dce1405 Also set -fshort-wchar on arm64, this fixes parsing strings from UEFI,
e.g. on the command line.

Sponsored by:	ABT Systems Ltd
2016-06-08 23:23:16 +00:00
Andrew Turner
aaad73f447 Print the newline character along with the carriage return when TERM_EMU is
disabled. Without this we print all lines over top of each other.

Sponsored by:	ABT Systems Ltd
2016-06-08 23:13:20 +00:00
Andrew Turner
9706d6ad89 Allow libefi to be built with TERM_EMU undefined. There were a few places
where we assumed TERM_EMU was defined but didn't check. Fix these by also
including them under the ifdefs.

As HO is called from loader we need a null implementation so loader.efi
doesn't need to know which version of libefi it is building against.

Sponsored by:	ABT Systems Ltd
2016-06-08 22:36:55 +00:00
Andrew Turner
d15667174d Use the UEFI event timer to update the time on arm and arm64. The current
code uses the GetTime function from the Runtime Service, however this has
been shown to not return a useable time on many arm64 UEFI implementations.

Reviewed by:	jhb, smh
Sponsored by:	ABT Systems Ltd
Differential Revision:	https://reviews.freebsd.org/D6709
2016-06-04 08:47:45 +00:00
Doug Ambrisko
9c8f0619db If the I/O offset and length is multiple of the media size then
directly pass the request otherwise use a buffer that is a
multiple of the media size.  This speeds up I/O quite a bit
when using large transfer sizes on 4Kn disks etc.

MFC after:	1 week
2016-05-27 19:23:15 +00:00
John Baldwin
4e865d9eb0 Fix unit number of EFI net interfaces and ignore psuedo network interfaces.
In r277943, the efinet_match() routine was changed to use an off by one
when matching network interfaces.  The effect was that using "net1"
actually used the device attached to "net0".

Digging into the hardware that needed this workaround more, I found that
UEFI was creating two simple network protocol devices for each physical
NIC.  The first device was a "raw" Ethernet device and the second device
was a "IP" device that used the IP protocol on top of the underlying
"raw" device.  The PXE code in the firmware used the "IP" device to pull
across the loader.efi, so currdev was set to "net1" when booting from the
physical interface "net0".  (The loaded image's device handle referenced
the "IP" device that "net1" claimed.)

However, the IP device isn't suitable for doing raw packet I/O (and the
current code to open devices exclusively actually turns the "IP" devices
off on these systems).

To fix, change the efinet driver to only attach to "raw" devices.  This
is determined by fetching the DEVICE_PATH for each handle which supports
the simple network protocol and examining the last node in the path.  If
the last node in the path is a MAC address, the device is assumed to be
a "raw" device and is added as a 'netX' device.  If the last node is not
a MAC address, the device is ignored.

However, this causes a new problem as the device handle associated with
the loaded image no longer matches any of the handles enumerated by
efinet for systems that load the image via the "IP" device.  To handle
this case, expand the logic that resolves currdev from the loaded image
in main().  First, the existing logic of looking for a handle that
matches the loaded image's handle is tried.  If that fails, the device
path of the handle that loaded the loaded image is fetched via
efi_lookup_image_devpath().  This device path is then walked from the
end up to the beginning using efi_handle_lookup() to fetch the handle
associated with a path.  If the handle is found and is a known handle,
then that is used as currdev.  The effect for machines that load the
image via the "IP" device is that the first lookup fails (the handle
for the "IP" device isn't claimed by efinet), but walking up the
image's device path finds the handle of the raw MAC device which is used
as currdev.

With these fixes in place, the hack to subtract 1 from the unit can now
be removed, so that setting currdev to 'net0' actually uses 'net0'.

PR:		202097
Tested by:	ambrisko
Sponsored by:	Cisco Systems
2016-05-26 23:32:28 +00:00
John Baldwin
8f7ada2196 Use a unique error message if we fail to find the simple network protocol.
While here, fix the various net driver callbacks to return early instead
of crashing if this fails.  (The 'init' callback from the netif interface
doesn't return an error if the protocol lookup fails.)

Sponsored by:	Cisco Systems
2016-05-26 23:08:57 +00:00
John Baldwin
72bc6425a9 Apply the printf %S band-aid for efinet.c to fix the arm64 build. 2016-05-26 23:07:20 +00:00
John Baldwin
b4f9242404 Remove second copy of the -Wno-format band-aid for printf %S. 2016-05-26 23:06:36 +00:00
John Baldwin
e06f8144fb Use routines from the recently added devpath.c.
These efipart layer did several devpath related operations inline.  This
just switches it over to using shared code for working with device paths.

Sponsored by:	Cisco Systems
2016-05-26 22:13:40 +00:00
John Baldwin
79ad8397ea Output the device path description for EFI network devices.
Lookup the DEVICE_PATH for each EFI network device handle and output the
string description using printf with '%S'.  To honor the pager, the newline
at the end of each line is still output with pager_output().

Sponsored by:	Cisco Systems
2016-05-26 21:48:39 +00:00
John Baldwin
3e5a19be71 Add some routines for working with EFI DEVICE_PATH objects.
- efi_lookup_devpath() uses the DEVICE_PATH_PROTOCOL to obtain the
  DEVICE_PATH for a given EFI handle.
- efi_lookup_image_devpath() uses the LOADED_IMAGE_DEVICE_PATH_PROTOCOL
  to lookup the device path of the device used to load a loaded image.
- efi_devpath_name() uses the DEVICE_PATH_TO_TEXT_PROTOCOL to generate
  a string description of a device path.  The returned string is a CHAR16
  string that can be printed via the recently added '%S' format in
  libstand's printf().  Note that the returned string is returned in
  allocated storage that should be freed by calling
  efi_free_devpath_name().
- efi_devpath_last_node() walks a DEVICE_PATH returning a pointer to the
  final node in the path (not counting the terminating node).  That is,
  it returns a pointer to the last meaninful node in a DEVICE_PATH.
- efi_devpath_trim() generates a new DEVICE_PATH from an existing
  DEVICE_PATH.  The new DEVICE_PATH does not include the last
  non-terminating node in the original path.  If the original DEVICE_PATH
  only contains the terminating node, this function returns NULL.
  The caller is responsible for freeing the returned DEVICE_PATH via
  free().
- efi_devpath_handle() attempts to find a handle that corresponds to a
  given device path.  However, if nodes at the end of the device path do
  not have valid handles associated with them, this function will return
  a handle that matches a node earlier in the device path.  In particular,
  this function returns a handle for the node closest to the end of the
  device path which has a valid handle.

Sponsored by:	Cisco Systems
2016-05-26 21:43:22 +00:00
Conrad Meyer
241adf4455 efi loader: Match format string to EFI_ERROR_CODE()
Silence a format specifier warning.

Sponsored by:	EMC / Isilon Storage Division
2016-05-25 00:13:01 +00:00
Warner Losh
a00ef24037 Large improvements to efi-show (though some weird problems
linger). We now print only printable characters for the
values and we print ascii strings as strings.
2016-05-20 19:38:01 +00:00
Warner Losh
d52a88fe7c Implement efi-set and efi-unset 2016-05-20 19:37:54 +00:00
Warner Losh
8f190a8c0e Cleanup to use %S. 2016-05-20 19:37:46 +00:00
Warner Losh
da5d9ec2ac Fix logic error so UEFI variables are reported correctly
without error at the end.
2016-05-19 16:36:06 +00:00
Pedro F. Giffuni
416970ad85 Minor spelling fixes. 2016-05-18 15:18:18 +00:00
Warner Losh
9a0b26ec6f Fix several instances where the boot loader ignored pager_output
return value when it could return 1 (indicating we should stop).
Fix a few instances of pager_open() / pager_close() not being called.
Actually use these routines for the environment variable printing code
I just committed.
2016-05-18 05:59:05 +00:00
Warner Losh
4a619be4bb Fix build breakage on arm64 by papering over the problem. We implement
a slightly non-standard %S that's more useful in the UEFI environment,
so ignore printf errors. There's no good cast to use. We'll need to
revisit this in the future.
2016-05-18 05:58:58 +00:00
Warner Losh
53ff4bbc05 Implement UEFI set environment variable, as well as exporting the EFI
version. This is also scriptable, though additional scripting will be
needed.

Differential Review: https://reviews.freebsd.org/D4494
MFC After: 3 days
2016-05-17 21:25:20 +00:00
Warner Losh
d4d32e5899 It sure would be nice to use printf with wide strings. Implement %S to
do that. The C_WIDEOUT flag indicates that the console supports
it. Mark the EFI console as supporting this.

MFC After: 3 days
2016-05-17 14:10:45 +00:00
Pedro F. Giffuni
98b6ade62d libefi: Tag an unreachable switch default.
Coverity reports an uninitialized "len" in case the switch defaults
without hitting any case. Respect the original intent and quell the
false positive with the relatively new __unreachable() builtin.

CID:	1347796
2016-05-16 20:00:09 +00:00