Commit Graph

1131 Commits

Author SHA1 Message Date
Simon J. Gerraty
c7e6f9dcf5 Allow loader.efi to identify non-standard boot setup
PATH_BOOTABLE_TOKEN can be set to a non-standard
path that identifies a device as bootable.

Reviewed by: kevans, bcran
Differential Revision:  https://reviews.freebsd.org/D22062
2019-10-17 20:40:06 +00:00
Toomas Soome
abc23d5932 boot1.efi: provide generic exit() and stub getchar()
panic() is expecting us to have exit and getchar, lets provide those.
2019-10-15 08:33:05 +00:00
Justin Hibbits
dbef5f7155 loader/powerpc64: Include generic PVR values in CAS architecture list
Add generic PVR values for PowerISA 2.07 and 3.00.  This allows booting pseries
in QEMU with compatibilty mode enabled.

Submitted by:	Shawn Anastasio <shawn@anastas.io>
2019-10-08 02:36:53 +00:00
Kyle Evans
605261992c Revert r352557: powerpc/loader: Install ubldr without stripping
This was committed due to what was later diagnosed as an msdosfs bug
preventing in-place strip. This bug was fixed in r352564, and we agreed to
keep the workaround in for a bit to allow the driver fix a suitable amount
of propagation time for folks building/installing powerpc/ubldr, seeing as
how we were not in any hurry to revert.
2019-10-07 03:28:11 +00:00
Justin Hibbits
cd51f7df9c loader/powerpc64: Fix HV check for CAS usage
Logic was backwards.  The function returns true if it *is* running as a
hypervisor, whereas we want to only call the CAS utility if we're running as a
guest.

Reported by:	Shawn Anastasio <shawn@anastas.io>
2019-10-07 03:05:32 +00:00
Toomas Soome
03c9cdf71d loader.efi: for text mode, use STM to scroll the whole screen
Since local UEFI console is implemented on top of framebuffer,
we need to avoid redrawing the whole screen ourselves, but let
Simple Text Mode to do the scroll for us.
2019-10-06 18:38:58 +00:00
Kyle Evans
e12ff89136 Further normalize copyright notices
- s/C/c/ where I've been inconsistent about it
- +SPDX tags
- Remove "All rights reserved" where possible

Requested by:	rgrimes (all rights reserved)
2019-09-26 16:19:22 +00:00
Toomas Soome
8074c5cc86 loader: fix indentation in efi_console and vidconsole
Remove extra tab.

Reported by:	yuripv
2019-09-25 07:36:35 +00:00
Toomas Soome
233ab015c0 loader: add teken.fg_color and teken.bg_color variables
Add settable variables to control teken default color attributes.
The supported colors are 0-7 or basic color names:
black, red, green, brown, blue, magenta, cyan, white.

The current implementation does add some duplication which will be addressed
later.
2019-09-25 07:09:25 +00:00
Toomas Soome
6dd078df19 loader_lua: lua color changes should end with reset
The color change should have reset sequence, not switch to white.
2019-09-22 17:39:20 +00:00
Toomas Soome
2de5a21edc loader_4th: menu items need to reset color attribute, not switch to white
Forth menu kernel and BE entries, instead of resetting the color attribute,
are switching to white color.
2019-09-22 16:10:25 +00:00
Kyle Evans
bb7b569d36 loader: Respect loader_color=YES for serial consoles
It's not uncommon these days for the terminals attached to serial consoles
to support ANSI escape sequences. However, we assume escape sequences may
break some serial consoles and default to not using them when boot_serial or
boot_multicons (or if console contains "comconsole" in the forth loader) for
broader compatibility. We also have loader_color which can be explicitly set
to "NO" to disable the use of ANSI escape sequences.

The problem is that loader_color=YES gets ignored when boot_serial=YES or
boot_multicons=YES (or when console contains "comconsole" in the forth
loader).

To fix, the existing default behavior remains unchanged when loader_color is
unset, loader_color=NO explicitly disables the use of ANSI escape sequences
still, and the change is that loader_color=YES can now be used to explicitly
allow ANSI escapes when a serial console is enabled.

Submitted by:	Ryan Moeller <ryan@ixsystems.com>
Reviewed by:	tsoome (forth), kevans (lua)
MFC after:	1 week
Sponsored by:	iXsystems, Inc. (Ryan)
Differential Revision:	https://reviews.freebsd.org/D21732
2019-09-20 19:43:40 +00:00
Justin Hibbits
39404490b7 powerpc/loader: Install ubldr without stripping
Summary:
Install's strip capability, by way of strip(1), doesn't seem to work
correctly on msdosfs, and instead ends up truncating the resulting
binary to 0-length.  As a workaround, don't strip ubldr(8).  This
fixes installworld on Book-E ubldr-based platforms, which prior to this
would need to manually install ubldr separately after installworld, in
order to have a functional ubldr.

The same thing could be done on PowerNV platforms that use msdosfs /boot
volumes, since loader and loader.kboot, etc, all get truncated to 0 on
install.  However, PowerNV does not use loader, instead loading from
petitboot, so it's not really necessary at this time.

Reviewed by:	kevans
Differential Revision: https://reviews.freebsd.org/D21725
2019-09-20 13:35:28 +00:00
Toomas Soome
23883413d4 loader: fix typo in zalloc. 2019-09-20 05:22:34 +00:00
Kyle Evans
8b2195605b mips: ubldr: use truncated load address for mips32
BFD appears to silently truncate 0xffffffff80800000 when it processes the
ldscript for 32-bit mips, but LLD chokes on it as the linker script tries to
place elements above 32-bit range. It's unclear to me if silent truncation
is kosher or not and whether this patch is really what we want to do, but it
is one approach at least.

Reviewed by:	imp, mizhka
Differential Revision:	https://reviews.freebsd.org/D21487
2019-09-18 01:33:17 +00:00
Toomas Soome
68861a62f5 loader: provide u> and xemit words if needed
We have external interpreter (userboot.so) which may be lagging behind
with updates and may be missing u> xemit words.
2019-09-17 18:05:33 +00:00
Toomas Soome
d6b090d1d4 loader: revert r352421
As insisted by kib, malloc(0) is quite legal.
2019-09-17 16:16:46 +00:00
Toomas Soome
840fa0f86d loader.efi: efipart needs to use ioalign
UEFI specification 2.7A, EFI_BLOCK_IO_PROTOCOL, page 566.

The ioalign property does define the alignment of data buffer.

If the alignment is required and our buffer is not aligned, or if
the data buffer is not multiple of Blocksize, we need to use bounce buffer
to perform the block IO. This is much like with BIOS version, except
there the INT13 needs buffer to be located in low memory.

Additionally, we need to handle disk writes properly.
2019-09-17 13:50:25 +00:00
Toomas Soome
11db1a1654 loader: add memalign() to libsa
Implement memalign(size_t alignment, size_t size) to allocate aligned memory.
2019-09-17 13:15:27 +00:00
Toomas Soome
62ea4c11d5 loader: stand.h should define reallocf as Reallocf
Use the same approach as other zalloc functions.
2019-09-17 13:07:02 +00:00
Toomas Soome
e57c0c2afb loader: cstyle cleanup libsa zalloc sources
Clean up libstand zalloc* sources. Note that it is not 100% whitespace cleanup.
I also reduced block in znalloc and zfree as those were obvious simplifications
and did help to save one level of indent.
2019-09-17 11:35:53 +00:00
Toomas Soome
144c4ca039 loader: factor out guard location setup from Realloc
To simplify and make it easier to read, use ga_Bytes field from guard
structure.
2019-09-17 09:47:35 +00:00
Toomas Soome
41e2c61669 loader: Malloc(0) should return NULL.
We really should not allocate anything with size 0.
2019-09-16 20:28:08 +00:00
Toomas Soome
1781ad707e loader_4th: scan_buffer can leave empty string on stack
When the file processing is done, we will have string with lenght 0 in stack and we will attempt to
allocate 0 bytes.
2019-09-16 20:26:53 +00:00
Kyle Evans
af876563d1 lualoader: Add reload-conf loader command
This command will trigger a reload of the configuration from disk. This is
useful if you've changed currdev from recovery media to local disk as much
as I have over the past ~2 hours and are tired of the extra keystrokes.

This is really just a glorified shortcut, but reload-conf is likely easier
to remember for other people and does save some keystrokes when reloading
the configuration. It is also resilient to the underlying config method
changing interface, but this is unlikely to happen.

MFC after:	1 week
2019-09-14 03:38:18 +00:00
Toomas Soome
e7da26b6ca loader: vidconsole should set LINES and COLUMNS
Set LINES and COLUMNS based on terminal dimensions.
2019-09-10 21:53:42 +00:00
Kyle Evans
90a2541772 lualoader: Revert to ASCII menu frame for serial console
The box drawing characters we use aren't necessarily safe with a serial
console; for instance, in the report by npn@, these were causing his xterm
to send back a sequence that lua picked up as input and halted the boot.
This is less than ideal.

Fallback to ASCII frames for console with 'comconsole' in it.  This is a
partial revert r338108 by imp@ -- instead of removing the menu entirely and
disabling color/cursor sequences, just reverting the default frame to ASCII
is enough to not break in this setup.

Reported by:	npn
Triaged and recommended by:	tsoome
2019-09-10 21:30:38 +00:00
Toomas Soome
094b40659f loader: --gc-sections needs sections to work with
--gc-sections is not really useful unless we generate sections with
-ffunction-sections -fdata-sections

While there, i386/loader would win from --gc-sections too.
2019-09-08 19:39:45 +00:00
Toomas Soome
21388f5cf8 loader.efi: UEFI text mode background colors are only using 3 bits
Need to mask background colors to pass allowed value.
2019-09-06 19:30:23 +00:00
Justin Hibbits
2f6823d4c1 Loader: Add load offset to powerpc kernel entry point
Summary:
There is logic in ELF loadimage() to relocate kernels, but currently
only type ET_EXEC.  PowerPC kernels are ET_DYN, and can be relocated anywhere.
Add the load offset to kernel entry points on this platform.

Reviewed by:	imp, ian
Differential Revision:	https://reviews.freebsd.org/D21286
2019-09-06 02:28:03 +00:00
Toomas Soome
56758831fe loader: use teken teminal emulator for x86 and uefi
Replace mini cons25 emulator with teken, this does enable us proper console
terminal for loader and will make it possible to implement different
back end callbacks to draw to screen.

At this time we still only "draw" in text mode.
2019-09-05 22:15:50 +00:00
Toomas Soome
938cae327c ficl: add xemit word
While emit will output one byte on screen, the xemit will output xchar.

