Commit Graph

45 Commits

Author SHA1 Message Date
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
35a22bcbf7 Add double-inclusion protection.
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2016-09-18 17:35:24 +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
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
Pedro F. Giffuni
5d708ee940 sys/boot: spelling fixes in comments.
No functional change.
2016-04-30 00:26:38 +00:00
Andrew Turner
fe3232f39a Make efi_time and EFI_GetTimeOfDay static, neither are used by other parts
of the efi code.

Sponsored by:	ABT Systems Ltd
2016-02-21 21:20:23 +00:00
Steven Hartland
89b50f6b4d Fix EFI multi device boot support
Fix EFI boot support when presented with multiple valid boot partitions
across multiple devices.

It now prefers to boot from partitions that are present on the underlying
device that the boot1 image was loaded from. This means that it will boot
from the partitions on device the user chose from EFI boot menu in
preference to those on other devices.

Also fixed is the recovery from a failed attempt to boot, from a seemingly
valid partition, by continuing to trying all other available partitions
no matter what the error.

boot1 now use * to signify a partition what was accepted from the preferred
device and + otherwise.

Finally some error messages where improved and DPRINTF's with slowed boot
to aid debugging.

ZFS will still be preferred over UFS when both are available on the boot
device.

Reviewed by:	imp
MFC after:	1 week
Sponsored by:	Multiplay
Differential Revision:	https://reviews.freebsd.org/D5108
2016-02-05 15:35:33 +00:00
Steven Hartland
7bd249ecf0 Add EFI ZFS boot support
This builds on the modular EFI loader support added r294060 adding a
module to provide ZFS boot support on EFI systems.

It should be noted that EFI uses a fixed size memory block for all
allocations performed by the loader so it may be necessary to tune this
size.

For example when building an image which uses mfs_root e.g. mfsbsd, adding
the following to /etc/make.conf would be needed to prevent EFI from running
out of memory when loading the mfs_root image.
EFI_STAGING_SIZE=128

Submitted by:	Eric McCorkle
MFC after:	2 weeks
X-MFC-With:	r293268
Sponsored by:	Multiplay
2016-01-15 02:33:47 +00:00
Steven Hartland
b2ec7c304e Modularise EFI boot loader
Make EFI boot loader modular in preparation for adding ZFS support.

This is a partial commit of the D4515.

Submitted by:	Eric McCorkle
Reviewed by:	emaste (in part)
MFC after:	2 weeks
X-MFC-With:	r293268
Sponsored by:	Multiplay
Differential Revision:	https://reviews.freebsd.org/D4515
2016-01-15 01:22:36 +00:00
Steven Hartland
022e692a47 Enable warnings in EFI boot code
Set WARNS if not set for EFI boot code and fix the issues highlighted by
setting it.

Most components are set to WARNS level 6 with few being left at lower
levels due to the amount of changes needed to fix at higher levels.

Error types fixed:
* Missing / invalid casts
* Missing inner structs
* Unused vars
* Missing static for internal only funcs
* Missing prototypes
* Alignment changes
* Use of uninitialised vars
* Unknown pragma (intrinsic)
* Missing types etc due to missing includes
* printf formatting types

Reviewed by:	emaste (in part)
MFC after:	2 weeks
X-MFC-With:	r293268
Sponsored by:	Multiplay
Differential Revision:	https://reviews.freebsd.org/D4839
2016-01-12 02:17:39 +00:00
Steven Hartland
d446abfaec Fix _MSC_EXTENSIONS checks
Use #ifdef instead of #if checks to prevent warnings generated by checks
to be enabled shortly.

MFC after:	2 weeks
Sponsored by:	Multiplay
2016-01-06 20:22:28 +00:00
Ed Maste
c82e181b74 Introduce and use new EFI_ERROR_CODE macro for EFI errors
Submitted by:	smh
MFC after:	1 week
2016-01-06 19:15:16 +00:00
Ed Maste
7ebeabcf9b Revert accidental whitespace changes included with r292623 2015-12-22 20:40:34 +00:00
Ed Maste
6ee0db8b76 Support a.out format in nlist only on i386
i386 is the only current FreeBSD architecture that ever used a.out
format.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D4687
2015-12-22 20:36:14 +00:00
Marcel Moolenaar
7aefa262d6 Add support for the UGA draw protocol. This includes adding a
command called 'uga' to show whether UGA is implemented by the
firmware and what the settings are. It also includes filling
the efi_fb structure from the UGA information when GOP isn't
implemented by the firmware.

