Commit Graph

3813 Commits

Author SHA1 Message Date
Toomas Soome
59fcc285f4 libefi: efi_devpath_match() should return bool
The current implementation of efi_devpath_match() is returning values 0 or 1,
so it should be updated to return bool.
2017-09-21 23:14:07 +00:00
Toomas Soome
5370de88cc libefi: devicename.c cleanups
Remove duplicated free()+return statements, default unit to 0
and improve strtol error processing.
2017-09-21 15:30:20 +00:00
Toomas Soome
3f247eab7a loader: biosmem allocate heap just below 4GB
The current biosmem code is walking bios smap entries and looking for smap
entry just below 4GB line, if there is such entry, its base and size is set
for heap base and size. Instead of entry base, we should use last HEAP_MIN
(currently 64MB) bytes just below 4GB, to make maximum space for kernel and
modules.

The problem was revealed on ASUS B350M-A system board, an AMD Ryzen 3 1200 CPU

memory map:

SMAP type=01 base=0000000000000000 len=000000000009d400 attr=01
SMAP type=02 base=000000000009d400 len=0000000000002c00 attr=01
SMAP type=02 base=00000000000e0000 len=0000000000020000 attr=01
SMAP type=01 base=0000000000100000 len=0000000009c00000 attr=01
SMAP type=02 base=0000000009d00000 len=0000000000300000 attr=01
SMAP type=01 base=000000000a000000 len=00000000be69b000 attr=01
SMAP type=03 base=00000000c869b000 len=0000000000016000 attr=01
SMAP type=01 base=00000000c86b1000 len=00000000124e7000 attr=01
SMAP type=02 base=00000000dab98000 len=0000000000138000 attr=01
SMAP type=03 base=00000000dacd0000 len=0000000000008000 attr=01
SMAP type=01 base=00000000dacd8000 len=0000000000100000 attr=01
SMAP type=04 base=00000000dadd8000 len=00000000003b3000 attr=01
SMAP type=02 base=00000000db18b000 len=0000000000d42000 attr=01
SMAP type=01 base=00000000dbecd000 len=0000000002133000 attr=01
SMAP type=01 base=0000000100000000 len=000000011f380000 attr=01
SMAP type=02 base=00000000de000000 len=0000000002000000 attr=01
SMAP type=02 base=00000000f8000000 len=0000000004000000 attr=01
SMAP type=02 base=00000000fdf00000 len=0000000000100000 attr=01
SMAP type=02 base=00000000fea00000 len=0000000000010000 attr=01
SMAP type=02 base=00000000feb80000 len=0000000000082000 attr=01
SMAP type=02 base=00000000fec10000 len=0000000000001000 attr=01
SMAP type=02 base=00000000fec30000 len=0000000000001000 attr=01
SMAP type=02 base=00000000fed00000 len=0000000000001000 attr=01
SMAP type=02 base=00000000fed40000 len=0000000000005000 attr=01
SMAP type=02 base=00000000fed80000 len=0000000000010000 attr=01
SMAP type=02 base=00000000fedc2000 len=000000000000e000 attr=01
SMAP type=02 base=00000000fedd4000 len=0000000000002000 attr=01
SMAP type=02 base=00000000fee00000 len=0000000000100000 attr=01
SMAP type=02 base=00000000ff000000 len=0000000001000000 attr=01

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D12368
2017-09-18 15:17:01 +00:00
Toomas Soome
8b448cf1d6 loader: biosmem.c cstyle cleanup
No functional changes, just cleanup.

Reviewed by:	allanjude, imp
Differential Revision:	https://reviews.freebsd.org/D12370
2017-09-14 16:42:29 +00:00
Allan Jude
dbfcf648a3 Increase EFI boot file size frok 128k to 384k
generate_fat.sh does the following:
- create an 800kb zero-filled file
- create an md device backed by this file
- format the device fat12
- mount the filesystem
- create the EFI ESP directory structure
- create the EFI boot file (BOOTx64 for amd64, BOOTaa64 for aarch64, etc)
- Adds a marker to the beginning of the file, and pad it to 384kb
- 384kb was chosen as it is less than half of 800kb, thus allowing
  users to keep a backup of their older boot file in the small partition
