Commit Graph

197 Commits

Author SHA1 Message Date
Toomas Soome
f6eef0f9a2 libefi: efipart_floppy() will should not pass acpi pointer if the HID test fails
The current efipart_floppy() implementation is leaking the acpi pointer.
2017-09-25 19:49:56 +00:00
Toomas Soome
c57460d994 libefi: define EISA PNP constants
Define EISA PNP constants and use them, also fix ID for 0x701
2017-09-22 07:44:36 +00:00
Toomas Soome
f43a98e6c2 libefi: efipart_hdinfo_add_filepath should check strtol result
Use errno for error checking.
2017-09-22 07:40:05 +00:00
Toomas Soome
abf054b4c6 libefi: efipart.c cstyle fix for efipart_print_common()
The else statement should have { }
2017-09-22 07:37:42 +00:00
Toomas Soome
5af584ffc1 libefi: efipart_strategy() should return ENXIO when there is no media
We should return ENXIO to indicate the situation with device present,
but no media.
2017-09-22 07:34:08 +00:00
Toomas Soome
cbc1b3de8f libefi: efi_devpath_match local len should be unsigned
DevicePathNodeLength() will always return unsigned value.
2017-09-22 02:53:01 +00:00
Toomas Soome
cfe103a2ac libefi: efipart.c should use calloc()
The device specific *_add functions are using malloc() + memset,
should use calloc instead.
2017-09-21 23:22:18 +00:00
Toomas Soome
59fcc285f4 libefi: efi_devpath_match() should return bool
The current implementation of efi_devpath_match() is returning values 0 or 1,
so it should be updated to return bool.
2017-09-21 23:14:07 +00:00
Toomas Soome
5370de88cc libefi: devicename.c cleanups
Remove duplicated free()+return statements, default unit to 0
and improve strtol error processing.
2017-09-21 15:30:20 +00:00
Toomas Soome
0a0c72ff93 libefi: efipart_realstrategy rsize pointer may be NULL
Need to check rsize before dereferencing it.
2017-09-13 14:27:13 +00:00
Toomas Soome
c7847a364a libefi: efipart_open should check the status from disk_open
In case of error from disk_open(), we should clean up properly.

Reviewed by:	allanjude, imp
Differential Revision:	https://reviews.freebsd.org/D12340
2017-09-12 14:18:45 +00:00
Toomas Soome
44832ad99d loader.efi: chain loader should provide proper device handle
Since the efipart rewrite, the chain command was looking for device
handle using interface applicable only for net devices. Disk
partitions and zfs pools need their own approach to find the proper handle.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D12287
2017-09-10 13:53:42 +00:00
Warner Losh
84ed53b2c0 Be consistent and do return (1);
Noticed by: tsoome@
Sponsored by: Netflix
2017-09-07 15:46:44 +00:00
Warner Losh
1d21184075 ucs2len
Rename boot1's wcslen to ucs2len, which we can't use in userland
because wchar in userland is unsigned, not short. Move it into
efichar.c. Also spell '* 2' as '* sizeof(efi_char)' and add 1 for the
trailing NUL to transition the FreeBSD boot env vars to being NUL
terminated on the same line...

Sponsored by: Netflix
2017-09-07 07:30:05 +00:00
Warner Losh
2c4b0cefde Make efichar.c routines available to libefi.
Make efichar.c routines available to libefi as well as
libefivar. Define LIBEFI when building so we can conditionally include
stand.h vs the normal userland stuff.
2017-08-31 17:32:09 +00:00
Warner Losh
57d7e4f502 Link in libefi for boot1
Add libefi to the list of libraries we'll link in. Move EFI table
definitions back to libefi so we don't have drift between the two
efi_main routines.