Since UGA does not provide information about the stride, we
set the stride to the horizontal resolution. This is likely
not correct and we should determine the stride by trial and
error. For now, this should show something on the console
rather than nothing.

Refactor this file to maximize code reuse.

PR:		202730
2015-08-30 23:58:53 +00:00
Andrew Turner
0cafabf97f Add support for arm64 to loader.efi and boot1.efi
Reviewed by:	emaste
Sponsored by:	The FreeBSD Foundation
2015-04-14 13:55:01 +00:00
Andrew Turner
63d071445e Add support to the efi boot1 and loader for 32-bit ARM. This will be used
by the future qemu virt support.

Differential Revision:	https://reviews.freebsd.org/D2238
Reviewed by:	emaste
2015-04-06 15:50:20 +00:00
Warner Losh
cda676ac0d Allow EFI and ACPI to be included together. When ACPI is included
first, EFI will use its definitions for {,U}INT{8,16,32,64} and
BOOLEAN. When EFI is included first, define ACPI_USE_SYSTEM_INTTYPES
to tell ACPI that these are already defined.

Differential Revision: https://reviews.freebsd.org/D1905
2015-02-20 01:40:55 +00:00
Rui Paulo
e708492700 EFI: print more information about EFI Tables.
This adds the GUIDs for DXE, HOB, Memory Type Information and Debug
Image Info.
2015-02-05 07:19:30 +00:00
Andrew Turner
c57b131994 Add the FDT table GUID. This is used to pass the device tree blob from UEFI
to the loader in a similar way to the ACPI tables.

This will be used on arm64 but is not specific to the architecture.

Sponsored by:	The FreeBSD Foundation
2014-11-12 17:56:38 +00:00
Ed Maste
7797431f9a Remove duplicated header content
I fail at patch(1).

MFC after:	3 days
2014-09-25 13:31:08 +00:00
Ed Maste
3bcd280e3b Switch to text mode in UEFI boot
The loader previously failed to display on MacBooks and other systems
where the UEFI firmware remained in graphics mode.

Submitted by:	Rafael Espíndola
2014-09-18 13:59:36 +00:00
Marcel Moolenaar
e7d939bda2 Remove ia64.
This includes:
o   All directories named *ia64*
o   All files named *ia64*
o   All ia64-specific code guarded by __ia64__
o   All ia64-specific makefile logic
o   Mention of ia64 in comments and documentation

This excludes:
o   Everything under contrib/
o   Everything under crypto/
o   sys/xen/interface
o   sys/sys/elf_common.h

Discussed at: BSDcan
2014-07-07 00:27:09 +00:00
Ed Maste
8c00aba8c4 Support UEFI booting on amd64 via loader.efi
This is largely the work from the projects/uefi branch, with some
additional refinements.  This is derived from (and replaces) the
original i386 efi implementation; i386 support will be restored later.

Specific revisions of note from projects/uefi:

r247380:

  Adjust our load device when we boot from CD under UEFI.

  The process for booting from a CD under UEFI involves adding a FAT
  filesystem containing your loader code as an El Torito boot image.
  When UEFI detects this, it provides a block IO instance that points at
  the FAT filesystem as a child of the device that represents the CD
  itself. The problem being that the CD device is flagged as a "raw
  device" while the boot image is flagged as a "logical partition". The
  existing EFI partition code only looks for logical partitions and so
  the CD filesystem was rendered invisible.

  To fix this, check the type of each block IO device. If it's found to
  be a CD, and thus an El Torito boot image, look up its parent device
  and add that instead so that the loader will then load the kernel from
  the CD filesystem.  This is done by using the handle for the boot
  filesystem as an alias.

  Something similar to this will be required for booting from other
  media as well as the loader will live in the EFI system partition, not
  on the partition containing the kernel.