- Unmount the filesystem
- Scan the image and find the offset where the marker was inserted
- The process requires root, to make image generation easier, images for
  each architecture are pregenerated, compressed with xz, and checked
  into svn.

The Makefile that generates boot1.efifat does the following:
- Ensure the compiled boot1.efi file is no larger than the generated image
- Decompress the template created by generate-fat.sh
- dd the contents of boot1.efi into boot1.efifat starting at the offset
  where the marker is found. This allows any file less than the maximum
  size to be written into the fat filesystem without having to mount it,
  so no root privileges are required.

Later work by imp and myself makes bsdinstall create a 200mb fat16 instead
of using this process, but it is retained to make image generation easier.

Submitted by:	Eric McCorkle (original version)
Reviewed by:	emaste, tsoome, Eric McCorkle
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D9680
2017-09-13 17:00:02 +00:00
Toomas Soome
0a0c72ff93 libefi: efipart_realstrategy rsize pointer may be NULL
Need to check rsize before dereferencing it.
2017-09-13 14:27:13 +00:00
Toomas Soome
c7847a364a libefi: efipart_open should check the status from disk_open
In case of error from disk_open(), we should clean up properly.

Reviewed by:	allanjude, imp
Differential Revision:	https://reviews.freebsd.org/D12340
2017-09-12 14:18:45 +00:00
Toomas Soome
b40aaca6dd loader should support large_dnode
The zfsonlinux feature large_dnode is not yet supported by the loader.

Reviewed by:	avg, allanjude
Differential Revision:	https://reviews.freebsd.org/D12288
2017-09-12 13:45:04 +00:00
Ed Maste
e9346a94d1 boot1: remove BOOT1_MAXSIZE default value
This Makefile relies on Makefile.fat providing the correct value for
BOOT1_MAXSIZE and BOOT1_OFFSET. Since BOOT1_OFFSET had no default value
here the build would already fail if Makefile.fat did not provide
correct values.

Sponsored by:	The FreeBSD Foundation
2017-09-11 14:33:04 +00:00
Toomas Soome
4f152c5b8a r323389 breaks the kernel build when WITHOUT_ZFS is defined in src.conf
Need to add #ifdef EFI_ZFS_BOOT guard into efi/loader/main.c

PR:		222215
Reported by:	Sylvain Garrigues
2017-09-11 07:38:53 +00:00
Ed Maste
5e66298138 boot1 generate-fat: generate all templates at once
In advance of other changes to the fat template generation process, have
generate-fat.sh create all template files at the same time so that they
cannot get out of sync.

Also correct a longstanding but where BOOT1_OFFSET was overwritten on
each invocation. A previous version of this patch stored a per-arch
offset (e.g. BOOT1_arm64_OFFSET) but that was deemed unnecessary.
Instead just hardcode the known offset that applies to all archs (0x2d)
and fail if the offset happens to be different.

Ongiong work (using newfs_msdos in bsdinstall and adding msdosfs support
to makefs) will eventually allow us to do away with this fat template
hack altogether, but in the near term we have a few improvements that
will build on this.

Reviewed by:	allanjude, imp, Eric McCorkle
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D10931
2017-09-11 00:37:00 +00:00
Toomas Soome
44832ad99d loader.efi: chain loader should provide proper device handle
Since the efipart rewrite, the chain command was looking for device
handle using interface applicable only for net devices. Disk
partitions and zfs pools need their own approach to find the proper handle.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D12287
2017-09-10 13:53:42 +00:00
Warner Losh
618a000b0c It's been pointed out that init_script at least is useful w/o
re-rooting. Remove deprecation notice for it. init_chroot likely is
still better served with reroot.
2017-09-09 21:33:43 +00:00
Warner Losh
e6d697124f Mark init_chroot and init_script variables as deprecated. 2017-09-09 16:04:49 +00:00
Warner Losh
84ed53b2c0 Be consistent and do return (1);
Noticed by: tsoome@
Sponsored by: Netflix
2017-09-07 15:46:44 +00:00
Warner Losh
1a822dfd33 Fix armv6 build
We need to extend the -Wno-format hack to yet another Makefile to cope
with %S meaning (CHAR16 *) not (wchar_t *) in the context of the EFI
boot loaders.