See: http://forth-standard.org/standard/xchar/XEMIT
2019-09-05 15:06:30 +00:00
Toomas Soome
0bd5d36798 ficl: add uIsGreater word
For some reason we have u< but not u>, fix it.
2019-09-05 09:04:48 +00:00
Rebecca Cran
9a2b7c5fce The efifat files are no longer used: remove the code to build them
Reviewed by:	imp, tsoome, emaste
Differential Revision:	https://reviews.freebsd.org/D20562
2019-09-04 20:55:48 +00:00
Toomas Soome
05b24e8617 loader.efi: use and prefer coninex interface
Add support for EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL.
2019-09-02 11:04:17 +00:00
Toomas Soome
591d5f0ef5 loader.efi: some systems do not translate scan code 0x8 to backspace
Add scancode translation for backspace.
2019-09-02 10:45:10 +00:00
Brandon Bergren
9ae631858e Move CAS check in powerpc64 ofw loader until after the PVR check.
This unbreaks using the powerpc64 loader on a 32-bit processor.

Approved by: jhibbits (mentor)
Differential Revision: https://reviews.freebsd.org/D21297
2019-09-01 18:26:21 +00:00
Toomas Soome
fd7e6079bc loader.efi: use shift 16 in efipart as it is max ashift supported by zfs 2019-08-31 06:24:09 +00:00
Toomas Soome
9f7b00f230 qemu-system-aarch64 does list block device with very large block size
Also insert Vendor device as "parent" disk (found in
qemu-system-aarch64 -cpu cortex-a57).

This does fix lsdev in loader.efi on this platform.
2019-08-30 20:54:30 +00:00
Kyle Evans
e1aa7047af stand: boot2: fix amd64-xtoolchain-gcc build
-Wno-missing-declarations is the GCC equivalent of
-Wno-missing-prototypes... this was overlooked in r351135.

MFC after:	3 days
X-MFC-With:	r351135
2019-08-23 01:16:12 +00:00
Kyle Evans
da8147c3c5 libsa: mips: fix typo that had slipped into the diff on local machine
MFC after:	1 week
X-MFC-With:	r351408
2019-08-22 21:49:13 +00:00
Kyle Evans
428925b5f2 libsa: mips: use _JB_* from machine/asm.h, remove regnum dep
This brings the libsa/mips _setjmp implementation closer to parity with the
libc version.

Reviewed by:	imp, jhb
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D21330
2019-08-22 21:42:11 +00:00
Toomas Soome
a15a23234d loader.efi: efipart should be more careful about constructing block device lists
The cd handles should be collected as list of partitions. Some systems also
provide base name for block device (like PciRoot(0x0)/Pci(0x5,0x0)), we need
to be careful about those.

To make out life a bit easier, we prepare not just an array of handles, but we
allocate pdinfo struct for each handle and devicepath, then we can simplify
our work to sort the devices.

Differential Revision:	https://reviews.freebsd.org/D21187
2019-08-20 19:31:11 +00:00
Tom Jones
ec18da7c04 Reduce size of EFI_STAGING_SIZE to 32 on arm
Reduce the size of the EFI_STAGING area we allocate on arm to 32. On arm SBC
such as the NanoPi-NEOLTS the staging area allocation will fail on the 256MB
model with a staging size of 64.

Reviewed by:    bcran, manu
Approved by:    bz (mentor)
MFC after:      2 weeks
Differential Revision: https://reviews.freebsd.org/D21016
2019-08-17 06:47:43 +00:00
Kyle Evans
80746f9f83 stand: gptboot: fix build with xtoolchain-llvm90
ufsread.c grows a dependency on __ashldi3 with llvm90. For gptboot, just
start pulling in ashldi3.c ashrdi3.c lshrdi3.c into libsa for all archs as
the number of archs requiring one or more of them keeps growing. qdivrem.c
and quad.h can be trivially kicked out of libsa if we start pulling these
from compiler-rt as qdivrem was only used to implement umoddi3, divdi3,
moddi3 (also in qdivrem.c).

Reviewed by:	imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D21291
2019-08-16 20:09:20 +00:00
Kyle Evans
37ac567ea7 stand: boot2: fix build with xtoolchain-llvm90
ufsread.c grows a dependency on __ashldi3 with llvm90. Grab ashldi3.c out of
compiler-rt rather than trying to link against libsa (for now).
-Wno-missing-prototypes is necessary to compile ashldi3.c standalone.

Reviewed by:	imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D21291
2019-08-16 20:07:43 +00:00
Kyle Evans
80335781ad stand: push LIBC_SRC up into defs.mk
Other parts of stand/ that don't use libsa will need to grab bits from libc
shortly. Push LIBC_SRC up to defs.mk in advance of this so that they can use
it, and rename it to LIBCSRC to match the convention of the rest of the *SRC
variables in this file.

Reviewed by:	imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D21282
2019-08-16 13:22:57 +00:00
Ed Maste
0a062e5ff6 gptzfsboot: remove CLANG_NO_IAS
Many components under stand/ had CLANG_NO_IAS added when Clang's
Integrated Assembler did not handle .codeNN directives.  Clang gained
support quite some time ago, so we can build stand/ with IAS.

In some cases there were small differences in generated object output.
In the case of gptzfsboot however using GNU as or Clang IAS to assemble
gptldr.S resulted in identical final gptzfsboot binary output.

Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D11115
2019-08-15 18:43:01 +00:00
Ed Maste
aa2dd958b4 stand: remove CLANG_NO_IAS from pxeldr
Many components under stand/ had CLANG_NO_IAS added when Clang's
Integrated Assembler (IAS) did not handle .codeNN directives.  Clang
gained support quite some time ago, and we can now build stand/ with
IAS.  In most cases IAS- and GNU as-assembled boot components were
identical, and CLANG_NO_IAS was already removed from other components.

Clang IAS produces different output for some components, including
pxeldr, so CLANG_NO_IAS was not previously removed for those.

In the case of pxeldr the difference is that IAS adds a size override
prefix (67h) to three instructions to specify a 32-bit address, even
though the two high bytes are zero and the address fits in 16 bits.
this wastes three bytes per instruction and causes some additional nop
npadding to be required elsewhere in the object, but pxeboot is not
size-constrained so it doesn't matter.

Sponsored by:	The FreeBSD Foundation
2019-08-15 17:59:22 +00:00
Ed Maste
1596e9a43c stand: remove CLANG_NO_IAS from cdboot
Many components under stand/ had CLANG_NO_IAS added when Clang's
Integrated Assembler (IAS) did not handle .codeNN directives.  Clang
gained support quite some time ago, and we can now build stand/ with
IAS.  In most cases IAS- and GNU as-assembled boot components were
identical, and CLANG_NO_IAS was already removed from other components.

Clang IAS produces different output for some components, including
cdboot, so CLANG_NO_IAS was not previously removed for those.

In the case of cdboot the difference is that IAS adds a size override
prefix (67h) to many instructions to specify a 32-bit address, even
though the two high bytes are zero.  This wastes three bytes per
instance, but as cdboot is not size-constrained it doesn't matter.
Padding is also different in one case; Clang used two one-byte nops
while GNU as used a single two-byte xchg %eax, %eax.  In any case, there
is no functional change.

Sponsored by:   The FreeBSD Foundation
2019-08-15 17:32:39 +00:00
Kyle Evans
a78c1027d7 Revert r351078, r351085: stand/quad.h eviction
It did not go well; further examination is required...
2019-08-15 17:15:32 +00:00
Kyle Evans
7ddaee2559 stand: kick out quad.h
Use quad.h from libc instead for the time being. This reduces the number of
nearly-identical-quad.h we have in tree to two with only minor changes.

Prototypes for some *sh*di3 have been added to match the copy in libkern.
The differences between the two are likely few enough that they can perhaps
be merged with little additional effort to bring us down to 1.

MFC after:	3 days
2019-08-15 15:47:48 +00:00
Ed Maste
3a6c85abcb stand: remove CLANG_NO_IAS from boot2
Many components under stand/ had CLANG_NO_IAS added when Clang's
Integrated Assembler (IAS) did not handle .codeNN directives.  Clang
gained support quite some time ago, and we can now build stand/ with
IAS.  In most cases IAS- and GNU as-assembled boot components were
identical, and CLANG_NO_IAS was already removed from other components.

Clang IAS produces different output for some components, including
boot2, so CLANG_NO_IAS was not previously removed for those.

In the case of boot2 the difference is that IAS produces a larger
encoding for one instruction (the testb at the beginning of read).

GNU as produces:

    2e    f6 06 b0 08       80

while IAS includes an address size override prefix (67) and produces:

    2e 67 f6 05 b3 08 00 00 80

This results in three fewer NOPs elsewhere in boot2 but no functional
change, so switch to IAS for boot2.

(We can separately pursue improved 16-bit IAS support with the LLVM
developers.)

Sponsored by:	The FreeBSD Foundation
2019-08-15 14:54:18 +00:00
Toomas Soome
6e5555adb1 loader: add error check for vdev_indirect calls
We can error out due to memory allocation errors, we can not recover from
those and need to get out.
2019-08-09 19:09:05 +00:00
Toomas Soome
b1b9326846 loader: support com.delphix:removing
We should support removing vdev from boot pool. Update loader zfs reader
to support com.delphix:removing.

Reviewed by:	allanjude
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D18901
2019-08-08 18:08:13 +00:00
Marcin Wojtas
435672e322 Verify files loaded in chain command.
The chain command can be used to chain load another binary.
If veriexec is enabled we should verify it first.
Note that on EFI systems the verification was already done
through firmware, assuming that Secure Boot was enabled there.

Submitted by: Kornel Duleba <mindal@semihalf.com>
Reviewed by: sjg
MFC after: 1 week
Obtained from: Semihalf
Differential Revision: https://reviews.freebsd.org/D20952
2019-08-08 17:03:30 +00:00
Toomas Soome
9cb069b552 loader.efi: efilib.h and libefi.c were left out of 350654
And this is second followup for 350654
2019-08-06 20:13:28 +00:00
Toomas Soome
cefffc0b45 loader.efi: boot1.c was left out of 350654
Followup for 350654.
2019-08-06 20:08:01 +00:00
Toomas Soome
110d56cbf4 loader.efi: replace HandleProtocol() with OpenProtocol()
The HandleProtocol() is deprecated interface and we should use OpenProtocol()
instead. Moreover, in some firmware implementation(s), the HandleProtocol()
does return device path using static storage, so we can not keep the value
returned there. With same firmware, the OpenProtocol() does return data we
do not need to clone.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D21162
2019-08-06 19:27:27 +00:00
Leandro Lupori
83e356c3c9 [PPC64] Implement CAS
Guest PPC OSs running under a hypervisor may communicate the features they
support, in order for the hypervisor to expose a virtualized machine in the way
the client (guest OS) expects (see LoPAPR 1.1 - B.6.2.3).