r246231:

  Add necessary code to hand off from loader to an amd64 kernel.

r246335:

  Grab the EFI memory map and store it as module metadata on the kernel.

  This is the same approach used to provide the BIOS SMAP to the kernel.

r246336:

  Pass the ACPI table metadata via hints so the kernel ACPI code can
  find them.

r246608:

  Rework copy routines to ensure we always use memory allocated via EFI.

  The previous code assumed it could copy wherever it liked. This is not
  the case. The approach taken by this code is pretty ham-fisted in that
  it simply allocates a large (32MB) buffer area and stages into that,
  then copies the whole area into place when it's time to execute. A more
  elegant solution could be used but this works for now.

r247214:

  Fix a number of problems preventing proper handover to the kernel.

  There were two issues at play here. Firstly, there was nothing
  preventing UEFI from placing the loader code above 1GB in RAM. This
  meant that when we switched in the page tables the kernel expects to
  be running on, we are suddenly unmapped and things no longer work. We
  solve this by making our trampoline code not dependent on being at any
  given position and simply copying it to a "safe" location before
  calling it.

  Secondly, UEFI could allocate our stack wherever it wants. As it
  happened on my PC, that was right where I was copying the kernel to.
  This did not cause happiness. The solution to this was to also switch
  to a temporary stack in a safe location before performing the final
  copy of the loaded kernel.

r246231:

  Add necessary code to hand off from loader to an amd64 kernel.

r246335:

  Grab the EFI memory map and store it as module metadata on the kernel.

  This is the same approach used to provide the BIOS SMAP to the kernel.

r246336:

  Pass the ACPI table metadata via hints so the kernel ACPI code can
  find them.

r246608:

  Rework copy routines to ensure we always use memory allocated via EFI.

  The previous code assumed it could copy wherever it liked. This is not
  the case. The approach taken by this code is pretty ham-fisted in that
  it simply allocates a large (32MB) buffer area and stages into that,
  then copies the whole area into place when it's time to execute. A more
  elegant solution could be used but this works for now.

r247214:

  Fix a number of problems preventing proper handover to the kernel.

  There were two issues at play here. Firstly, there was nothing
  preventing UEFI from placing the loader code above 1GB in RAM. This
  meant that when we switched in the page tables the kernel expects to
  be running on, we are suddenly unmapped and things no longer work. We
  solve this by making our trampoline code not dependent on being at any
  given position and simply copying it to a "safe" location before
  calling it.

  Secondly, UEFI could allocate our stack wherever it wants. As it
  happened on my PC, that was right where I was copying the kernel to.
  This did not cause happiness. The solution to this was to also switch
  to a temporary stack in a safe location before performing the final
  copy of the loaded kernel.

r247216:

  Use the UEFI Graphics Output Protocol to get the parameters of the
  framebuffer.

Sponsored by:	The FreeBSD Foundation
2014-04-04 00:16:46 +00:00
Ed Maste
ee83e77448 Merge efilib changes from projects/uefi
r247216:

  Add the ability for a device to have an "alias" handle.

r247379:

  Fix network device registration.

r247380:

  Adjust our load device when we boot from CD under UEFI.

  The process for booting from a CD under UEFI involves adding a FAT
  filesystem containing your loader code as an El Torito boot image.
  When UEFI detects this, it provides a block IO instance that points
  at the FAT filesystem as a child of the device that represents the CD
  itself. The problem being that the CD device is flagged as a "raw
  device" while the boot image is flagged as a "logical partition".
  The existing EFI partition code only looks for logical partitions and
  so the CD filesystem was rendered invisible.

  To fix this, check the type of each block IO device. If it's found to
  be a CD, and thus an El Torito boot image, look up its parent device
  and add that instead so that the loader will then load the kernel from
  the CD filesystem.  This is done by using the handle for the boot
  filesystem as an alias.

  Something similar to this will be required for booting from other media
  as well as the loader will live in the EFI system partition, not on the
  partition containing the kernel.