Sponsored by: Netflix
2017-09-07 07:30:24 +00:00
Warner Losh
1d21184075 ucs2len
Rename boot1's wcslen to ucs2len, which we can't use in userland
because wchar in userland is unsigned, not short. Move it into
efichar.c. Also spell '* 2' as '* sizeof(efi_char)' and add 1 for the
trailing NUL to transition the FreeBSD boot env vars to being NUL
terminated on the same line...

Sponsored by: Netflix
2017-09-07 07:30:05 +00:00
Conrad Meyer
907f50fe04 Add smn(4) driver for AMD System Management Network
AMD Family 17h CPUs have an internal network used to communicate between
the host CPU and the PSP and SMU coprocessors.  It exposes a simple
32-bit register space.

Reviewed by:	avg (no +1), mjoras, truckman
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D12217
2017-09-05 15:13:41 +00:00
Marcin Wojtas
cb4226ba86 Fix loader bug causing too many pages allocation when bootloader is U-Boot
FreeBSD loader expects to have mmsz variable set by bootloader.
U-Boot behaviour is that if buffer size is not big enough to keep
whole memory map, assign the smallest correct buffer size to sz
and return error.

In other words U-Boot assumes that nobody will need mmsz value when buffer
is not filled with memory map, which is not true, so calculated pages value
was too big to allocate.

Solution: Simply assign default value to mmsz.

Submitted by: Patryk Duda <pdk@semihalf.com>
Obtained from: Semihalf
Sponsored by: Semihalf
Differential Revision: https://reviews.freebsd.org/D12194
2017-09-05 05:53:43 +00:00
Warner Losh
d419d89ec9 Revert r322941: Eliminate redundant device matching functions
Turns out, they are subtly different. I'll refactor anew in the future
if it's worth it then.

Sponsored by: Netflix
Reported by: Tomoaki AOKI-san
2017-09-02 18:18:49 +00:00
Warner Losh
6b4a1e856f Save where we're booted from
Record the file path for boot1.efi as the UEFI environemnt variable
FreeBSDBootVarGUID:Boot1Path. Record the device this came from as
FreeBSDBootVarGUID:Boot1Dev. While later stages of the boot may be
able to guess these values by retrieving UEFIGlobal:BootCurrent and
groveling through the correct UEFIGlobal:BootXXXX, this provides
certanty in the face of behavior from any part of the boot loader
chain that might "guess" what to do next. These env variables are
volatile and will disappear on reboot.

Sponsored by: Netflix
2017-08-31 17:32:24 +00:00
Warner Losh
b048c3564d Exit rather than panic for most errors.
In the FreeBSD UEFI boot protocol, boot1.efi exits back to UEFI if it
can't boot the image for most reasons (so that further items in the
EFI boot manger list can be tried). Rename panic to efi_panic, make it
static and give it an extra status argument. Exit back to UEFI with
that status argument so the next loader can be tried.

Use malloc/free exclusively instead of mixing malloc/free and
AllocatePool/FreePool. The code is smaller.