Sponsored by: Netflix
2017-08-26 18:30:14 +00:00
Warner Losh
c40241db0f Move efi_main into efi/loader
Move the efi_main routine out of libefi into sys/boot/efi/loader.
Since boot1 has its own efi_main routine, this effectively prevents
boot1 from linking with libefi. By moving it out, we can share code
better (though though some refactoring with boot1's efi_main and
loader.efi's efi_main is definitely in order).

Sponsored by: Netflix
2017-08-26 18:29:24 +00:00
Toomas Soome
07672e9c19 libefi/time.c cstyle cleanup
libefi/time.c is mix of different styles, this update does cleanup.
Also fix 0 versus NULL, and zero the tv structure for case we get error
from UEFI firmware.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D11861
2017-08-05 05:20:03 +00:00
Warner Losh
9990efd2e2 Move EFI fmtdev functionality to libefi
This patch moves code necessary for the fmtdev functionality from
loader to libefi, allowing other applications to make use of it

Submitted by: Eric McCorkle
Differential Revision: https://reviews.freebsd.org/D11862
2017-08-04 16:33:36 +00:00
Warner Losh
f48bfebce1 Add EFI utility functions to libefi
This patch adds additional EFI utility functions to convert errno
values to EFI_STATUS errors, as well as EFI times to UNIX times.

Submitted by: Eric McCorkle
Differential Revision: https://reviews.freebsd.org/D11858
2017-08-04 04:20:11 +00:00
Warner Losh
457ea3bce3 Move EFI ZFS functions to libefi
This patch moves some EFI ZFS functions from loader to libefi,
allowing them to be used by anything that links against libefi.

Submitted by: Eric McCorkle
Differential Revision: https://reviews.freebsd.org/D11855
2017-08-04 04:20:06 +00:00
Warner Losh
acf82d2659 Add definitions and utilities for EFI drivers
This patch adds definitions and utility code for creating EFI drivers
using the EFI_DRIVER_BINDING_PROTOCOL.

Submitted by: Eric McCorkle
Differential Revision: https://reviews.freebsd.org/D11852
2017-08-04 04:16:41 +00:00
Andrew Turner
b56e404049 Always set the receive mask in loader.efi. Some UEFI implementations set
this to be too restrictive. We need to have both broadcast and unicast
enabled for loader to work. Set them in all cases to ensure this is true.

This allows the Cavium ThunderX 2s in the netperf cluster to netboot using
a USB NIC.

PR:		221001
Reviewed by:	emaste, tsoome
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D11732
2017-07-27 15:06:34 +00:00
Allan Jude
e11bad9d2b Integer underflow in efipart_realstrategy when I/O starts after end of disk
This fixes an integer underflow in efipart_realstrategy, which causes
crashes when an I/O operation's start point is after the end of the disk.
This can happen when trying to detect filesystems on very small disks.
This can occur if a BIOS freebsd-boot partition exists on a system when the
EFI loader is being used.

PR:		219000
Submitted by:	Eric McCorkle <eric@metricspace.net>
Reviewed by:	cem (previous version), tsoome (previous version)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D10559
2017-07-01 20:25:22 +00:00
Toomas Soome
da8fb057e5 loader: network read rework
The current read from network is working from up to down - we have some
protocol needing the data from the network, so we build the buffer space
for that protocol, add the extra space for headers and pass this buffer
down to be filled by nif get call in hope, we have guessed the incoming
packet size right. Amazingly enough this approach mostly does work, but
not always...

So, this update does work from down to up - we allocate buffer (based
on MTU or frame size info), fill it up, and pass on for upper layers.
The obvious problem is that when we should free the buffer - if at all.

In the current implementation the upper layer will free the packet on error
or when the packet is no longer needed.

While working on the issue, the additional issue did pop up - the bios
implementation does not have generic get/put interface but is using pxe
udpsend/udpreceive instead. So the udp calls are gone and undi interface
is implemented instead. Which in turn means slight other changes as we
do not need to have duplicated pxe implementation and can just use dev_net.

To align packet content, the actual read from nic is using shifted buffer by
ETHER_ALIGN (2).

Reviewed by:	bapt
Differential Revision:	https://reviews.freebsd.org/D10232
2017-05-06 20:32:27 +00:00
Toomas Soome
c9296b3227 loader: F_READ/F_WRITE should be checked against masked flag
The work to make it possible to avoid bcache via using F_NORA modifier did
miss the fact that not all loader platforms are using the bcache, and so
it is possible the modifier is not cleared, as bcache strategy function is
not used.

For fix, we make sure the checks are dont with masked flag.

This patch does fix boot for platforms which do not use bcache.

Reported by:	emaste
Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D10422
2017-04-18 18:07:54 +00:00
Alexander Kabaev
19f7eeed61 Do not use -msoft-float with intention of disabling FP on aarch64
GNU GCC does does recognise it as a valid option and we already
use -mgeneral-regs-only that has the desired effect.

Reviewed by: emaste
Differential Revision:	https://reviews.freebsd.org/D10306
2017-04-07 22:58:25 +00:00
Toomas Soome
4479aa540f loader: efipart should check disk size from partition table
While testing 32bit UEFI OVMF (which has bug about how the disk size
is presented), I did witness the errors from blkio->ReadBlocks().

It became apparent we can not entirely trust UEFI interfaces either,
so additional checks are needed.

So we use disk_ioctl(DIOCGMEDIASIZE) for disks, with fallback of
Media->LastBlock for other media.

In addition, we need to check if there is media present.

+ small fixes for error printout, and avoiding multiple blk * 512.

Reviewed by:	allanjude
Approved by:	allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D10197
2017-03-30 16:23:31 +00:00
Toomas Soome
b91aad35da loader: remove open_disk cache
As we provide the disk size verification and correction via disk_ioctl
and disk state provided by disk_open(), we can not share the partition
state in disk_devdesc structure. Also the sharing does make a lot of sense
with ufs, as only one partition is open at any given time, but zfs pools
do keep the disk devices open.

To make sure we do get the correct information about the open device,
just remove the cache.

Reviewed by:	allanjude, smh
Approved by:	allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D9757
2017-03-16 12:04:43 +00:00
Warner Losh
bea9d78b2d Share UCS2/UTF8 routines between boot loader and userland.
Move the UCS2 to UTF8 routines over into sys/boot/efi and have
libefivar grab them from there.

Sponsored by: Netflix
2017-03-09 00:24:01 +00:00
Pedro F. Giffuni
e099b90b80 sys: Replace zero with NULL for pointers.
Found with:	devel/coccinelle
MFC after:	3 weeks
Differential Revision:	https://reviews.freebsd.org/D9694
2017-02-22 02:35:59 +00:00
Toomas Soome
dcb8552acb loader: cstyle fixes and DIOCGMEDIASIZE should use uint64_t
Cleaned up some spaces where tabs should be.
efipart_ioctl() DIOCGMEDIASIZE needs to use uint64_t, not off_t

Reviewed by:	allanjude
Approved by:	allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D9562
2017-02-13 21:33:50 +00:00
Toomas Soome
c05d666747 loader: implement MEDIA_FILEPATH_DP support in efipart
The efipart rework did break the ARM systems as the new code is
using more exact filters to sort the devices and we need to
add support for MEDIA_FILEPATH_DP device paths.

PR:		216940
Reported by:	karl@denninger.net
Reviewed by:	allanjude, manu
Approved by:	allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D9520
2017-02-11 15:25:49 +00:00
Toomas Soome
c7bf8909b1 loader: possible NULL pointer dereference in efipart.c
Fix bugs found by Coverity in efipart.c.

The Issue is that efi_devpath_last_node() can return NULL pointer, and
therefore we should check for it. In real life we really do not
expect to see it to happen, so we will just error out from the test.

CID:		1371004
Reported by:	Coverity
Reviewed by:	allanjude
Approved by:	allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D9490
2017-02-08 15:52:09 +00:00
Emmanuel Vadot
9f0b20a57c efipart is also using the '%S' printf format, add -Wno-format for it.
This fix building for armv6.
2017-02-07 15:16:01 +00:00
Toomas Soome
467c82cb84 loader: Replace EFI part devices.
Rewrite EFI part device interface to present disk devices in more
user friendly way.

We keep list of three types of devices: floppy, cd and disk, the
visible names: fdX: cdX: and diskX:

Use common/disk.c and common/part.c interfaces to manage the
partitioning.

The lsdev -l will additionally list the device path.

Reviewed by:	imp, allanjude
Approved by:	imp (mentor), allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D8581
2017-02-06 09:18:47 +00:00
Toomas Soome
bfe9bdb063 loader: libefi/env.c warnings in arm build
The arm build has revealed some of the warnings, the fix for CHAR16
warning is to switch the warning off for env.c (same as for efinet.c).

For error code we need to use macro.

Reported by:	gjb
Reviewed by:	imp
Approved by:	imp (mentor)
Differential Revision:	https://reviews.freebsd.org/D9422
2017-02-03 16:39:10 +00:00
Toomas Soome
d124e3965a loader.efi environment related cleanups
Since we have dedicated libefi/env.c file for variable support, the following
changes are done:

Simple cstyle changes in env.c
Moved efi variable related commands from loader/main.c to libefi/env.c
Did create function to set "efi-version" environment variable in env.c.

This function does serve two purposes: for first a  small clean up of the
loader main(), and for second, it does replace the otherwise unused
efi_variable_support hack.
A bit of cleanup of ficl backend functions. The TEST_MAIN has no meaning,
and removed few memory leaks.

The forth code is updated to use "efi-version" variable, instead of ficl
environment check.

Reviewed by:	imp
Approved by:	imp (mentor)
Differential Revision:	https://reviews.freebsd.org/D9165
2017-02-01 08:46:59 +00:00
Toomas Soome
9c1cd3f5c3 loader: efi devpath api usage should be more aware of NULL pointers
As the efi_devpath_last_node() and efi_devpath_trim() can return NULL
pointers, the consumers of this API should check the the NULL pointers.

Same for efinet_dev_init() using calloc().

Reported by:	Robert Mustacchi <rm@joyent.com>
Reviewed by:	jhb, allanjude
Approved by:	allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D9203
2017-01-18 08:18:07 +00:00
Toomas Soome
fdb9150ea4 loader: move device path definitions to include/efidevp.h
No functional change, only moving uuid and protocol bits to include/efidevp.h

Reviewed by:	imp, jhb
Approved by:	imp (mentor)
Differential Revision:	https://reviews.freebsd.org/D9192
2017-01-16 20:57:01 +00:00
Toomas Soome
1ecc859193 dosfs support in libstand is broken since r298230
Apparently the libstand dosfs optimization is a bit too optimistic
and did introduce possible memory corruption.

This patch is backing out the bad part and since this results in
dosfs reading full blocks now, we can also remove extra offset argument
from dv_strategy callback.

The analysis of the issue and the backout patch is provided by Mikhail Kupchik.

PR:		214423
Submitted by:	Mikhail Kupchik
Reported by:	Mikhail Kupchik
Reviewed by:	bapt, allanjude
Approved by:	allanjude (mentor)
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D8644
2016-12-30 19:06:29 +00:00
Toomas Soome
77d81a4dab lsdev device name section headers should be printed by dv_print callback.
lsdev command does walk over devsw list, prints list element name and
will use dv_print() callback to print the device list.
Unfortunately this approach will add unneeded noise when there are no
particular devices detected.

To remove "empty" device section headers, the dv_print() callback
should print the header instead.

In addition, fixed dv_print callback for md module.

Reviewed by:	imp
Approved by:	imp (mentor)
Differential Revision:	https://reviews.freebsd.org/D8551
2016-11-19 08:54:21 +00:00
Toomas Soome
cbd6713146 Loader paged/pageable data is not always paged.
This change does modify devsw dv_print() to return the int value,
enabling walkers to interrupt the walk on non zero value from dv_print().

This will allow the pager_print actually to stop displaying data on
user input, and additionally pager is used in various *dev_print callbacks,
where it was missing.

For test, lsdev [-v] command should display data by screenfuls and should
stop when the key 'q' is pressed on pager prompt.

Reviewed by:	allanjude
Approved by:	allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D5461
2016-11-08 06:50:18 +00:00
Toomas Soome
e9915a079c efinet_dev_print should honor verbose option.
lsdev should display detailed information about net devices only with -v
switch. This will make EFI and BIOS version of the loader to have the
same behavior.

Reviewed by:	bapt, imp
Approved by:	imp (mentor)
Differential Revision:	https://reviews.freebsd.org/D8415
2016-11-02 06:37:35 +00:00
Warner Losh
dbef2d4941 Fix two backwards tests.
CID: 1365227, 1365228
2016-10-25 19:04:44 +00:00
Warner Losh
75a63b2de3 Really make WITHOUT_FORTH (MK_FORTH==no) work. The recent inclusion of
FICL definitions not in ficl/ficl32 files broke this generally. This
makes that stuff conditional on BOOT_FORTH. Also, move definitions
related to the architecture (FICL_CPUARCH and friends) into
Makefile.ficl that all parts of the tree that include files with ficl
need to include (but only if MK_FORTH == yes). In addition, had to fix
library ordering issue with LIBSTAND to keep it last. Without boot
forth, there's no references to memset to bring in memset.o from
libstand.a to satisfy libgeliboot.a's use of it. Listing libstand last
solves this issue (and it's the proper place for libstand to boot).
2016-10-25 17:31:57 +00:00
Andrew Turner
3ad9f8d024 Fix the build on both arm64 and when WITHOUT_FORTH is defined.
* On arm64 we need to use the ${MACHINE_CPUARCH} subdirectory.
 * env.c is only needed when using forth so only build it there.

Sponsored by:	ABT Systems Ltd
2016-10-25 14:01:13 +00:00
Warner Losh
b6110871b5 Preliminary support for EFI in boot loader. Define efi-boot forth
environment variable to allow conditional compilation based on EFI
being present or not. Provide efi-setenv, efi-getenv, and
efi-unsetenv, though those need improvement. Move the efi definition
to libefi (but include a reference so they get included).
2016-10-24 20:36:54 +00:00
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
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