r247381:

  Remove a scatalogical debug printf that crept in.
2014-04-03 21:39:59 +00:00
Ed Maste
80cd00209b Add amd64 EFI headers
Sponsored by:	The FreeBSD Foundation
2014-03-13 18:17:18 +00:00
Marcel Moolenaar
716f79c093 Remove file system support based on the simple file system protocol
as this only allows us to access file systems that EFI knows about.
With a loader that can only use EFI-supported file systems, we're
forced to put /boot on the EFI system partition. This is suboptimal
in the following ways:
1.  With /boot a symlink to /efi/boot, mergemaster complains about
    the mismatch and there's no quick solution.
2.  The EFI loader can only boot a single version of FreeBSD. There's
    no way to install multiple versions of FreeBSD and select one
    at the loader prompt.
3.  ZFS maintains /boot/zfs/zpool.cache and with /boot a symlink we
    end up with the file on a MSDOS file system. ZFS does not have
    proper handling of file systems that are under Giant.

Implement a disk device based on the block I/O protocol instead and
pull in file system code from libstand. The disk devices are really
the partitions that EFI knows about.

This change is backward compatible.

MFC after:	1 week
2010-01-09 22:54:29 +00:00
Marcel Moolenaar
0463b4a2fb Major rework of the ia64 loaders. The two primary objectives are:
1. Make libefi portable by removing ia64 specific code and build
   it on i386 and amd64 by default to prevent regressions. These
   changes include fixes and improvements over previous code to
   establish or improve APIs where none existed or when the amount
   of kluging was unacceptably high.
2. Increase the amount of sharing between the efi and ski loaders
   to improve maintainability of the loaders and simplify making
   changes to the loader-kernel handshaking in the future.

The version of the efi and ski loaders are now both changed to 1.2
as user visible improvements and changes have been made.
2006-11-05 22:03:04 +00:00
Marcel Moolenaar
6576695766 Sync the EFI headers with version 1.10.14.62 of the Intel sample EFI
implementation. This re-introduces C99 style comments that previously
were replaced by original C comments.
2006-11-02 02:42:48 +00:00
Stefan Farfeleder
ea8b0ab337 Don't try to use 'typedef struct foo' if just 'struct foo' makes more sense
and works on all compilers.  This also removes the need for
__CC_SUPPORTS_FORWARD_REFERENCE_CONSTRUCT in <sys/cdefs.h>.

OK'ed by:	marcel, dfr
2005-03-07 15:38:37 +00:00
Stefan Farfeleder
0eca8743b8 Fix typos in a comment. 2005-03-06 13:53:05 +00:00
Joerg Wunsch
a5f50ef9e4 netchild's mega-patch to isolate compiler dependencies into a central
place.

This moves the dependency on GCC's and other compiler's features into
the central sys/cdefs.h file, while the individual source files can
then refer to #ifdef __COMPILER_FEATURE_FOO where they by now used to
refer to #if __GNUC__ > 3.1415 && __BARC__ <= 42.

By now, GCC and ICC (the Intel compiler) have been actively tested on
IA32 platforms by netchild.  Extension to other compilers is supposed
to be possible, of course.

