Commit Graph

58 Commits

Author SHA1 Message Date
Justin Hibbits
1ea717577f Allow efi loader to get network params from uboot
Summary:
efi loader does not work with static network parameters. It always uses
BOOTP/DHCP and also uses RARP as a fallback.  Problems with DHCP servers can
cause the loader to fail to populate network parameters.

Submitted by:	Siddharth Tuli <siddharthtuli_gmail.com>
Reviewed by:	imp
Sponsored by:	Juniper Networks, Inc.
Differential Revision:	https://reviews.freebsd.org/D20811
2019-07-12 00:54:20 +00:00
Toomas Soome
21b2840e7d efihttp: mac and err can be used uninitialized
While there, also check if mac != NULL, and use pointer compare for ipv4
and dns.
2019-07-02 20:32:35 +00:00
Toomas Soome
8136db2894 efihttp: mark unused arguments with __unused
we do have __unused, lets use it.
2019-06-30 20:21:27 +00:00
Toomas Soome
f7ae06cb5e efihttp: comparison of integers of different signs
message.HeaderCount is UINTN (unsigned int), so should be i.
2019-06-30 20:18:31 +00:00
Toomas Soome
5bca29b882 Clean efihttp pointer-sign warnings
The Http protocol structure is using unsigned char strings, Use type casts
where needed.
2019-06-30 20:15:02 +00:00
Rebecca Cran
1ee03da25e Re-enable loader efi http boot and fix dv_open bug if dv_init failed
The code in efihttp.c was assuming that dv_open wouldn't be called if
dv_init failed. But the dv_init return value is currently ignored.

Add a new variable, `efihttp_init_done` and only proceed in dv_open if
it's true. This fixes the loader on systems without efi http support.
2019-06-26 03:06:57 +00:00
Rebecca Cran
da4961c796 loader: add HTTP support using UEFI
Add support for an HTTP "network filesystem" using the UEFI's HTTP
stack.

This also supports HTTPS, but TianoCore EDK2 implementations currently
crash while fetching loader files.
Only IPv4 is supported at the moment. IPv6 support is planned for a
follow-up changeset.

Note that we include some headers from the TianoCore EDK II project in
stand/efi/include/Protocol verbatim, including links to the license instead
of including the full text because that's their preferred way of
communicating it, despite not being normal FreeBSD project practice.

Submitted by:	scottph
Reviewed by:	imp, bcran
Differential Revision:	https://reviews.freebsd.org/D20643
2019-06-24 23:18:42 +00:00
Rebecca Cran
3109cebc22 efinet: Defer exclusively opening the network handles
Don't commit to exclusive access to the network device handle by
efinet until the loader has decided to load something through the
network. This allows for the possibility of other users of the
network device.

Submitted by:	scottph
Reviewed by:	tsoome, emaste
Tested by: 	tsoome, bcran
Differential Revision:	https://reviews.freebsd.org/D20642
2019-06-19 18:47:44 +00:00
Warner Losh
83ffeb8b52 Introduce efi_devpath_same_disk
This is like efi_devpath_match, but allows differing device media
paths. Those just specify the partition information.

Differential Revision: https://reviews.freebsd.org/D20513
2019-06-04 18:36:07 +00:00
Toomas Soome
2a0e2c88db loader: no-TERM_EMU is broken now
If TERM_EMU is not defined, we do not have curx variable. Use conout mode
for efi and expose get_pos() for i386.
2019-05-09 12:14:52 +00:00
Toomas Soome
686d524bc9 loader: implement proper 8 char tab stops
The current console code is printing out 8 spaces for tab, calculate
the amount of spaces based on tab stops.
2019-05-09 10:37:57 +00:00
Warner Losh
b9e19b077e Abstract out efi_devpath_to_handle to search for a handle that matches
the desired devpath.
2019-05-06 18:39:27 +00:00
Warner Losh
751241a7c7 Add efi_freebsd_delenv
Add a wrapper around efi_delenv akin to efi_freebsd_getenv and
efi_getenv.
2019-04-25 20:09:49 +00:00
Warner Losh
59a05bdf35 Create boot_img as a global variable
Get the information from the image that we're booting and store it in
a global variable. Prefer using this to passing it around. Remove the
special case for zfs that set the preferred boot handle by having it
uses this global variable diretly.