This is done by calling the "/ibm,client-architecture-support" (CAS) method,
informing supported features in option vectors.  Until now, FreeBSD wasn't
using CAS, but instead relied on hypervisor/QEMU's defaults.

The problem is that, without CAS, it is very inconvenient to run POWER9 VMs on
a POWER9 host running with radix enabled.  This happens because, in this case,
the QEMU default is to present the guest OS a dual MMU (HPT/RPT), instead of
presenting a regular HPT MMU, as FreeBSD expects, resulting in an early panic.
The known workarounds required either changing the host to disable radix or
passing a flag to QEMU to run in a POWER8 compatible mode.

With CAS, FreeBSD is now able to communicate that it wants an HPT MMU,
independent of the host setup, which now makes FreeBSD work on POWER9/pseries,
with KVM enabled and without hugepages (support added in a previous commit).

As CAS is invoked through OpenFirmware's call-method interface, it needs to be
performed early, when OpenFirmware is still operational. Besides, now that FDT
is the default way to inspect the device tree on PPC, OFW call-method feature
will be unavailable by default, when control is passed to the kernel. Because
of this, the call to CAS is being performed at the loader, instead of at the
kernel.

To avoid regressions with old platforms, this change uses CAS only on
POWER8/POWER9.

Reviewed by:	jhibbits
Differential Revision:	https://reviews.freebsd.org/D20827
2019-07-31 20:31:36 +00:00
Ruslan Bukin
be4890f75e Fix EFI loader build when LOADER_NET_SUPPORT=no.
Sponsored by:	DARPA, AFRL
2019-07-30 14:54:18 +00:00
Simon J. Gerraty
bbac74ca3c loader: ignore some variable settings if input unverified
libsecureboot can tell us if the most recent file opened was
verfied or not.
If it's state is VE_UNVERIFIED_OK, skip if variable
matches one of the restricted prefixes.

Reviewed by:	stevek
MFC after:	1 week
Sponsored by:	Juniper Networks
Differential Revision:	https://reviews.freebsd.org//D20909
2019-07-17 23:33:14 +00:00
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
94e8f7c65f Increase EFI_STAGING_SIZE to 100MB on x64
To avoid failures when the large 18MB nvidia.ko module is being loaded,
increase EFI_STAGING_SIZE from 64MB to 100MB on x64 systems.
Leave the other platforms at 64MB.
2019-06-27 22:06:41 +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
519346ce8c Disconnect EFI HTTP support
The EFI HTTP code has been causing boot failures for people, so disable it
while a fix is being worked on.
2019-06-25 21:26:57 +00:00
Warner Losh
f5a95d9a07 Remove NAND and NANDFS support
NANDFS has been broken for years. Remove it. The NAND drivers that
remain are for ancient parts that are no longer relevant. They are
polled, have terrible performance and just for ancient arm
hardware. NAND parts have evolved significantly from this early work
and little to none of it would be relevant should someone need to
update to support raw nand. This code has been off by default for
years and has violated the vnode protocol leading to panics since it
was committed.

Numerous posts to arch@ and other locations have found no actual users
for this software.

Relnotes:	Yes
No Objection From: arch@
Differential Revision: https://reviews.freebsd.org/D20745
2019-06-25 04:50:09 +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
Warner Losh
ec9abc1843 Move to using a common kernel path between the boot / laoder bits and
the kernel.
2019-06-24 20:34:53 +00:00
Matt Macy
6459a61ea7 Tell loader to ignore newer features enabled on the root pool.
There are many new features in ZoF. Most, if not all, do not effect read only usage.
Encryption in particular is enabled at the pool level but used at the dataset level.
The loader obviously will not be able to boot if the boot dataset is encrypted, but
should not care if some other dataset in the root pool is encrypted.

Reviewed by:	allanjude
MFC after:	1 week
2019-06-19 21:10:13 +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
Leandro Lupori
68ed5ad2d5 [PPC] Fix loader input with newer QEMU versions
At least since version 4.0.0, QEMU became bug-compatible with PowerVM's
vty, by inserting a \0 after every \r. As this confuses loader's
interpreter and as a \0 coming from the console doesn't seem reasonable,
it's now being filtered at OFW console input.

Reviewed by:	jhibbits
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D20676
2019-06-19 11:37:43 +00:00
Xin LI
f89d207279 Separate kernel crc32() implementation to its own header (gsb_crc32.h) and
rename the source to gsb_crc32.c.

This is a prerequisite of unifying kernel zlib instances.

PR:		229763
Submitted by:	Yoshihiro Ota <ota at j.email.ne.jp>
Differential Revision:	https://reviews.freebsd.org/D20193
2019-06-17 19:49:08 +00:00
Li-Wen Hsu
3aa9258286 Fix gcc build by removing redeclaration
Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D20622
2019-06-13 03:48:36 +00:00
Warner Losh
5698b5c2b7 Add stuff to disable warning for %S
Add the customary warnings to disable format checking on armv7. Code
move to new files, and the unconditional setting of WARNS to 6
provoked it on tinerbox...
2019-06-08 19:58:58 +00:00
Warner Losh
f61f5a0b2d Create gptboot.efi
This is a primary boot loader that is intended to implement the
gptboot partition selection algorithm just like we did for BIOS
booting. While the preferred method for UEFI is to use the UEFI Boot
Manager protocol, there are situations where that can't be done: some
BIOS makers interfere with the protocol in unhelpful ways, there's a
new standard for a zero variable write from the client OS, and finally
for USB drives that might be mobile between systems with multiple
partitions there needs to be a media stable way to select.

Reviewed by: tsoome, bcran
Differential Revision: https://reviews.freebsd.org/D20547
2019-06-08 19:02:17 +00:00
Warner Losh
f46eb75217 Break out the disk selection protocol from the rest of boot1.
Segregate the disk probing and selection protocol from the rest of the
boot loader.

Reviewed by: tsoome, bcran
Differential Revision: https://reviews.freebsd.org/D20547
2019-06-08 18:59:50 +00:00
Warner Losh
31927bd4ad Rework the reporting of the priority.
Simplify the code a bit and rework how we report the results
of the probing.

Reviewed by: tsoome@
Differential Revision: https://reviews.freebsd.org/D20537
2019-06-07 02:05:22 +00:00
Warner Losh
52a662514d Remove left-over status variables 2019-06-07 00:02:02 +00:00
Warner Losh
55de7f3406 Fix when NOFAT is defined
We need to add the *efi file to the list of things that get built,
even if we're not creating the efifat stuff.
2019-06-06 22:56:55 +00:00
Warner Losh
fef7bfef6f Use simple malloc/free instead of dropping down to the UEFI
BootServices AllocatePool/FreePool calls. They are simpler to use and
result in the same thing happening.

Reviewed by: tsoome@
Differential Revision: https://reviews.freebsd.org/D20540
2019-06-06 21:04:37 +00:00
Toomas Soome
ed29b75ca3 loader: disk_open() should honor D_PARTNONE
The D_PARTNONE is documented to make it possible to open raw MBR
partition, but the current disk_open() does not really implement this
statement.

The current code is checking partition against -1 (D_PARTNONE) but does
attempt to open partition table in case we do have FreeBSD MBR partition type.
Instead, we should check -2 (D_PARTWILD).

In case we do have MBR + BSD label, this code is only working because
by default, the first BSD partiton is created starting with relative sector
0, and we can still access the BSD table from that MBR slice.

Reviewed by:	imp
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D20501
2019-06-06 16:27:05 +00:00
Warner Losh
175e3aa56e Don't make the efifat thing if NOFAT is defined. 2019-06-06 03:07:10 +00:00
Warner Losh
de357a736d Eliminate unused uuid parameters from gptread and gptread_table. We
only need it for the gptfind() function, where it's used.
2019-06-05 02:34:58 +00:00
Warner Losh
92fb04661f ufs_module.c can't currently be compiled with -Wcast-align, but the
code is safe enough. Turn off the warning for now until I can find the
right construct to silence it in the code.
2019-06-05 00:08:30 +00:00
Warner Losh
cf461fdb1d Don't shadow a global zfsmount variable. 2019-06-05 00:04:21 +00:00
Warner Losh
b5f3ad3ad1 Use newly minted efi_devpath_same_disk() instead of
efi_devpath_match(). This fixes a regression in r347193.