Submitted by:	netchild
Reviewed by:	various developers on arch@, some time ago
2005-03-02 21:33:29 +00:00
Warner Losh
6a0fd84b50 Start each of the license/copyright comments with /*- 2005-01-05 22:16:58 +00:00
Marcel Moolenaar
f3beed66fa o Introduce efimd_va2pa() to translate addresses in efi_copy{in|out}()
and efi_readin(). This removes MD code from copy.c.
o  Don't unconditionally add pal.S to SRCS. It's specific to ia64.
2004-11-28 00:30:22 +00:00
John Baldwin
1696e797f4 Fix typo in comment. 2003-12-10 19:08:09 +00:00
Marcel Moolenaar
6257165c74 Pass the HCDP table address to the kernel. If no such table exists,
NULL is passed. The address of the HCDP table can be found by
iterating over the configuration tables in the EFI system table.
To avoid more duplication, a function can be called with the GUID
of interest. The function will do the scanning. Use the function
in all places where we iterate over the configuration tables in
an attempt to find a specific one.

Bump the loader version number as the result of this.

Approved by: re (blanket)
2002-12-10 20:11:20 +00:00
Marcel Moolenaar
155dbcacfb Change the startup code to fix a memory leak and to allow us to
accept load options (=command line options).

The call graph changes from *entry*->efi_main->efi_init, where
efi_main is the EFI equivalent of main to *entry*->efi_main->main,
where main is what you'd expect. efi_main now is what efi_init was.
The prototype of main follows that of C. The first argument is argc
and the second is argv. There is no third argument.
Allocation of heap pages is now handled by the EFI library and it
now deallocates the pages when main() returns or when exit() is
called. This allows us to safely return to the boot manager (or
EFI shell) without leaks. EFI applications are responsible to free
all memory themselves.

Handling of the load options is a bit tricky. There are either no
load options, load options in ASCII or load options in Unicode.
The EFI library will translate the ASCII options to Unicode options
as to simplify user code. Since the load options are passed as a
single string (if present) and main() accepts argc and argv, the
startup code also has to split the string into words and build the
argv vector. Here the trickiness starts. When the loader is started
from the EFI shell, argv[0] will automaticly load the program name.
In all other cases (ie through the boot manager), this is not the
case. Unfortunately, there's no trivial way to check. Hence, a
set of conditions is checked to determine if we need to fill in
argv[0] ourselves or not. This checking is not perfect. There are
known cases where it fails to do the right thing. The logic works
for most expected cases, though. This includes the case where no
options are given.

Approved by: re (blanket)
2002-12-10 06:22:25 +00:00
Marcel Moolenaar
0068037936 Add the GUID of the DIG64 HCDP table. 2002-12-08 20:47:44 +00:00
Marcel Moolenaar
06cb726431 An almost mechanical sweep to replace C++ style comments with C
style comments. This is not an attempt to conform to style(9).
Such has lower priority.
2002-05-19 03:17:22 +00:00
Tom Rhodes
d394511de3 More s/file system/filesystem/g 2002-05-16 21:28:32 +00:00
Peter Wemm
9b6a75edb3 gcc-3.1 likes to have extra { } around the internal array initializers in
the GUID templates.
2002-03-19 10:50:09 +00:00
Peter Wemm
24ffe931b9 Lookup the EFI_FPSWA driver and pass the interface pointer through to the
kernel before we call ExitBootServices().  I've typed the definitions
in efifpswa.h from the Intel FPSWA manual (urk).
2001-11-19 07:09:47 +00:00
Peter Wemm
8e92224a8a This is used in C, not C++. functions with no args have func(void) in our
kernel.
2001-11-19 06:58:14 +00:00
Mike Barcroft
0ac2d551f2 o Add new header <sys/stdint.h>.
o Make <stdint.h> a symbolic link to <sys/stdint.h>.
o Move most of <sys/inttypes.h> into <sys/stdint.h>, as per C99.
o Remove <sys/inttypes.h>.
o Adjust includes in sys/types.h and boot/efi/include/ia64/efibind.h
  to reflect new location of integer types in <sys/stdint.h>.
o Remove previously symbolicly linked <inttypes.h>, instead create a
  new file.
o Add MD headers <machine/_inttypes.h> from NetBSD.
o Include <sys/stdint.h> in <inttypes.h>, as required by C99; and
  include <machine/_inttypes.h> in <inttypes.h>, to fill in the
  remaining requirements for <inttypes.h>.
o Add additional integer types in <machine/ansi.h> and
  <machine/limits.h> which are included via <sys/stdint.h>.

Partially obtain from:	NetBSD
Tested on:		alpha, i386
Discussed on:		freebsd-standards@bostonradio.org
Reviewed by:		bde, fenner, obrien, wollman
2001-11-02 18:05:43 +00:00
Doug Rabson
fd3e14e915 First approximation of an ia64 EFI loader. Not functional. 2001-06-09 16:49:51 +00:00