Reviewed by: kevans@
Differential Revision: https://reviews.freebsd.org/D20015
2019-04-22 18:40:24 +00:00
Warner Losh
3d384d51aa Start to reduce the number of #ifdef EFI_ZFS_BOOT
There's a number of EFI_ZFS_BOOT #ifdefs that aren't needed, or can be
eliminated with some trivial #defines. Remove the EFI_ZFS_BOOT ifdefs
that aren't needed. Replace libzfs.h include which is not safe to
include without EFI_ZFS_BOOT with efizfs.h which is and now
conditionally included libzfs.h. Define efizfs_set_preferred away
and define efi_zfs_probe to NULL when ZFS is compiled out.
2019-04-20 05:31:56 +00:00
Warner Losh
16b07b25c4 Add wrapper functions to convert strings to EFI_DEVICE_PATH
In anticipation of new functionality, create routines to convert char *
and a CHAR16 * to a EFI_DEVICE_PATH
	EFI_DEVICE_PATH *efi_name_to_devpath(const char *path);
	EFI_DEVICE_PATH *efi_name_to_devpath16(CHAR16 *path);
	void efi_devpath_free(EFI_DEVICE_PATH *dp);
The first two return an EFI_DEVICE_PATH for the passed in paths. The
third frees up the storage the first two return when the caller is
done with it.

Differential Revision: https://reviews.freebsd.org/D19971
2019-04-19 19:45:19 +00:00
Warner Losh
a13881aff4 Add efi_delenv
Add an interface to remove / delete UEFI variables.
2019-04-18 05:40:50 +00:00
Warner Losh
883d342d38 Add a more generic efi_setenv function.
efi_setenv allows any UEFI variable to be set.
2019-04-18 05:37:18 +00:00
Ian Lepore
14243f8de7 Distinguish between "no partition" and "choose best partition" with a constant.
The values of the d_slice and d_partition fields of a disk_devdesc have a
few values with special meanings in the disk_open() routine. Through various
evolutions of the loader code over time, a d_partition value of -1 has
meant both "use the first ufs partition found in the bsd label" and "don't
open a bsd partition at all, open the raw slice."

This defines a new special value of -2 to mean open the raw slice, and it
gives symbolic names to all the special values used in d_slice and
d_partition, and adjusts all existing uses of those fields to use the new
constants.

The phab review for this timed out without being accepted, but I'm still
citing it below because there is useful commentary there.

Differential Revision:	https://reviews.freebsd.org/D19262
2019-03-24 18:51:52 +00:00
John Baldwin
2e43efd0bb Drop "All rights reserved" from my copyright statements.
Reviewed by:	rgrimes
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D19485
2019-03-06 22:11:45 +00:00
Marcin Wojtas
8157763ec7 Allow reading the UEFI variable size
When loading bigger variables form UEFI it is necessary to know their
size beforehand, so that an appropriate amount of memory can be
allocated. The easiest way to do this is to try to read the variable
with buffer size equal 0, expecting EFI_BUFFER_TOO_SMALL error to be
returned. Allow such possible approach in efi_getenv routine.

Extracted from a bigger patch as suggested by imp.

Submitted by: Kornel Duleba <mindal@semihalf.com>
Obtained from: Semihalf
Sponsored by: Stormshield
2019-02-08 14:56:28 +00:00
Warner Losh
52467047aa Regularize the Netflix copyright
Use recent best practices for Copyright form at the top of
the license:
1. Remove all the All Rights Reserved clauses on our stuff. Where we
   piggybacked others, use a separate line to make things clear.
2. Use "Netflix, Inc." everywhere.
3. Use a single line for the copyright for grep friendliness.
4. Use date ranges in all places for our stuff.

Approved by: Netflix Legal (who gave me the form), adrian@ (pmc files)
2019-02-04 21:28:25 +00:00
Matt Macy
fbeb31a26b MK_ZFS -> {MK_ZFS|MK_LOADER_ZFS}, this is so we can diable userland / kernel
ZFS but keep the boot-loaders when using ZoL port.

MFC after: 1 week
Reviewed by: rgrimes
Differential Revision: https://reviews.freebsd.org/D18739
2019-01-05 22:45:20 +00:00
Toomas Soome
6564182252 loader.efi: efi variable rework and lsefi command added
This update does add diag and debug capabilities to interpret the efi
variables, configuration and protocols (lsefi).