Reported by: Tomoaki AOKI
Differential Revision: https://reviews.freebsd.org/D20513
2019-06-04 18:36:12 +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
Warner Losh
63acab6a5b [zfsboot] Fix boot env back compat (#190)
* Fix boot env back compat

zfsboot must try zfsloader before loader in order to remain compatible
with boot environments created prior to zfs functionality being rolled
into loader proper.

* Improve comments in zfsboot

Explain the significance of the load path order, and put the comment
about looping through the paths in the appropriate scope.

Obtained From:  TrueNAS commit 4c60c62fcf0b6b6eac98ee8d46e7bbea64bc86f5
Submitted by: Ryan Moeller <ryan@freqlabs.com>
2019-06-03 19:10:46 +00:00
Rebecca Cran
ea13a93166 Fix comment parsing in interp_simple.c
loader.rc has comment lines without a trailing space, which get
interpreted as commands. Avoid this by only matching against the
backslash character.

Reviewed by:	imp, tsoome
Differential Revision:	https://reviews.freebsd.org/D20491
2019-06-01 19:47:15 +00:00
Kyle Evans
9892cc9ad4 stand: zfs: Free bouncebuf on error path in vdev_read
r344226 inadvertently added this path in which we return from failure on an
lseek and do not free bouncebuf on the way out.

MFC after:	3 days
2019-05-31 17:44:22 +00:00
Xin LI
12d62cc2d7 Unexpand be32dec().
MFC after:	2 weeks
2019-05-30 02:23:57 +00:00
Toomas Soome
93a2d4c92f loader: malloc+memset is calloc in spa_create
Replace malloc + memset pair with calloc.
2019-05-29 07:33:51 +00:00
Toomas Soome
f28f385b9c boot1.efi should also provide Calloc
boot1.efi does provide Malloc and Free, we also need Calloc.
2019-05-29 07:32:43 +00:00
Toomas Soome
51e5c6b89e loader: zfs_alloc and zfs_free should use panic
The zfs alloc and free code print out the error and get stuck in infinite loop; use panic() instead.
2019-05-29 07:24:10 +00:00
Simon J. Gerraty
2ef9ff7dd3 ficl pfopen: verify file
If the file is verified - do not allow write
otherwise do not allow read.

Add O_ACCMODE to stand.h

Reviewed by:	stevek, mindal_semihalf.com
MFC after:	3 days
Sponsored by:	Juniper Networks
Differential Revision:	https://reviews.freebsd.org/D20387
2019-05-24 19:43:38 +00:00
Xin LI
5e86bd6073 Remove kgzip and kgzldr.
PR:		183666, 229763
Submitted by:	Yoshihiro Ota <ota at j.email.ne.jp>
Differential Revision:	https://reviews.freebsd.org/D20248
2019-05-24 05:34:21 +00:00
Jung-uk Kim
540a97e342 Initialize a variable to fix build with GCC. 2019-05-23 22:49:03 +00:00
Jung-uk Kim
fdb9b7af98 Remove yet another unused variable. 2019-05-23 22:01:05 +00:00
Emmanuel Vadot
8a2ad0aec8 loader: Remove unused variable
Reported by:	lwshu, ci@
2019-05-23 20:04:22 +00:00
Emmanuel Vadot
32199fb311 loader: Add pnp functions for autoloading modules based on linker.hints
This adds some new commands to loader :

- pnpmatch
   This takes a pnpinfo string as argument and tries to find a kernel module
   associated with it. -v and -d option are available and are the same as in
   devmatch (v is verbose, d dumps the hints).
- pnpload
   This takes a pnpinfo string as argument and tries to load a kernel module
   associated with it.
- pnpautoload
   This will attempt to load every kernel module for each buses. Each buses are
   probed, the probe function will generate pnpinfo string and load kernel module
   associated with it if it exists.

Only simplebus for FDT system is implemented for now.
Since we need the dtb and overlays to be applied before searching the tree
fdt_devmatch_next will load and apply the dtb + overlays.

All the pnp parsing code comes from devmatch and is the same at 99%.

Reviewed by:	imp, kevans
Differential Revision:	https://reviews.freebsd.org/D19498
2019-05-23 19:26:50 +00:00
Justin Hibbits
4d6fa83c73 stand: TARGET_ARCH is spelled MACHINE_ARCH in Makefiles
Reported by:	imp
2019-05-21 03:05:24 +00:00
Justin Hibbits
b2775610c0 stand/powerpc: Only build loader.kboot for powerpc64
kboot is only made for powerpc64 systems, not 32-bit systems.

This unbreaks the build for powerpcspe.

Reported by:	ngie
2019-05-21 01:42:57 +00:00
Enji Cooper
637b653270 Unbreak the build when ELF_VERBOSE is defined after r348005
This change properly terminates the formatting string quote modification done
in r348005, which is triggered when `ELF_VERBOSE` is defined.

MFC with:	r348005
Reported by:	ci (amd64, gcc)
2019-05-21 00:46:47 +00:00
Leandro Lupori
ff7449d6f5 [PowerPC64] stand: fix build using clang 8 as compiler
This change fixes "stand" build issues when using clang 8
as compiler.

Submitted by:   alfredo.junior_eldorado.org.br
Reviewed by:    jhibbits
Differential Revision: https://reviews.freebsd.org/D20026
2019-05-20 19:21:35 +00:00
Toomas Soome
b17868a211 loader: fix memory handling errors in module.c
file_loadraw():
check for file_alloc() and strdup() results.
we leak 'name'.

mod_load() does leak 'filename'.

mod_loadkld() does not need to check fp, file_discard() does check.
2019-05-13 22:17:11 +00:00
Toomas Soome
82c29d4fde loader: use DPRINTF in biosdisk.c and define safe DPRINTF
r345066 did miss biosdisk.c.

Also define DPRINTF as ((void)0) for case we do not want debug printouts.

MFC after:	1 week
2019-05-09 13:12:43 +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
41a1c642e4 loader: ptable_print() needs two tabs sometimes
Since the partition/slice names do vary in length, check the length
of the fixed part of the line against 3 * 8, if the lenth is less than
3 tab stops, print out extra tab.

use snprintf() instead of sprintf.
2019-05-09 11:04:10 +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
Xin LI
c9083b850a Move contrib/zlib to sys/contrib/zlib so that we can use it in kernel.
This is a prerequisite of unifying kernel zlib instances.

Submitted by:	Yoshihiro Ota <ota at j.email.ne.jp>
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D20191
2019-05-08 08:43:15 +00:00
Toomas Soome
726f09bc6a command_bcache() does not use argv
Therefore mark argv __unused.
2019-05-07 10:01:45 +00:00
Toomas Soome
e3e96239cd loader: bcache code does not need to check argument for free() 2019-05-07 08:14:30 +00:00
Toomas Soome
74772ef1ae loader: use safer DPRINTF body for non-debug case 2019-05-07 07:46:40 +00:00
Warner Losh
141b1c328d Simplify boot1 allocation of handles.
There's no need to pre-malloc the number of handles. Instead call
LocateHandles twice, once to get the size, and once to get the
data.
2019-05-06 19:35:30 +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
f28eb4856d We only ever need one devinfo per handle. So allocate it outside of
looping over the filesystem modules rather than doing a malloc + free
each time through the loop. In addition, nothing changes from loop to
loop, so setup the new devinfo outside the loop as well.
2019-05-06 18:39:22 +00:00
Warner Losh
4cf36aa101 Reach over and pull in devpath.c from libefi
This allows us to remove three nearly identical functions because the
differences don't matter, and the size difference is trivial.
2019-05-06 18:38:46 +00:00
Toomas Soome
15f5e297d0 loader: validate sectorsize argument in disk_open()
The bug and patch is reported against 11.2, but it is good idea to have
the check in place for all versions.

PR:		236585
Submitted by:	john@feith.com
Reported by:	john@feith.com
MFC after:	1 day
2019-05-05 06:38:47 +00:00
Warner Losh
1f6ba72eb4 Use SRC+= rather than SRC=
To allow boot1/Makefile to be included, use SRC+= rathern than SRC=
so the including Makefile can add additional sources to the build.
2019-05-03 21:13:09 +00:00
Warner Losh
ce2403e672 Substitute boot1 with ${BOOT1}
Allow for other names to be built, so parameterize this makefile to
avoid hard coding boot1.
2019-05-03 21:13:04 +00:00
Warner Losh
6f21634d55 When we can't get memory, trying again right away is going to
fail. Rather than print N failure messages, bail on the first one.
2019-05-03 21:09:25 +00:00
Warner Losh
aacd73b871 Remove stray '*'
We're storing an EFI_HANDLE, not an pointer to a handle. Since
EFI_HANDLE is a void * anyway, this has little practical effect since
the conversion to / from void * and void ** is silent.
2019-05-03 21:06:34 +00:00
Kyle Evans
83475ff137 stand: correct mis-merge from r346879
Small mis-merge from multiple WIP resulted in block io media handles getting
double-initialized. This resulted in some installations oddly landing at the
mountroot prompt.

Reported by:	ler
Reviewed by:	imp
2019-05-02 17:01:13 +00:00
Warner Losh
fa4b817970 Use D_PARTISGPT rather than bare 255
These three cases dovetail with other places in the code where we use
or set D_PARTISGPT when we mean that the partitioning scheme is
GPT. Use this #define to make the code easier to undertand.

Reviewed by: tsoome@
Differential Revision: https://reviews.freebsd.org/D20122
2019-05-01 05:42:13 +00:00
Ian Lepore
ba761eace4 Add a paragraph that mentions gptboot having an interactive mode, and
direct the user to the boot(8) manpage, which provides the details on that.
2019-04-30 18:48:20 +00:00
Toomas Soome
3a1f80e2d7 zfsboot: to detect disk size, use GPT information first
If we do have GPT on disk, read the disk size from it and do not
call int13.

Since int13 does report bogus informatiopn too often, rather trust the
partition table. We are using the same strategy with loader.

MFC after:	1 month
2019-04-30 17:45:22 +00:00
Warner Losh
4ecd512f75 Implement uefi_ignore_boot_mgr env variable.
When set, we ignore all the hints that the UEFI boot manager has set
for us. We also always fail back to the OK prompt when we can't find
the right thing to boot rather than failing back to the UEFI boot
manager. This has the side effect of also expanding the cases where we
fail back to the OK prompt to include when we're booted under UEFI,
but UEFI::BootCurrent isn't set in the environment and we can't find a
proper place to boot from.

Reviewed by: bcran
Differential Revision: https://reviews.freebsd.org/D20016
2019-04-29 05:02:54 +00:00
Warner Losh
bc6053b345 Implement uefi_rootdev
If uefi_rootdev is set in the environment, then treat it like a device
path. Convert the string to a device path and see if we can find a
device that matches. If so, use that device at our root dev no matter
what. If it's bad in any way, the boot will fail.

Reviewed by: bcran
Differential Revision: https://reviews.freebsd.org/D20016
2019-04-29 05:02:50 +00:00
Warner Losh
8ac2d6f5d6 Read in and parse /efi/freebsd/loader.env from the boot device's
partition as if it were on the command line.

Fetch FreeBSD-LoaderEnv UEFI enviornment variable. If set, read in
loader environment variables from it. Otherwise read in
/efi/freebsd/loader.env. Both are read relative to the device
loader.efi loaded from (they aren't full UEFI device paths)

Next fetch FreeBSD-NextLoaderEnv UEFI environment variable. If
present, read the file it points to in as above and delete the UEFI
environment variable so it only happens once.

This lets one set environment variables in the bootloader.
Unfortunately, we don't have all the mechanisms in place to parse the
file, nor do we have the magic pattern matching in place that
loader.conf has. Variables are of the form foo=bar. No quotes are
supported, so spaces aren't allowed, for example. Also, variables like
foo_load=yes are intercepted when we parse the loader.conf file and
things are done based on that. Since those aren't done here, variables
that cause an action to happen won't work.

Reviewed by: bcran
Differential Revision: https://reviews.freebsd.org/D20016
2019-04-29 05:02:25 +00:00
Toomas Soome
4914ee11ae loader: implement map-vdisk and unmap-vdisk commands
illumos update: https://www.illumos.org/issues/10598

Add map-vdisk and unmap-vdisk commands to create virtual disk interface on top of file. This will allow to use disk image from file system to load and start the kernel.

By mapping file, we create vdiskX device, the device will be listed by lsdev [-v] and can be accessed directly as ls vdisk0p1:/path or can be used as value for currdev variable.

vdisk strategy function does not use bcache as we have bcache used with backing file. vdisk can be unmapped when all consumers have closed the open files.

In first iteration we do not support the zfs images because zfs pools do keep the device open (there is no "zpool export" mechanism). Adding zfs support is relatively simple, we just need to run zfs disk probe after mapping is done.

Differential Revision:	https://reviews.freebsd.org/D19733
2019-04-26 17:58:44 +00:00
Warner Losh
125e3b9d9b Add the proper range of years for Netflix's copyright on this
file. Note that I wrote it.
2019-04-25 20:23:13 +00:00
Warner Losh
8c914c579e Move initialization of the block device handles earlier (we're just
snagging them from UEFI BIOS). Call the device type init routines
earlier as well, as they don't depend on how the console is
setup. This will allow us to read files earlier in boot, so any rare
error messages that this might move only to the EFI console will be an
acceptable price to pay. Also tweak the order of has_kbd so it resides
next to the rest of the console code. It needs to be after we initialize
the buffer cache.
2019-04-25 20:10:02 +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
Emmanuel Vadot
0eb610e8e3 loader: fdt: Add fdt_is_setup function
When efi_autoload is called it will call fdt_setup_fdtp which setup the
dtb and overlays. If a user already loaded at dtb or overlays or just
printed the efi provided dtb, this will re-setup everything and also
re-applying the overlays.
Test that everything is setup before doing it again.

Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D20059
2019-04-25 20:08:43 +00:00
Ian Lepore
e77f4eb2a0 Restore the ability to open a raw disk or partition in loader(8).
The disk_open() function searches for "the best partition" when slice and
partition information is not provided as part of the device name.  As of
r345477 the slice and partition fields of a disk_devdesc are initialized to
D_SLICEWILD and D_PARTWILD; in the past they were initialized to -1, which
was sometimes interpreted as meaning 'wildcard' and sometimes as 'open the
raw partition' depending on the context.  So as an unintended side effect of
r345477 it became basically impossible to ever open a disk or partition
without doing the 'best partition' search.  One visible effect of that was
the inability to open the raw disk to read the partition table correctly in
zfs_probe_dev(), leading to failures to find the zfs pool unless it was on
the first partition.

Now instead of always initializing slice and partition to wildcards, the
disk_parsedev() function initializes them based on the presence of a
path/file name following the device.  If there is any path or filename
following the ':' that ends the device name, then slice and partition are
initialized to D_SLICEWILD and D_PARTWILD.  If there is nothing after the
':' then it is considered to be a request to open the raw device or
partition itself (not a file stored within it), and the fields are
initialized to D_SLICENONE and D_PARTNONE.

With this change in place, all the tests in src/tools/boot are succesful
again, including the recently-added cases of booting from a zfs pool on
a partition other than slice 1 of the device.

PR:		236981
2019-04-25 15:09:21 +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
36d3716064 Move setting of console earlier in boot.
There's no reason we can't setup the console first thing after the
arch flags are setup. We set it undconditionally to efi. This is a
good default, and will get us error messages to at least the efi
console no matter what. This will also prime the pump so that as other
variables are set, they will take effect and the console will be
correct as soon as those env vars are set. Also remove the redundant
setting of the console to efi when we know the console is efi.

Differential Revision: https://reviews.freebsd.org/D20014
2019-04-22 18:33:32 +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
87818fbe99 Add UEFI definitions related to converting string to DEVICE_PATH
Add definitions from UEFI 2.7 Errata B standards doc for converting a
text string to a device path. Added clearly missing 'e' at the end of
Device to resolve mismatch in that document in
EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL element names.

Differential Revision: https://reviews.freebsd.org/D19971
2019-04-19 19:45:15 +00:00
Warner Losh
40c9957cb7 Add define for CONST.
Newer interfaces take CONST parameters, so define CONST to minimize
differences between our headers and the standards docs.

Differential Revision: https://reviews.freebsd.org/D19971
2019-04-19 19:44:59 +00:00
Warner Losh
375cd3bbaa Minor tweak to the debug
Make it clear we're loading from UFS.
2019-04-18 15:19: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
Kyle Evans
2a1e52f347 stand: refactor overlay loading a little bit
It was pointed out that manually loading a .dtb to be used rather than
relying on platform-specific method for loading .dtb will result in overlays
not being applied. This was true because overlay loading was hacked into
fdt_platform_load_dtb, rather than done in a way more independent from how
the .dtb is loaded.

Instead, push overlay loading (for now) out into an
fdt_platform_load_overlays. This method easily allows ubldr to pull in any
fdt_overlays specified in the ub env, and omits overlay-checking on
platforms where they're not tested and/or not desired (e.g. powerpc). If we
eventually stop caring about fdt_overlays from ubenv (if we ever cared),
this method should get chopped out in favor of just calling
fdt_load_dtb_overlays() directly.

Reported by:	Manuel Stühn (freebsdnewbie freenet de)
2019-04-11 13:26:28 +00:00
Toomas Soome
0dc2db13ec loader: command_lsefi: ret can be used uninitialized
MFC after:	1w
2019-04-07 14:07:28 +00:00
Toomas Soome
ed79202682 loader: add file_remove() function to undo file_insert_tail().
346002 did miss the fact that we do not only undo the loadaddr, but also
we need to remove the inserted module. Implement file_remove() to do the job.

MFC after:	1w
2019-04-07 13:36:17 +00:00
Toomas Soome
d7125bb1e2 loader: mod_loadkld() error: we previously assumed 'last_file' could be null
The last_file variable is used to reset the loadaddr variable back to original
value; however, it is possible the last_file is NULL, so we can not blindly
trust it. But then again, we can just save the original loadaddr and use
the saved value for recovery.

MFC after:	1w
2019-04-07 12:20:17 +00:00
Toomas Soome
d28c594669 loader: file_addmetadata() should check for memory allocation
malloc() can return NULL.

MFC after:	1w
2019-04-07 12:10:19 +00:00
Toomas Soome
1d28f39d20 loader: remove pointer checks before free() in module.c
free() does check for NULL argument, remove duplicate checks.

MFC after:	1w
2019-04-07 11:55:11 +00:00
Toomas Soome
db7599e9e5 loader: file_addmodule should check for memory allocation
strdup() can return NULL.

MFC after:	1w
2019-04-07 11:50:41 +00:00
Toomas Soome
cef2742e20 loader: malloc+bzero is calloc
Replace malloc+bzero in module.c with calloc.

MFC after:	1w
2019-04-07 11:48:41 +00:00
Marcin Wojtas
b0fefb25c5 Create kernel module to parse Veriexec manifest based on envs
The current approach of injecting manifest into mac_veriexec is to
verify the integrity of it in userspace (veriexec (8)) and pass its
entries into kernel using a char device (/dev/veriexec).
This requires verifying root partition integrity in loader,
for example by using memory disk and checking its hash.
Otherwise if rootfs is compromised an attacker could inject their own data.

This patch introduces an option to parse manifest in kernel based on envs.
The loader sets manifest path and digest.
EVENTHANDLER is used to launch the module right after the rootfs is mounted.
It has to be done this way, since one might want to verify integrity of the init file.
This means that manifest is required to be present on the root partition.
Note that the envs have to be set right before boot to make sure that no one can spoof them.

Submitted by: Kornel Duleba <mindal@semihalf.com>
Reviewed by: sjg
Obtained from: Semihalf
Sponsored by: Stormshield
Differential Revision: https://reviews.freebsd.org/D19281
2019-04-03 03:57:37 +00:00
Ed Maste
698194ab24 stand: remove CLANG_NO_IAS from zfsldr
Many components under stand/ had CLANG_NO_IAS added when Clang's
Integrated Assembler (IAS) did not handle .codeNN directives.  Clang
gained support quite some time ago, and we can now build stand/ with
IAS.

Note that in some cases there are small differences in the generated
output, so CLANG_NO_IAS should be removed only after testing (or after
finding no differences in the output).  For zfsldr I compared objdump
output between GNU as- and Clang IAS-built zfsldr and .text was
identical (changes were limited to the object's ELF headers and debug
info).

Sponsored by:	The FreeBSD Foundation
2019-03-26 20:32:05 +00:00
Kyle Evans
8f7f3d08ae lualoader: Fix up some luacheck concerns
- Garbage collect an unused (removed because it was useless) constant
- Don't bother with vararg notation if args will not be used

MFC after:	1 week
2019-03-26 02:35:58 +00:00
Kyle Evans
c206dd4d81 lualoader: Clear the screen before prompting for password
Assuming that the autoboot sequence was interrupted, we've done enough
cursor manipulation that the prompt for the password will be sufficiently
obscured a couple of lines up. Clear the screen and reset the cursor
position here, too.

MFC after:	1 week
2019-03-26 02:33:27 +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
Ed Maste
fe6ee08134 loader: fix loading of kernels with . in path
The loader indended to search the kernel file name (only) for . but
instead searched the entire path, so paths like
"boot/test.elfv2/kernel" would not work.

Submitted by:	alfredo.junior_eldorado.org.br
Reviewed by:	kevans
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D19658
2019-03-20 16:24:47 +00:00
Marcin Wojtas
c42e554dc9 Add missing boot.4th verification
During initialization of the forth interpreter
the loader looks for "/boot/boot.4th"
and executes any code found there.
That file was loaded bypassing verification.
Add a call to verify_file to change that.

Submitted by: Kornel Duleba <mindal@semihalf.com>
Reviewed by: sjg
Obtained from: Semihalf
Sponsored by: Stormshield
2019-03-19 02:45:32 +00:00
Kyle Evans
7325df02c5 stand: Improve some debugging experience
Some of these files using <FOO>_DEBUG defined a DEBUG() macro to serve as a
debug-printf. -DDEBUG is useful to enable some debugging output across
multiple ELF/common parts, so switch the DEBUG-as-printf macros over to
something more like DPRINTF that is more commonly used for this kind of
thing and less likely to conflict.

userboot/elf64_freebsd debugging also assumed %llx for uint64; use PRIx64
instead.

MFC after:	1 week
2019-03-12 16:21:39 +00:00
Emmanuel Vadot
73a41ff81c stand/common/module: Apply style(9) 2019-03-07 18:57:43 +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
13ea0450a9 Extend libsecureboot(old libve) to obtain trusted certificates from UEFI and implement revocation
UEFI related headers were copied from edk2.

A new build option "MK_LOADER_EFI_SECUREBOOT" was added to allow
loading of trusted anchors from UEFI.

Certificate revocation support is also introduced.
The forbidden certificates are loaded from dbx variable.
Verification fails in two cases:

There is a direct match between cert in dbx and the one in the chain.
The CA used to sign the chain is found in dbx.
One can also insert a hash of TBS section of a certificate into dbx.
In this case verifications fails only if a direct match with a
certificate in chain is found.

Submitted by: Kornel Duleba <mindal@semihalf.com>
Reviewed by: sjg
Obtained from: Semihalf
Sponsored by: Stormshield
Differential Revision:	https://reviews.freebsd.org/D19093
2019-03-06 06:39:42 +00:00
Rebecca Cran
ce37b71e68 Add retry loop around GetMemoryMap call to fix fragmentation bug
The call to BS->AllocatePages can cause the memory map to become framented,
causing BS->GetMemoryMap to return EFI_BUFFER_TOO_SMALL more than once. For
example this can happen on the MinnowBoard Turbot, causing the boot to stop
with an error. Avoid this by calling GetMemoryMap in a loop.

Reviewed by:	imp, tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D19341
2019-03-06 05:39:40 +00:00
Simon J. Gerraty
fd1d7567d8 Add -d flag to load command
When doing load -t manifest -d increments debug level

Reviewed by:	stevek
2019-03-04 19:50:59 +00:00
Rebecca Cran
ea7796a9ae EFI: don't call printf after ExitBootServices, since it uses Boot Services
ExitBootServices terminates all boot services including console access.
Attempting to call printf afterwards can result in a crash, depending on the
implementation.

Move any printf statements to before we call bi_load, and remove any that
depend on calling bi_load first.

Reviewed by:	imp, tsoome
Differential Revision:	https://reviews.freebsd.org/D19374
2019-03-02 04:02:11 +00:00
Simon J. Gerraty
8df8b2d3e5 Enable veriexec for loader
This relies on libbearssl and libsecureboot
to verify files read by loader in a maner equivalent
to how mac_veriexec

Note: disabled by default.
Use is initially expected to be by embeded vendors

Reviewed by:	emaste, imp
Sponsored by:	Juniper Networks
Differential Revision:	D16336
2019-02-26 06:22:10 +00:00
Kyle Evans
e5a24fa137 stand: Remove unused i386 EFI MD bits
r328169 removed the copy of bootinfo that would've made this somewhat
functional. However, this is irrelevant- earlier work in r292338 was done to
exit boot services in the MI bi_load() rather than having N copies of the
GetMemoryMap/ExitBootServices dance.

i386 never quite caught up to that; ldr_enter was still being called but
the prereq for that, ldr_bootinfo, was no longer. As a consequence, this
ExitBootServices() was being called with a mapkey=0, clearly bogus, and
reportedly breaking the boot in some instances.

Reported by:	bcran
MFC after:	1 week
2019-02-26 03:37:12 +00:00
Toomas Soome
6cea60aef5 loader: really fix cd9660 dirmatch
The cd9660_open() does pass whole path to dirmatch() and we need to
compare only the current path component, not full path.

Additinally, skip over duplicate / (if any) and check if the last component
in the path was meant to be directory (having trailing /). If it is in fact
a file, error out.
2019-02-20 21:07:09 +00:00
Ian Lepore
98934c6843 Fix the handling of legacy-format devices in the u-boot loaderdev variable.
When I added support for the standard loader(8) disk0s2a: type formats,
the parsing of legacy format was broken because it also contains a colon,
but it comes before the slice and partition. That would cause disk_parsedev()
to return success with the slice and partition set to wildcard values.

This change examines the string first, and if it contains spaces, dots, or
a colon at any position other than the end, it must be a legacy-format
string and we don't even try to use disk_parsedev() on it.

Reported by:	Manuel Stuhn
2019-02-20 03:00:55 +00:00
Toomas Soome
63f582e0f5 loader: ptable_close() should check its argument
If the passed in table is NULL, just return.
2019-02-18 20:29:19 +00:00
Ian Lepore
28ef0240e0 Allow the u-boot loaderdev env var to be formatted in the "usual" loader(8)
way: device<unit>[s|p]<slice><partition>.  E.g., disk0s2a or disk3p12.
The code first tries to parse the variable in this format using the
standard disk_parsedev().  If that fails, it falls back to parsing the
legacy format that has been supported by ubldr for years.

In addition to 'disk', all the valid uboot device names can also be used:
mmc, sata, usb, ide, scsi. The 'disk' device serves as an alias for all
those types and will match the Nth storage-type device found (where N is
the unit number).
2019-02-18 17:12:30 +00:00
Ian Lepore
e5c0d6a0ca Fix more places to use DEV_TYP_NONE instead of -1 to indicate 'no device'. 2019-02-18 15:28:12 +00:00
Ian Lepore
85c7139a76 Use DEV_TYP_NONE instead of -1 to indicate no device was specified.
DEV_TYP_NONE has a value of zero, which makes more sense since the device
type is a bunch of bits describing the device, crammed into an int.
2019-02-18 15:09:19 +00:00
Toomas Soome
61250f78c4 cd9660: dirmatch fails to unmatch when name is prefix for directory record
Loader does fail to properly match the file name in directory record and
does open file based on prefix match.

For fix, we check the name lengths first.

Reviewed by:	allanjude
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D19213
2019-02-18 08:26:18 +00:00
Ian Lepore
5a75fc4b11 Make uboot_devdesc properly alias disk_devdesc, so that parsing the u-boot
loaderdev variable works correctly.

The uboot_devdesc struct is variously cast back and forth between
uboot_devdesc and disk_devdesc as pointers are handed off through various
opaque interfaces.  uboot_devdesc attempted to mimic the layout of
disk_devdesc by having a devdesc struct, followed by a union of some
device-specific stuff that included a struct that contains the same fields
as a disk_devdesc.  However, one of those fields inside the struct is 64-bit
which causes the entire union to be 64-bit aligned -- 32 bits of padding
is added between the struct devdesc and the union, so the whole mess ends
up NOT properly mimicking a disk_devdesc after all.  (In disk_devdesc there
is also 32 bits of padding, but it shows up immediately before the d_offset
field, rather than before the whole collection of d_* fields.)

This fixes the problem by using an anonymous union to overlay the devdesc
field uboot network devices need with the disk_devdesc that uboot storage
devices need.  This is a different solution than the one contributed with
the PR (so if anything goes wrong, the blame goes to me), but 95% of the
credit for this fix goes to Pawel Worach and Manuel Stuhn who analyzed the
problem and proposed a fix.

PR:		233097
2019-02-18 04:44:52 +00:00
Kyle Evans
d61897abea lualoader: only clear the screen before first password prompt
This was previously an unconditional screen clear, regardless of whether or
not we would be prompting for any passwords. This is pointless, given that
the screen clear is only there to put our screen into a consistent state
before we draw the prompts and do cursor manipulation.

This is also the only screen clear besides that to draw the menu.  One can
now see early pre-loader and loader output with the menu disabled, which may
be useful for diagnostics.

Reported by:	ian
MFC after:	3 days
2019-02-18 02:59:47 +00:00
Justin Hibbits
bc4d122db0 powerpc/boot: Move ubldr to /boot/uboot, and make this a separate filesystem
Summary:
Now that mpc85xx can boot via ubldr, move ubldr to a separate
filesystem, mounted on /boot/uboot, so that a fresh install can boot correctly.

Reviewed By: nwhitehorn
Differential Revision: https://reviews.freebsd.org/D18709
2019-02-18 01:57:47 +00:00
Ian Lepore
7827bb1c2c Garbage collection no-longer-used constant. 2019-02-17 23:48:51 +00:00
Ian Lepore
5b777dbfa5 Make lsdev -v output line up in neat columns by using a fixed width for
the size field and a tab between the partition type and the size.

Changes this

  disk devices:
        disk0 (MMC)
        disk0s1: DOS/Windows            49MB
        disk0s2: FreeBSD                14GB
        disk0s2a: FreeBSD UFS         14GB
        disk0s2b: Unknown             2048KB
        disk0s2d: FreeBSD UFS         2040KB

to this

  disk devices:
        disk0 (MMC)
        disk0s1: DOS/Windows      49MB
        disk0s2: FreeBSD          14GB
        disk0s2a: FreeBSD UFS     14GB
        disk0s2b: Unknown       2048KB
        disk0s2d: FreeBSD UFS   2040KB
2019-02-17 23:46:11 +00:00
Ian Lepore
71c96def1c Use a couple local variables to avoid repetitive long expressions that
cause line-wrapping.
2019-02-17 23:38:17 +00:00
Ian Lepore
4d02caf7cb Restore loader(8)'s ability for lsdev to show partitions within a bsd slice.
I'm pretty sure this used to work at one time, perhaps long ago.  It has
been failing recently because if you call disk_open() with dev->d_partition
set to -1 when d_slice refers to a bsd slice, it assumes you want it to
open the first partition within that slice.  When you then pass that open
dev instance to ptable_open(), it tries to read the start of the 'a'
partition and decides there is no recognizable partition type there.

This restores the old functionality by resetting d_offset to the start
of the raw slice after disk_open() returns.  For good measure, d_partition
is also set back to -1, although that doesn't currently affect anything.

I would have preferred to make disk_open() avoid such rude assumptions and
if you ask for partition -1 you get the raw slice.  But the commit history
shows that someone already did that once (r239058), and had to revert it
(r239232), so I didn't even try to go down that road.
2019-02-17 23:32:09 +00:00
Patrick Kelsey
a070559721 It turns out r344226 narrowed the overrun bug but did not eliminate it entirely
This commit fixes a remaining output buffer overrun in the
single-sector case when there is a non-zero tail.

Reviewed by:	allanjude, tsoome
MFC after:	3 months
MFC with:	r344226
Differential Revision:	https://reviews.freebsd.org/D19220
2019-02-17 17:47:08 +00:00
Patrick Kelsey
861729a32e Remove whole-disk vdev support from zfsboot
This is consistent with the removal of whole-disk vdev support from
libsa/zfs/zfs.c in r342151, and is part way to having the LBAs read
during probe be fully constrained by partition tables when present.

Reviewed by:	tsoome
MFC after:	3 months
Differential Revision:	https://reviews.freebsd.org/D19142
2019-02-17 03:52:44 +00:00
Patrick Kelsey
07362361e0 Fix memory corruption bug introduced in r325310
The bug occurred when a bounce buffer was used and the requested read
size was greater than the size of the bounce buffer.  This commit also
rewrites the read logic so that it is easier to systematically verify
all alignment and size cases.

Reviewed by:	allanjude, tsoome
MFC after:	3 months
Differential Revision:	https://reviews.freebsd.org/D19140
2019-02-17 03:35:15 +00:00
Ed Maste
bcf99d2d99 Add WITH_PIE knob to build Position Independent Executables
Building binaries as PIE allows the executable itself to be loaded at a
random address when ASLR is enabled (not just its shared libraries).

With this change PIE objects have a .pieo extension and INTERNALLIB
libraries libXXX_pie.a.

MK_PIE is disabled for some kerberos5 tools, Clang, and Subversion, as
they explicitly reference .a libraries in their Makefiles.  These can
be addressed on an individual basis later.  MK_PIE is also disabled for
rtld-elf because it is already position-independent using bespoke
Makefile rules.

Currently only dynamically linked binaries will be built as PIE.

Discussed with:	dim
Reviewed by:	kib
MFC after:	1 month
Relnotes:	Yes
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D18423
2019-02-15 22:22:38 +00:00
Kyle Evans
e49f2c66d1 stand: dev_net: correct net_open's interpretation of params
net_open previously casted the first vararg to a char * and this was
half-OK: at first, it is passed to netif_open, which would cast it back to
the struct devdesc * that it really is and use it properly. It is then
strdup()d and used as the netdev_name, which is objectively wrong.

Correct it so that the first vararg is properly casted to a struct devdesc *
and the netdev_name gets set properly to make it more clear at a glance that
it's not doing something horribly wrong.

Reported by:	mmel
Reviewed by:	imp, mmel, tsoome
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D19206
2019-02-15 18:28:51 +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
Oleksandr Tymoshenko
8c8748225f Unbreak mip64 build after r328437
Add exit and getchar functions to beri/boot2 code. They are required by
panic_action functin introduced in r328437
2019-01-20 21:09:44 +00:00
Toomas Soome
5e84b57828 libsa: add asprintf()
asprintf() is a nice tool for string processing.

MFC after:	2 weeks
2019-01-17 22:00:02 +00:00
Toomas Soome
7c52f914db loader should ignore active multi_vdev_crash_dump feature on zpool
Since the loader zfs reader does not need to read the dump zvol, we can
just enable the feature.

illumos issue #9051 https://www.illumos.org/issues/9051

MFC after:	2 weeks
2019-01-17 21:52:41 +00:00
Kirk McKusick
88640c0e8b Create new EINTEGRITY error with message "Integrity check failed".
An integrity check such as a check-hash or a cross-correlation failed.
The integrity error falls between EINVAL that identifies errors in
parameters to a system call and EIO that identifies errors with the
underlying storage media. EINTEGRITY is typically raised by intermediate
kernel layers such as a filesystem or an in-kernel GEOM subsystem when
they detect inconsistencies. Uses include allowing the mount(8) command
to return a different exit value to automate the running of fsck(8)
during a system boot.

These changes make no use of the new error, they just add it. Later
commits will be made for the use of the new error number and it will
be added to additional manual pages as appropriate.

Reviewed by:    gnn, dim, brueffer, imp
Discussed with: kib, cem, emaste, ed, jilles
Differential Revision: https://reviews.freebsd.org/D18765
2019-01-17 06:35:45 +00:00
Oleksandr Tymoshenko
9883649c84 Add Dell Chromebook to the list of devices with E820 extmem quirk enabled
Just like for Acer C270 chromebook the E820 extmem workaround is required for
FreeBSD to boot on Dell chromebook.

PR:		204916
Submitted by:	Keith White <kwhite@site.uottawa.ca>
MFC after:	1 week
2019-01-14 01:30:48 +00:00
Warner Losh
2cd8f54b87 biospci_write_config args were backwards
biospci_write_config args swapped length and value to write. Some
hardware coped just fine, while other hardware had issues.

PR: 155441
Submitted by: longwitz at incore dot de
2019-01-08 20:01:56 +00:00
Warner Losh
f871c5d99d Create MK_LOADER_VERBOSE and connect it to ELF_VERBOSE in the loader
code.

PR: 18498
Submitted by: mellon at pobox dot com
2019-01-07 05:49:27 +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
a9f7119bb8 With buggy int13 ah=15, we can mis-identify the floppy devices.
We have no option than trust INT13 ah=08 return code during the init phase.

PR:		234460
Reported by:	Oleh Hushchenkov
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D18723
2019-01-05 07:20:00 +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
295586e818 i386_parsedev() needs to support fd devices
MFC after:	2 weeks
2019-01-02 20:31:15 +00:00
Toomas Soome
46aedfa274 Add Copyright.
Reported by:	Rodney W. Grimes
2018-12-30 15:34:12 +00:00
Toomas Soome
75772fa26e loader: create bio_alloc and bio_free for bios bounce buffer
We do have 16KB buffer space defined in pxe.c, move it to bio.c and implement
bio_alloc()/bio_free() interface to make it possible to use this space for
other BIOS calls (notably, from biosdisk.c).

MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D17131
2018-12-30 09:35:47 +00:00
Rebecca Cran
d5cee48f3e Wait a maximum of 300 seconds for network send/recv in libsa
The reason for this change is that currently, a send/recv
takes many hours to time out.
This is suboptimal in the bootloader because it means for example
that NFS will take hours to fail before allowing subsequent access
methods such as gzip to be tried.

Setting MAXWAIT to 300 seconds (5 minutes) still allows slow
connections of 1Mb to be used to download a 30MB kernel file.

Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D18544
2018-12-20 19:27:46 +00:00
Toomas Soome
4f22b40a32 loader: zfs reader should not probe partitionless disks (UEFI case)
With r342151 I did fix the BIOS version of zfs_probe_dev() from accessing
the whole disk, but the fix was not complete - we actually did not check
if the device name was really for whole disk. Since UEFI version
is only calling the zfs_probe_dev() with partitions and not with whole
disk, the UEFI loader was not able to find the zfs pools.

This update does correct the issue by calling archsw.arch_getdev() to
translate the device name back to dev_desc, and we have whole disk when both
partition and slice values are -1.

Reported by:	alvisen_gmail.com
Differential Revision:	https://reviews.freebsd.org/D18558
2018-12-17 07:43:29 +00:00
Toomas Soome
1309bed839 loader: zfs reader should not probe partitionless disks
First of all, normal setups can not boot such pools as the tools
do not support installing boot programs.

Secondly, for proper pool configuration detection, we need to checks all
four label copies on disk, 2 from front and 2 from the end of the disk,
but zfs label does not contain the size of the disk - so we depend on
firmware to report the correct disk size or use information from the
partition table.

Without partition table, we only can rely on firmware to report and support
disk IO properly.

There is a specific case: 8TB disks are reported by BIOS to have 4294967295
sectors (0x00000000ffffffff), the sectors reported by OS is 15628053168
(0x00000003a3812ab0), so the reported size is less than actual but is hitting
32-bit max. Unfortuantely the real limit must be even lower because probing
this disk in this system will wnd up with hung system.

UEFI boot of this system seems not to be affected.

Reviewed by:	imp
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D18558
2018-12-16 08:58:14 +00:00
Rebecca Cran
122229de87 Cast error message in efi_main.c to CHAR16* to avoid build error 2018-12-13 23:49:20 +00:00
Rebecca Cran
974df0a915 Print an error message in efi_main.c if we can't allocate memory for the heap
With the default Qemu parameters, only 128MB RAM gets given to a VM. This causes
the loader to be unable to allocate the 64MB it needs for the heap. This change
makes the cause of the error more obvious.

Differential Revision:	https://reviews.freebsd.org/D17958
2018-12-13 23:20:58 +00:00
Justin Hibbits
9471caaba7 powerpc/ubldr: Teach powerpc's ubldr to boot 64-bit kernels
This is just a copy of powerpc/ofw's ppc64_elf_freebsd.c modified to fit
ubldr's boot format.

MFC after:	1 week
2018-12-10 01:52:39 +00:00
Ian Lepore
9631ae8267 Don't reference zfs-specific variables if LOADER_ZFS_SUPPORT is undefined
because the variables will be undefined too.

Reported by:	sjg@
Pointy hat:	ian@
2018-12-06 20:28:09 +00:00
Kirk McKusick
fb14e73cb4 Normally when an attempt is made to mount a UFS/FFS filesystem whose
superblock has a check-hash error, an error message noting the
superblock check-hash failure is printed and the mount fails. The
administrator then runs fsck to repair the filesystem and when
successful, the filesystem can once again be mounted.

This approach fails if the filesystem in question is a root filesystem
from which you are trying to boot. Here, the loader fails when trying
to access the filesystem to get the kernel to boot. So it is necessary
to allow the loader to ignore the superblock check-hash error and make
a best effort to read the kernel. The filesystem may be suffiently
corrupted that the read attempt fails, but there is no harm in trying
since the loader makes no attempt to write to the filesystem.

Once the kernel is loaded and starts to run, it attempts to mount its
root filesystem. Once again, failure means that it breaks to its prompt
to ask where to get its root filesystem. Unless you have an alternate
root filesystem, you are stuck.

Since the root filesystem is initially mounted read-only, it is
safe to make an attempt to mount the root filesystem with the failed
superblock check-hash. Thus, when asked to mount a root filesystem
with a failed superblock check-hash, the kernel prints a warning
message that the root filesystem superblock check-hash needs repair,
but notes that it is ignoring the error and proceeding. It does
mark the filesystem as needing an fsck which prevents it from being
enabled for writing until fsck has been run on it. The net effect
is that the reboot fails to single user, but at least at that point
the administrator has the tools at hand to fix the problem.

Reported by:    Rick Macklem (rmacklem@)
Discussed with: Warner Losh (imp@)
Sponsored by:   Netflix
2018-12-06 00:09:39 +00:00
Ian Lepore
7297dc4441 Fix args cross-threading between gptboot(8) and loader(8) with zfs support.
When loader(8) is built with zfs support enabled, it assumes that any extarg
data present is a zfs_boot_args struct, but if the first-stage loader was
gptboot(8) the extarg data is actually a geli_boot_args struct.  Luckily,
zfsboot(8) and gptzfsboot(8) have always passed KARGS_FLAGS_ZFS along with
KARGS_FLAGS_EXTARG, so we can use KARGS_FLAGS_ZFS to decide whether the
extarg data is a zfs_boot_args struct.

To avoid similar problems in the future, gptboot(8) now passes a new
KARGS_FLAGS_GELI to indicate that extarg data is geli_boot_args.  In
loader(8), if the neither KARGS_FLAGS_ZFS nor KARGS_FLAGS_GELI is set but
extarg data is present (which will be the case for gptboot compiled before
this change), we now check for the known size of the geli_boot_args struct
passed by the older versions of gptboot as a way of confirming what type of
extarg data is present.

In a semi-related tidying up, since loader's main() has already decided
what type of extarg data is present and set the global 'zargs' var
accordingly, don't repeat the check in extract_currdev, just check whether
zargs is NULL or not.

X-MFC after:	a few days, along with prior related changes.
2018-12-04 16:43:50 +00:00
Ed Maste
f7eb23ee34 stand/i386: rename .s to .S to use Clang IAS
As part of the migration away from obsolete binutils we want to retire
GNU as.  Most assembly files used on amd64 have a .S extension and
(via rules in share/mk/bsd.suffixes.mk) are assembled with Clang's
Integrated Assembler (IAS).  Rename files in stand/i386 to .S to use
the integrated assembler.

Clang's IAS supports the defsym option (via -Wa,) but only with one
dash, not two.  As both -defsym and --defsym are accepted by GNU as,
use the former.

PR:		233611
Reviewed by:	tsoome
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D18369
2018-12-03 19:16:34 +00:00
Warner Losh
991699dbba Move inclusion of src.opts.mk later.
src.opts.mk includes bsd.own.mk. This in turn defines CTFCONVERT_CMD
depending on the MK_CTF value. We then set MK_CTF to no, which has no
real effect. The solution is to set all the MK_foo values before
including src.opts.mk.

This should stop the cdboot binary from exploding in size for releases
built WITH_CTF=yes in src.conf.

Sponsored by: Netflix
2018-12-03 17:51:10 +00:00
Ian Lepore
df108aafe9 Eliminate duplicated code and struct member definitions in the handoff
of args data between gptboot/zfsboot and loader(8).

Despite what seems like a lot of changes here, there are no actual
changes in behavior, or in the data layout in the structures involved.
This is just eliminating identical code pasted into multiple locations.

In detail, the changes are...

- Move struct zfs_boot_args definition from libsa/zfs/libzfs.h to
  i386/common/bootargs.h because it is specific to x86 booting and the
  handoff between zfsboot and loader, and has no relation to the zfs
  library code in general.

- The geli_boot_args and zfs_boot_args structs both contain an identical
  set of member variables containing geli information.  Extract this out
  to a new geli_boot_data struct, and embed it in the arg-passing structs.

- Provide new routines geli_import_boot_data() and geli_export_boot_data()
  that can be shared between gptboot, zfsboot, and loader instead of
  pasting identical code into several different .c files.

- Remove some checks for a NULL pointer that can never be true because the
  pointer being tested was set using pointer math (kargs + 1) and that can
  never result in NULL in this code.
2018-12-03 03:58:30 +00:00
Justin Hibbits
781dc30c1b ubldr: Force 'usefdt' variable to 1 for powerpc
The fdt is gated, on powerpc, with a 'usefdt' environment variable.  Force
enable it in ubldr, so that the fdt is passed through the metadata.
2018-12-02 02:20:35 +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
Toomas Soome
cdff10360e loader: create separate lists for fd, cd and hd, merge bioscd with biosdisk
Create unified block IO implementation in BIOS version, like it is done in UEFI
side. Implement fd, disk and cd device lists, this will split floppy devices
from disks and will allow us to have consistent, predictable device naming
(modulo BIOS issues).

Differential Revision:	https://reviews.freebsd.org/D17888
2018-11-30 08:01:11 +00:00
Maxim Sobolev
d92fb78458 When handling CMD_CRIT error set command_errmsg to NULL after we dump it out,
so that it does not result in error message printed twice.

OK load doodoo
can't find 'doodoo'
can't find 'doodoo'
OK

MFC after:	2 weeks
2018-11-30 02:14:41 +00:00
Maxim Sobolev
55d5c94943 The libstand's panic() appends its own '\n' to the message, so that users of the API
don't need to supply one.

MFC after:	2 weeks
2018-11-29 18:37:48 +00:00
Toomas Soome
13dcff6bd8 loader: command_bcache() should print unsigned values
All bcache counters are unsigned.
2018-11-29 14:21:01 +00:00
Ian Lepore
b92c2c907e Add comments describing the bootargs handoff between loader(8) and gptboot
or zfsboot, when loader(8) is the BTX loader.  No functional changes.
2018-11-28 18:09:42 +00:00
Justin Hibbits
89797c881d powerpcspe: Don't crash the loader on ubldr with SPE instructions.
-msoft-float seems to be insufficient for disabling the SPE on powerpcspe.
Force it off with -mno-spe as well.  This prevents a crash in ubldr on
powerpcspe.
2018-11-28 01:47:01 +00:00
Ian Lepore
52c0ec1455 Restore the ability to override the disk unit/partition at the boot: prompt
in gptboot.

When arch-independent geli support was added, a new static 'gdsk' struct
was added, but there was still a static 'dsk' struct, and when you typed
in an alternate disk/partition, the string was parsed into that struct,
which was then never used for anything.  Now the string gets parsed into
gdsk.dsk, the struct that's actually used.

X-MFC after:	3 days
2018-11-27 16:16:38 +00:00
Guangyuan Yang
71cf0a4e29 Bump the date of pxeboot(8) manual page for r340917.
PR:		123484
MFC after:	5 days
2018-11-27 08:51:15 +00:00
Ed Maste
4f7c9c3e4e stand/i386/libi386: rename .s file to .S to use Clang IAS
As part of the migration away from obsolete binutils we want to retire
GNU as.  Most assembly files used on amd64 have a .S extension and are
assembled with Clang's Integrated Assembler (IAS); rename pxetram.s to
.S to use IAS as well.

The generated .text is identical (the entire .o file is not, as Clang
adds debug info.)

PR:		205250, 233094
Sponsored by:	The FreeBSD Foundation
2018-11-26 19:29:18 +00:00
Ed Maste
e5b8bced3f btx: rename .s files to .S to use Clang IAS
As part of the migration away from obsolete binutils we want to retire
GNU as.  Most assembly files used on amd64 have a .S extension and are
assembled with Clang's integrated assembler; rename two files in
stand/i386/btx/lib to .S to use IAS as well.

The generated .text is identical (the entire .o files are not, as Clang
adds debug info).

PR:		205250, 233094
Discussed with:	imp
Sponsored by:	The FreeBSD Foundation
2018-11-26 19:14:33 +00:00
Guangyuan Yang
2dfc267231 Update pxeboot(8) manual page to reflect the next-server change in the ISC DHCP v3 server.
PR:		123484
Submitted by:	edwin@mavetju.org
Reviewed by:	AllanJude
MFC after:	1 week
2018-11-25 09:37:57 +00:00
Maxim Sobolev
6c81fe160c Nuke out buffer overflow safety marker code, it duplicates similar code in
the malloc()/free() as well as having potential of softening the handling
in case error is detected down to a mere warning as compared to hard panic
in free().

Submitted by:	tsoome
Differential Revision:	https://reviews.freebsd.org/D18299
2018-11-23 22:36:56 +00:00
Ed Maste
76b6af6731 Disable build-id in i386 binary boot components
A user may enable build-id for all builds by adding
LDFLAGS=-Wl,--build-id=sha1 to /etc/make.conf.  In this case the build-id
note ends added up to mbr and pmbr's .text, which makes it too large (it
ends up being 532 bytes). To avoid this explicitly turn off build-id for
these components.

Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D15470
2018-11-23 13:50:18 +00:00
Ed Maste
02c4bf4391 stand: remove CLANG_NO_IAS from btx and gptboot
Many components under stand/ had CLANG_NO_IAS added when Clang's
Integrated Assembler (IAS) did not handle .codeNN directives.  Clang
gained support quite some time ago, and we can now build stand/ with
IAS.

Note that in some cases there are small differences in the generated
output, so CLANG_NO_IAS should be removed only after testing (or after
finding no differences in the output).

PR:		205250, 233094
Sponsored by:	The FreeBSD Foundation
2018-11-20 16:54:42 +00:00
Toomas Soome
a3fd276be0 loader: ptable_open() check for ptable_cd9660read result is wrong
The ptable_*read() functions return NULL on read errors (and partition table
closed as an side effect). The ptable_open must check the return value and
act properly.

PR:		232483
Reported by:	lev
Reviewed by:	lev,cem
Differential Revision:	https://reviews.freebsd.org/D17890
2018-11-07 21:36:52 +00:00
Toomas Soome
53e3fbee09 loader: always set media size from partition.
The disk access is validated by using partition table definitions, therefore
we have no need for if statements, just set the disk size.

Of course the partition table itself may be incorrect/inconsistent, but if
so, we are in trouble anyhow.

Differential Revision:	https://reviews.freebsd.org/D17822
2018-11-07 11:14:22 +00:00
Kyle Evans
bdf12807be lualoader: Add chainload menu entry
MFC after:	4 days
2018-11-05 16:20:07 +00:00
Toomas Soome
0d0ffe4faa loader: biosdisk should check if the media is present
The bd_print/bd_open/bd_strategy need to make sure the device does have
media, before getting into performing IO operations. Some systems can
hung if the device without a media is accessed.

Reported by:	yuripv
2018-11-02 11:41:58 +00:00
Toomas Soome
c50609fc32 loader: do not probe floppy devices for zfs
The subject is telling it all.
2018-11-02 09:47:18 +00:00
Kyle Evans
83f7a74cda lualoader: Implement boot-conf
MFC after:	3 days
2018-11-02 03:25:23 +00:00
Toomas Soome
3c3779dc20 libsa: cstyle cleanup tftp.c
No functinal changes intended.
2018-11-01 22:13:18 +00:00
Toomas Soome
c658866914 libsa: tftp should use calloc
instead of malloc() memset(), use calloc().
2018-11-01 13:29:55 +00:00
Toomas Soome
f442898fe7 libsa: tftp should not read past file end
When we have the file size via tsize option, use it to make sure we
will not attempt to read past file end.
2018-11-01 13:12:05 +00:00
Gleb Smirnoff
9319dded3d Remove unnecessary include from libstand. 2018-10-31 19:59:20 +00:00
Toomas Soome
09312399a7 loader: issue edd probe before legacy ah=08 and detect no media
while probing for drives, use int13 extended info before standard one and
provide workaround for case we are not getting needed information in case
of floppy drive.

In case of INT13 errors, there are (at least) 3 error codes appearing in case
of missin media - 20h, 31h and 80h. Flag the no media and do not print an
error.

Differential Revision:	https://reviews.freebsd.org/D17667
2018-10-31 16:42:40 +00:00
Kyle Evans
5beb550712 lualoader: Fix try_include error handling
The previous iteration of try_include attempted to be 'friendly' and error()
out if we hit an error that wasn't ENOENT. This was semi-OK, but fragile as
it relied on pattern matching the error message.

Move the responsibility for handling failure to the caller. Following
a common lua pattern, we'll return the return value of the underlying
require() on success, or false and an error message.

Reported by:	bcran
MFC after:	3 days
2018-10-29 02:58:30 +00:00
Warner Losh
16633f3a2d Move LUA_ROOT to /boot/lua
While this is mostly unused today, this is a better place than
/usr/local/lua.
2018-10-28 02:57:50 +00:00
Kyle Evans
e1f1ddeb35 lualoader: Always return a proper dictionary for blacklist
If module_blacklist isn't specified, we have an empty blacklist; effectively
the same as if module_blacklist="" were specified in loader.conf(5).

This was reported when switching to a BE that predated the module_blacklist
introduction, but the problem is valid all the same and likely to be tripped
over in other scenarios.

Reported by:	bwidawsk
MFC after:	3 days
2018-10-27 04:10:42 +00:00