Sponsored by: Netflix
2017-08-31 17:32:19 +00:00
Warner Losh
08576441a4 boot1.efi: print more info about where boot1.efi is loaded from
Print the device that boot1.efi was loaded from. Print the path as
well (since it isn't included in DeviceHandle). Move block where we do
this earlier so all the block handle code is now together.

Sponsored by: Netflix
2017-08-31 17:32:14 +00:00
Warner Losh
2c4b0cefde Make efichar.c routines available to libefi.
Make efichar.c routines available to libefi as well as
libefivar. Define LIBEFI when building so we can conditionally include
stand.h vs the normal userland stuff.
2017-08-31 17:32:09 +00:00
Warner Losh
b0fc288b1a Eliminate redunant device path matching.
Use efi_devpath_match instead of device_paths_match. They are
functionally the same. Remove device_paths_match from boot1.c and call
efi_devpath_match instead.

Sponsored by: Netflix
2017-08-27 03:10:16 +00:00
Warner Losh
4532588625 Use efi_devpath_str for debug path info.
Kill our own hand-rolled (and somewhat flawed) devpath_str in favor of
the recently added efi_devpath_str in libefi. This gives us much
better names at the expense of not being able to debug on EFI 1.2
machines (since the UEFI protocol efi_devpath_str depends on was added
in UEFI 2.0). However, this isn't the first thing that requires newer
than EFI 1.2, so it's quite possible that this doesn't change the
universe of machines we can EFI boot from. This will now give us the
full UEFI path, even for devices we don't yet know about. More
importantly, it gives us the full HD(...) part of the path, which is
sufficient by itself to locate disks that follow the rules (dd one
disk (but not partition) to another still needs the rest of the path
to disambiguate, but that isn't following the rules that require every
GPT table to have globally unique GUIDs for every partion).

This also has the side effect of shrinking boot1.efi by ~3k.

Sponsored by: Netflix
2017-08-26 23:04:19 +00:00
Warner Losh
57d7e4f502 Link in libefi for boot1
Add libefi to the list of libraries we'll link in. Move EFI table
definitions back to libefi so we don't have drift between the two
efi_main routines.

Sponsored by: Netflix
2017-08-26 18:30:14 +00:00
Warner Losh
abc3c1089d Forward declare struct dsk to avoid warnings when building libi386.
Sponsored by: Netflix
2017-08-26 18:30:08 +00:00
Warner Losh
868cb4f19e Remove useless 'static' for an enum definition.
Sponsored by: Netflix
2017-08-26 18:30:03 +00:00
Warner Losh
f4380fc45d Fix warnings due to type mismatch.
Cast ctxp to caddr_t to pass data as expected. While void * is a
universal type, char * isn't (and that's what caddr_t is defined as).
One could argue these prototypes should take void * rather than
caddr_t, but changing that is much more invasive.

Sponsored by: Netflix
2017-08-26 18:29:58 +00:00
Warner Losh
6fefa52c48 _STAND is sometimes defined on the command line. Make the define here match.
Sponsored by: Netflix
2017-08-26 18:29:53 +00:00
Warner Losh
7b900dc2be No need for MK_ZFS around these: they are by their nature only active
when MK_ZFS is true.

Sponsored by: Netflix
2017-08-26 18:29:48 +00:00
Warner Losh
0414cb13ec Use the loader.efi conventions for the various EFI tables.
Sponsored by: Netflix
2017-08-26 18:29:43 +00:00
Warner Losh
194748f6a3 Cleanup efi_main return type
Make the return type of efi_main uniform. Declare the Exit() function
as not returning. Move efi_main's declaration to the proper header.

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

Sponsored by: Netflix
2017-08-26 18:29:24 +00:00
Mariusz Zaborski
3453dc72ad Hide length of geli passphrase during boot.
Introduce additional flag to the geli which allows to restore previous
behavior.

Reviewed by:	AllanJude@, cem@ (previous version)
MFC:		1 month
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D11751
2017-08-26 14:07:24 +00:00
Maxim Sobolev
c7e10205ae Make spinconsole platform independent and hook it up into EFI loader on
i386 and amd64. Not enabled on ARMs, those are lacking timer routines.

MFC after:	2 moths
Sponsored by:	Sippy Software, Inc.
2017-08-25 17:29:48 +00:00
Oleksandr Tymoshenko
00120249a7 Add "xlnx,zynq-7000" to zedboard and zybo compatible property
This property is required to boot CURRENT on zedboard and zybo

PR:		221208
Submitted by:	Thomas Skibo <thoma555-bsd@yahoo.com>
2017-08-24 02:08:52 +00:00
Emmanuel Vadot
d5d62a7a89 RPI DTS: Add value previously set by VideoCore and DTB links
Using latest U-Boot for RPI 1 or 2 the DTB loaded by the firmware is discarded.
The DTB was previously patched by the firmware to contain the DMA channel mask.
DTB provided by the rpi firmware or DTS in the Linux tree contain the raw value
directly. Do the same for our DTS as we cannot switch to the upstream ones yet.
Not having the DMA channel mask setup properly cause mmc not to be detected
(and probably other problems on driver using DMA).

Also, add links for rpi dtb to the name used by u-boot. This way the dtb can be
loaded by ubldr using the U-Boot env variable fdtfile.

Tested On: RPI B Rev2, RPI Zero, RPI 2 v1.1 RPI 2 v1.2

Thanks to Sylvain Garrigues <sylvain@sylvaingarrigues.com> for the help.