The side effect is that we add/update bunch of related headers.
2019-01-03 20:27:50 +00:00
Toomas Soome
34ada20958 loader.efi: update memmap command to recognize new attributes
Also move memory type to string translation to libefi for later use.

MFC after:	2 weeks
2019-01-03 09:03:58 +00:00
Toomas Soome
fb0df66629 loader.efi: fix EFI getchar() for multiple consoles
This fix is ported from illumos (issue #9970), the analysis and initial
implementation was done by John Levon.

See also: https://www.illumos.org/issues/9970

Currently, efi_cons_getchar() will wait for a key. While this seems to make
sense, the implementation of getchar() in common/console.c will loop across
getchar() for all consoles without doing ischar() first.

This means that if we've configured multiple consoles, we can't input into
the serial, as getchar() will be sat waiting for input only from efi_console.c

This patch does implement a bit more generic key buffer to support
translation of input keys, and we use generic efi_readkey() to reduce
duplication from calls from getchar() and poll().
2018-11-30 08:42:14 +00:00
Rebecca Cran
9a815e0a58 Simplify the EFI delay() function by calling BS->Stall()
Differential Revision: https://reviews.freebsd.org/D16753
2018-10-26 21:57:22 +00:00
Warner Losh
00a47597a3 Implement efiblk_get_pdinfo_by_device_path
Lookup a block device by it's device path. We use a 'loose' lookup
whereby we scan forward to the first Media Path portion of the device
path, then look at all our handles for one whose first Media Path
matches. This will also work if the device path pointed to has a
following file path (or paths) as that's ignored. It assumes that
there's only one media path node that describes the entire device,
which is true as of the latest UEFI spec (2.7 Errata A) as far as I've
been able to determine.

Sponsored by: Netflix
2018-07-23 20:36:54 +00:00
Warner Losh
c6c2a73c0c Implement efi_devpath_length
Return the total length, in bytes, of the device path (including the
terminating node at the end).

Sponsored by: Netflix
2018-07-23 20:36:50 +00:00
Warner Losh
13850b362f Implement efi_devpath_match_node
Returns true if the first node pointed to by devpath1 is identical to
the first node pointed to by devpath2, with care taken to not read
past the end of the valid parts of either devpath1 or
devpath2. Otherwise, returns false.

Sponsored by: Netflix
2018-07-23 20:36:45 +00:00
Warner Losh
3ef81aa0f5 Store the number of handles we get back in efipart_nhandles rather
than the number of bytes. Don't divide by the element size every time
we have to iterate. Eliminate now-unused variables.

Sponsored by: Netflix
2018-07-23 20:36:41 +00:00
Warner Losh
ee4e1d5807 Implement efi_devpath_to_media_path
Takes a generic device path as its input. Scans through it to find the
first media_path node in it and returns a pointer to it. If none is
found, NULL is returned.

Sponsored by: Netflix
2018-07-23 20:36:25 +00:00
Warner Losh
5a399a1a39 Remove bogus attempt to simulate scrolling. It's not needed and messes
up serial output. Setting the cursor position after every character is
inefficient, and causes all lines to be over-printed in the serial
console for the boot loader. Allow the terminal to do the emulation.

This isn't completely perfect when the size of the terminal attached
to the serial port isn't the same as 80x25 to match the viedoe console
(or whatever the video console is). While imperfect still, these
changes make it much better.

This makes the serial port useful with UEFI.

Differential Revision: https://reviews.freebsd.org/D16309
2018-07-17 21:45:14 +00:00
Warner Losh
11df3a2881 More typos
Noticed by: ian@
2018-07-17 20:26:17 +00:00
Warner Losh
debf8b839b Fix typo in the command summary.
Of course, I can't get the command to work, but it's a start...
2018-07-17 20:11:52 +00:00
Warner Losh
c2bac3e1ba Provide a more direct interface to tell ZFS what the preferred handle
is. We tell the ZFS code now, and it checks rather than having a
callback to do the checks.

This will allow us to have a more graceful fallback code. In the
future, it's anticipated that we may fallback to a more global search
(or implement a command to do so) when reqeusted by the user, or we
detect a violation of the UEFI Boot Manager protocol severe enough to
warrant this backstop. For now, it just allows us to get rid of img as
a global.

Sponsored by: Netflix
2018-06-15 19:07:26 +00:00
Warner Losh
fa9dc8d3ed Refactor currdev setting
Refactor the currdev setting to find the device we booted from. Limit
searching when we don't already have a reasonable currdev from that to
the same device only. Search a little harder for ZFS volumes as that's
needed for loader.efi to live on an ESP.

Sponsored by: Netflix
Differential Review: https://reviews.freebsd.org/D13784
2018-04-11 19:46:24 +00:00
Emmanuel Vadot
c5cf2b33fe efinet: Do not return only if ReceiveFilter fails
If the network interface or the uefi implementation do not support the
ReceiveFilter interface do not return only and just print a message.
U-Boot doesn't support is and likely never will. Also even if this fails
it doesn't mean that network in EFI isn't supported.
2018-03-30 16:37:08 +00:00
Kyle Evans
bc40337bb0 loader consoles: Implement SGR 24, 25
Mostly for completeness sake- implement 24 (no underline) and 25 (no blink)

MFC after:	3 days
2018-03-24 02:01:25 +00:00
Kyle Evans
88ccfa7497 Loader consoles: Implement SGR 22, reset intensity
MFC after:	3 days
2018-03-23 03:48:45 +00:00
Toomas Soome
255b83725c libefi: UEFI_BOOT_VAR_GUID duplicates EFI_GLOBAL_VARIABLE
Drop UEFI_BOOT_VAR_GUID and use EFI_GLOBAL_VARIABLE.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D14696
2018-03-15 05:58:35 +00:00
Warner Losh
5722dd8394 Move the env convenience routines out of boot1.c.
These routines are more generally useful. Even though boot1 is on its
way out, it's better to make these common during the transition than
copy them.
2018-03-12 21:40:14 +00:00
Warner Losh
f7b26b765b Use the one-line-per-file pattern here, and sort the file names.
Sponsored by: Netflix
2018-03-12 21:40:09 +00:00
Warner Losh
2472d92505 GC unused routines.
Sponsored by: Netflix
2018-03-12 21:40:05 +00:00
Warner Losh
ad00892f4c Remove d_type from devdesc. It's not needed as we can fetch it from
d_dev->dv_type when we need it.
2018-03-12 21:39:59 +00:00
Warner Losh
de04d704a9 Use the actual struct devdesc at the start of all *_devdesc structs
The current system is fragile and requires very careful layout of all
*_devdesc structures. It also makes it hard to change the base
devdesc. Take a page from CAM and put the 'header' in all the derived
classes and adjust the code to match.

For OFW, move the iHandle h_handle out of a slot conflicting with
d_opendata. Due to quirks in the alignment rules, this worked.
However changing the code to use d_opendata storage now that it's a
pointer is hard, so just have a separate field for it.

All other cleanups were to make the *_devdesc structures match where
they'd taken some liberties that were none-the-less compatible enough
to work.
2018-03-12 21:39:49 +00:00
Warner Losh
49898aa2ff We can't use d_opendata for blkio storage.
open_disk uses d_opendata for it's own purpse. We can't store blkio
there. Fortunately, blkio is stored elsewhere and we never actually
retrieve blkio from d_opendata. Eliminate it as a source of confusion.
Eliminate all stores of d_opendata in efi since this layer doesn't own
that field.
2018-03-12 21:39:38 +00:00
Warner Losh
4784aef9f5 Consolidate three copies of ZFS commands into a central location.
There's no reason to have multiple copies of lszfs and
reloadbe. Consolidate them into one location. Also ldi_get_size is the
same everywhere (except sparc64). Make it the same everywhere as the
common definition is more general and will work on spar64.
2018-02-21 15:57:36 +00:00
Emmanuel Vadot
8b75269237 efi: Only scan the BLKIO MEDIA once
Scan only the BLOCK IO MEDIA once instead of each time for each type of
device (fd, cd and hdd).
Leave the mechanism to free and reprobe all devices if one day we want
to implement a "dev rescan" thing.

Reviewed by:	imp, tsoome
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D14334
2018-02-14 18:05:37 +00:00
Warner Losh
b28421d5f1 These 4th words were an attempt to allow integration into the boot
loader scripts. However, that path won't be taken after all it
seems. Remove this code before it decays into uselessness. Also remove
build dependencies on forth no longer needed.
2018-02-02 15:01:44 +00:00