PR:		218344
2017-08-19 14:27:11 +00:00
Oleg Bulyzhin
2052157d77 Fix BSD label partition end sector calculation.
Reviewed by:	ae
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D12066
2017-08-17 19:39:42 +00:00
Warner Losh
0362fb3a9c Define proposed GUID for FreeBSD boot loader variables. 2017-08-16 20:09:39 +00:00
Warner Losh
d9983db1f6 Remove unused defines. 2017-08-16 20:06:38 +00:00
Toomas Soome
fb46c37596 loader.efi: repace XXX with real comments in trap.c
There are two missing comments marked as XXX in trap.c, fix this.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D12035
2017-08-15 14:03:26 +00:00
Ruslan Bukin
af19cc59ca Support for v1.10 (latest) of RISC-V privilege specification.
New version is not compatible on supervisor mode with v1.9.1
(previous version).

Highlights:
    o BBL (Berkeley Boot Loader) provides no initial page tables
      anymore allowing us to choose VM, to build page tables manually
      and enable MMU in S-mode.
    o SBI interface changed.
    o GENERIC kernel.
      FDT is now chosen standard for RISC-V hardware description.
      DTB is now provided by Spike (golden model simulator). This
      allows us to introduce GENERIC kernel. However, description
      for console and timer devices is not provided in DTB, so move
      these devices temporary to nexus bus.
    o Supervisor can't access userspace by default. Solution is to
      set SUM (permit Supervisor User Memory access) bit in sstatus
      register.
    o Compressed extension is now turned on by default.
    o External GCC 7.1 compiler used.
    o _gp renamed to __global_pointer$
    o Compiler -march= string is now in use allowing us to choose
      required extensions (compressed, FPU, atomic, etc).

Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D11800
2017-08-10 14:18:09 +00:00
Ryan Libby
2473c1b145 i386/boot2: -fno-asynchronous-unwind-tables for gcc
The amd64 build of boot2 was failing with gcc 6.3.0 due to being more
than 1 kB too large. It was apparently generating a .eh_frame section
which was not being removed by objcopy -S. The .eh_frame section seems
to be mandatory per the amd64 ABI, but boot2 is compiled for i386 (uses
-m32), and therefore should be optional in this context. Suppress
generation of .eh_frame with the -fno-asynchronous-unwind-tables flag to
gcc. This saves 1348 bytes (the limit is 7680 bytes).

Reviewed by:	dim, imp
Approved by:	markj (mentor)
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D11928
2017-08-09 20:13:49 +00:00
Marcin Wojtas
29a263df94 Update pl310 node in Armada 38x DTS to match the one used in Linux
Since the cache controller nodes fixup is added to the platform code,
this patch aligns it to the Linux device tree representation.

Submitted by: Patryk Duda <pdk@semihalf.com>
Reviewed by: cognet (mentor)
Approved by: cognet (mentor)
Obtained from: Semihalf
Differential Revision: https://reviews.freebsd.org/D11884
2017-08-09 01:31:05 +00:00
Marcin Wojtas
30608f6dd6 Remove clock-frequency properties from Armada 38x timer nodes
Since the timers' base frequency setting is added to the platform code,
this patch removes clock-frequency properties from global
and twd timers, aligning both to the Linux device tree.

Submitted by: Patryk Duda <pdk@semihalf.com>
Reviewed by: cognet (mentor)
Approved by: cognet (mentor)
Obtained from: Semihalf
Differential Revision: https://reviews.freebsd.org/D11882
2017-08-09 01:20:53 +00:00
Marcin Wojtas
f2d9a004fb Restore original /soc ranges on Marvell Armada 38x boards
Because fdt_get_ranges can process now multiple 'ranges' entries,
restoring the ranges from original Linux device trees is possible.

Submitted by: Patryk Duda <pdk@semihalf.com>
Reviewed by: cognet (mentor)
Approved by: cognet (mentor)
Obtained from: Semihalf
Differential Revision: https://reviews.freebsd.org/D11877
2017-08-09 00:51:45 +00:00
Toomas Soome
07672e9c19 libefi/time.c cstyle cleanup
libefi/time.c is mix of different styles, this update does cleanup.
Also fix 0 versus NULL, and zero the tv structure for case we get error
from UEFI firmware.

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

Submitted by: Eric McCorkle
Differential Revision: https://reviews.freebsd.org/D11862
2017-08-04 16:33:36 +00:00