Commit Graph

1815 Commits

Author SHA1 Message Date
Warner Losh
1306a5dc07 stand/libsa: zfs use standard ZFS_EARLY stuff
Now that the minor issues preventing zfs.c from using CFLAGS_EARLY have
been fixed, use that mechanism like everything else that needs the
OpenZFS spl headers. This simplifies things somewhat. Update comments to
document why zfs.c is still special, though in different ways.

Note: We also use the fact that NEED_SOLARIS_BOOLEAN is only defined in
an environment where the solaris compat boolean stuff will be defined
prior to this point (eg, when we're building zfs.c in libsa), but not in
other environments (like when we're building mkimage and stand-alone
boot loaders that don't use libsa). These latter uses should be changed
to use the same ZFS compile env, but aren't as part of this commit.
This has to be done in the same change as the ZFS_EARLY change to not
break zfs.c building for one commit affecting bisectabiltiy.

Sponsored by:		Netflix
Reviewed by:		tsoome, delphij
Differential Revision:	https://reviews.freebsd.org/D35894
2022-07-24 16:53:36 -06:00
Warner Losh
09ace5cefb stand/zfs: Limit flags further for ZFS
Constrain CFLAGS for ZFS: don't add anything globally. Add the includes
to only the files that need them. Add -DHAS_ZSTD_ZFS to zfs.c (which
includes zfsimpl.c which includes zfssubr.c both of which need this
defined). Also add it to efi/boot1/Makefile since zfs_module.c also
includes zfsimple.c.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D35887
2022-07-24 16:53:35 -06:00
Warner Losh
b3f43ee031 stand: Use c99 structure initialization for userboot's host_fsops
Sponsored by:		Netflix
2022-07-24 16:53:35 -06:00
Warner Losh
b7625c2c2c stand: Use c99 structure initialization for gzipfs_fsops
Sponsored by:		Netflix
2022-07-24 16:53:35 -06:00
Warner Losh
9450d9c4e5 stand: Use c99 structure initialization for splitfs_fsops
Sponsored by:		Netflix
2022-07-24 16:53:35 -06:00
Warner Losh
e7d045aa2b stand: Use c99 structure initialization for pkgfs_fsops
Sponsored by:		Netflix
2022-07-24 16:53:35 -06:00
Warner Losh
90a7e556a4 stand: Use c99 structure initialization for nfs_fsops
Sponsored by:		Netflix
2022-07-24 16:53:35 -06:00
Warner Losh
0ad8a113b7 stand: Use c99 structure initialization for bzipfs_fsops
Sponsored by:		Netflix
2022-07-24 16:53:35 -06:00
Warner Losh
12a41918a2 stand: Use c99 structure initialization for ext2fs_fsops
Sponsored by:		Netflix
2022-07-24 16:53:35 -06:00
Warner Losh
c4f4a6c983 stand: Use c99 structure initialization for network device
Use c99 structure init for devsw.

Sponsored by:		Netflix
2022-07-24 16:53:34 -06:00
Warner Losh
bf855d1bf2 stand: Use c99 structure initialization for fwohci device
Use c99 structure init for devsw.

Sponsored by:		Netflix
2022-07-24 16:53:34 -06:00
Warner Losh
4c460aaf83 stand: Use c99 structure initialization for userboot block device
Use c99 structure init for devsw.

Sponsored by:		Netflix
2022-07-24 16:53:34 -06:00
Warner Losh
1e3d1c86bc stand: Use c99 structure initialization for uboot block device
Use c99 structure init for devsw.

Sponsored by:		Netflix
2022-07-24 16:53:34 -06:00
Warner Losh
e72a01f132 stand: Use c99 structure initialization for ofw's block device
Use c99 structure init for devsw.

Sponsored by:		Netflix
2022-07-24 16:53:34 -06:00
Warner Losh
fc5d0d51aa stand: Use c99 structure initialization for kboot's hostdisk device
Use c99 structure init for devsw.

Sponsored by:		Netflix
2022-07-24 16:53:34 -06:00
Warner Losh
143452f760 stand: Use c99 structure initialization for md device
Use c99 structure init for devsw.

Sponsored by:		Netflix
2022-07-24 16:53:34 -06:00
John Baldwin
bb7ddd077c stand geli: Restore include path to LDRSRC.
Various GELI sources need bootstrap.h and disk.h. In theory they
shouldn't need anything outside of libsa, but disk.h and bootstrap.h are
currently required.

This fixes the build with MK_LOADER_ZFS=no.

Obtained from: CheriBSD
Fixes: eaf7aabddc stand: geli CFLAGS tightening
Sponsored by: DARPA
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D35861
2022-07-22 10:08:46 -06:00
John Baldwin
d1fb0e1dc8 stand libsa: Restore include path to LDRSRC for disk.h for filesystems.
In theory they shouldn't need anything outside of libsa, but disk.h and
bootstrap.h are currently required. Future work wil address this issue.

This fixes the build with MK_LOADER_ZFS=no. ZFS's Makefile.inc adds
these flags globally to CFLAGS when it should not. This masked the
problem because the tools/boot/universe.sh didn't build MK_LOADER_ZFS=no
as part of its regressions. Future work will also fix this.

Obtained from: CheriBSD
Fixes: 84bf2bbbec stand: constrain zlib/gzip CFLAGS better
Sponsored by: DARPA
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D35860
2022-07-22 10:08:40 -06:00
Dimitry Andric
e60f6384f9 Adjust parse() definition in boot2 to avoid clang 15 warning
With clang 15, the following -Werror warning is produced:

    stand/i386/boot2/boot2.c:358:6: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]

This is because parse() is declared with a (void) argument list, and
defined with an empty argument list. Make the definition match the
declaration.

MFC after:	3 days
2022-07-15 21:18:28 +02:00
Warner Losh
01c58e7e4f kboot: Pull in constants from Linux's mmap.h api
Define the usual #defines for mmap(2) (with HOST_ prepended) and use
them instead of hard coding constants.

Sponsored by:		Netflix
2022-07-15 12:00:51 -06:00
Warner Losh
2870493f1f kboot: Properly cap number of segments loaded for kexec
Linux has an arbitrary limit of 16 segments. Make sure we don't load too
many.

Sponsored by:		Netflix
2022-07-15 12:00:51 -06:00
Warner Losh
ffb0d016df kboot: Refinements to host_kexec_load
Move kexec_segments to host_syscall.h and pre-pend host_ to it.  Correct
args to host_exec_load.

Sponsored by:		Netflix
2022-07-15 12:00:51 -06:00
Warner Losh
8fa9263f67 kboot: Use #defines for magic reboot constants
Sponsored by:		Netflix
2022-07-15 12:00:51 -06:00
Warner Losh
8138a766b0 kboot: Implement mount(2)
Create a wrapper for the mount system call. To ensure a sane early boot
environment and to gather data we need for kexec, we may need to mount
some special filesystems.

Sponsored by:		Netflix
2022-07-15 12:00:50 -06:00
Warner Losh
a99d47bcaa kboot: Implement mkdir(2)
mkdir() may be needed early in boot to create missing
directories. Provide a syscall wrapper for it.

Sponsored by:		Netflix
2022-07-15 12:00:50 -06:00
Warner Losh
bc84de741d kboot: Implement dup(2)
Early in boot, we need to create the normal stdin/out/err env for the
boot loader to run in. To do that, we need to open the console and
duplicate the file descriptors which requires dup(2). Implement a
wrapper as host_dup.

Sponsored by:		Netflix
2022-07-15 12:00:50 -06:00
Warner Losh
a4ed0eb1aa kboot: Implement symlink(2)
Linux's /dev/fd is implemented inside of /proc/self/fd, so we may need
to create a symlink to it early in boot. "/dev/fd" and "/dev/std*" might
not be strictly required for the boot loader, but should be present for
maximum flexibility.

Sponsored by:		Netflix
2022-07-15 12:00:50 -06:00
Warner Losh
764780294f kboot: Implement getpid(2)
Add host_getpid() so we can know if we're running as init(8) or not.  If
we are, we may chose to do early system setup / sanity operations.

Sponsored by:		Netflix
2022-07-15 12:00:50 -06:00
Warner Losh
76949f503f kboot: Implement munmap(2)
Define host_munmap so we can use it in the x86 code to find things for
the BIOS/CMS boot path and unmap after we find it.

Sponsored by:		Netflix
2022-07-15 12:00:50 -06:00
Warner Losh
a647d4a4d1 kboot: Implement stat(2) and fstat(2) system calls
Implement stat(2) and fstat(2) in terms of newfstatat and newfstat
system calls respectively (assume we have a compat #define when
there's no newfstat and just a regular fstat and do so for ppc).

Snag struct kstat (the Linux kernel stat(2), et al interface) from musl
and attribute properly.

Sponsored by:		Netflix
2022-07-15 12:00:50 -06:00
Warner Losh
ae366d5106 kboot: Add HOST_O_ constants for open, etc
Add the common O_ constants for the open, fcntl, etc system calls. They
are different than FreeBSD's. While they can differ based on
architecture, they are constant for architectures we care about, and
those architectures use the 'generic' version so future architectures
will also work.

Sponsored by:		Netflix
2022-07-15 12:00:50 -06:00
Warner Losh
bf35f00522 kboot: Enhance kboot_getdev to cope with NULLs
Fallback to currdev when NULL is passed in when 'rootdev' is NULL. Other
getdevs do this. Additional features are needed here still, though.

Sponsored by:		Netflix
2022-07-15 12:00:50 -06:00
Warner Losh
edc23ddf9c kboot: Reimplement older system calls in terms of newer ones
aarch64 doesn't have open, just openat, etc. Cope.

Sponsored by:		Netflix
2022-07-15 12:00:49 -06:00
Warner Losh
f5ed1b0f84 kboot: Rework _start
Split _start into _start and _start_c (inspired by musl and the powerpc
impl is copied from there). This allows us to actually get the command
line arguments on all the platforms. We have a very simplified startup
that supports only static linking.

Sponsored by:		Netflix
2022-07-15 12:00:49 -06:00
Warner Losh
c1bbe71104 stand: Remove extra efi.h include
There's nothing EFI specific about this file, so remove including efi.h.

Sponsored by:		Netflix
2022-07-15 12:00:49 -06:00
Toomas Soome
f4ca0fdbe6 loader.efi: faults could try to print out call trace
with grab_faults, we can try to print out the trace of function calls.
Without symbol table, we can not translate addresses to function names,
but even addresses can help to track the bugs.

For loader functions, print out absolute address, so it could be
searched from objdump -d output.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D35433
2022-07-14 15:59:26 +03:00
Warner Losh
4773d3425e stand: Add comments on ZFS build
Add comments describing the weird nesting things we have to do to live
inside the ZFS world. Also fix a stale comment by moving nvlist.c to an
early user.

Sponsored by:		Netflix
2022-07-08 23:01:59 -06:00
Warner Losh
75ad24775b stand: Add blake3 support to boot loader
Add the necessary glue to get blake3 building for the boot loaded as
well as connected to the ZFS system so it is useful.

On some platforms, we create references to blake3_sse2_impl and
blake3_sse41_impl ops structs to utilize SIMD. These aren't present on
x86 (since we dind't ask for them), but are on aarch64 with no
implementation. Since we don't want SIMD in the boot loader, have these
all return 'unsupported' always. This should be fixed upstream to allow
more flexibility in this selection, but for now we use this hack to not
modify the sys/contrib/openzfs with difficult to maintain hacks while
an upstreamable solution is found.

tsoome@ did the implementation bits in sys/cddl/boot, and I did the
Makefile work and the aweful blake3_impl_hack.c.

Co-author:		tsoome@freebsd.org
Sponsored by:		Netflix
Reviewed by:		kevans (earlier version)
Differential Revision:	https://reviews.freebsd.org/D35750
2022-07-08 22:57:59 -06:00
Warner Losh
df76778ad5 stand: delete zstd_shim.c
We no longer need to use this to get zfs_zstd.c compiling, so delete it.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D35750
2022-07-08 22:49:56 -06:00
Warner Losh
119c786f7b stand: Compile zfs_zstd.c directly now
Now that we have the ability to work around all the issues that
zstd_stub.c worked around, compile zfs_std.c directly.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D35750
2022-07-08 22:49:56 -06:00
Warner Losh
b0a337d501 stand: Fix inclusion of sys/blake3.h
sys/blake3.h is not safe to include in a standalone environment. It
assumes, unwisely, that there's only kernel or userland. The userland
choice is bad due to imperfections in how we handle stdlib.h in this
environment (we wind up including the host's stdlib.h, it expects a
standard FreeBSD setup which the gymnastics we've done to create a
OpenSolaris/Illumos-like environment interfere with). Thankfully, in
this case we can just pretend to be the kernel for a little bit by
defining _KERNEL and the undefing it after we exit.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D35750
2022-07-08 22:49:55 -06:00
Warner Losh
faf25f48d6 stand: Work around upstream issues in the standalone environment
There's a number of issues with including zfs_context.h from a
standalone environment. First, sys/uio_imp.h isn't at all safe for this
environment, so define its guard #defines so that its contents are
skipped. Next, there's a problem including string.h to get the mem*
routines, so just define them here. ZFS_MODULE_PARAM_ARGS isn't defined
properly. I had wanted to define it when I was upstreaming changes to
include/os/freebsd/spl/sys/zfs_context.h, but they ran into resistance
so I'm defining that here now (it is also defined in zstd_shim.c, but
that will disappear once the issues it works around are
cleared). Finally, sys/sysmacros.h has to be included now before
sys/atomic.h, but upstream includes it after so include it here so that
the guards make the out-of-order includes in upstream irrelevant.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D35750
2022-07-08 22:49:55 -06:00
Warner Losh
87d3aa5397 stand: For ZFS build, add new directory
OpenZFS is based on having a number of layers of include files that
define things and include the next layer. Insert a later at the start
for files in libsa/zfs/spl so we can override issues with upstream
OpenZFS while we work to get the issues corrected upstream.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D35750
2022-07-08 22:49:55 -06:00
Warner Losh
37dabb06e2 stand: Add comment about CFLAGS pollution
Add a note that veriexec / bearssl builds will pollute the CFLAGS in a
way that's somewhat hard to fix, so I'm just noting it for now.

Sponsored by:		Netflix
2022-07-08 11:47:37 -06:00
Warner Losh
84bf2bbbec stand: constrain zlib/gzip CFLAGS better
Define ZLIB_CFLAGS and use it only for the sources that are in ZLIB or
that include it.

Sponsored by:		Netflix
2022-07-08 11:47:37 -06:00
Warner Losh
59a4cfe03c stand: Confine BZIP defines to bzip files
Sponsored by:		Netflix
2022-07-08 11:47:37 -06:00
Warner Losh
eaf7aabddc stand: geli CFLAGS tightening
Only add -DWEAK_REFS to sha256.c and sha512.c instead of
everything. Remove redundant include that's not needed.
Minor formatting tweak.

Sponsored by:		Netflix
2022-07-08 11:47:36 -06:00
Warner Losh
451ac17a50 stans: Narrow the scope of includes and other flags
CFLAGS+= here affects *ALL* libsa files being built. However, this is
only needed for zfs.c, so define it only for this. Also, use the defines
from defs.mk. Move all the zfs.c include hacks together. Also, move the
-Wformat -Wall warnings that were added to CFLAGS+= to the individual
files instead for the same reason.

Sponsored by:		Netflix
2022-07-08 11:47:36 -06:00
Warner Losh
0e5ac0ad03 stand: Use a for loop for all the common ZSTD files
Also add comments about why we're not using the BMI instructions when
vailable.

Sponsored by:		Netflix
2022-07-08 11:47:36 -06:00
Warner Losh
285f6ab665 stand: Separate out ZSTD sources from ZFS sources
Sponsored by:		Netflix
2022-07-08 11:47:36 -06:00
Warner Losh
f424b167a3 stand: Don't reuse ZFSSRC
ZFSSRC is the top level directory where the ZFS sources come from. Don't
reuse it for a list of ZFS sources. Instead, use ZFS_SRC

Sponsored by:		Netflix
2022-07-08 11:47:36 -06:00
Warner Losh
2753bbe71b amd64/efi: Remove setting hints for rsdp
Given that hints set this way don't work when a static kenv is compiled
into the kernel. acpi.rsdp has been set for this for the past 6 years,
and all kernels in that time have used it in preference to the hints. As
such, we no longer hints.*, so remove them.

Sponsored by:		Netflix
Reviewed by:		jhb
Differential Revision:	https://reviews.freebsd.org/D35634
2022-07-02 08:02:12 -06:00
Warner Losh
37a3df3d61 loader: Set preferred kenv for acpi.rsdp on arm64
Several years ago, x86 moved from using hints to communicate this
information to using the simpler acpi.rsdp variables. If one compiles
static hints into the kernel, then these hints are ignored. We can
remove this when we branch FreeBSD 15. Thought about BURN_BRIDGES
here, but it's too messy.

Sponsored by:		Netflix
Reviewed by:		andrew, jhb
Differential Revision:	https://reviews.freebsd.org/D35632
2022-07-02 08:02:12 -06:00
Alfredo Dal'Ava Junior
5d48fb3b16 loader: fix powerpc* ofw loader
With the introduction of llvm14, the powerpc* loader used on ofw/pseries
for 32 and 64 bit architectures puts the .data.rel.ro section after
.data section. This caused a crash kernel didn't boot. Bisect pointed to
change https://reviews.llvm.org/D111717 but problem could be fixed by
adding a section description to make it appear in the expected order.

This patch is based on discussion at:
        https://github.com/llvm/llvm-project/issues/56306

MFC after:	1 day
Sponsored by:	Instituto de Pesquisas Eldorado (eldorado.org.br)
2022-07-01 12:56:46 -03:00
Albert Jakiela
1323f0aa9c stand/uboot: setup archsw before probing devices
In some cases ubldr would try to mount a disk device before
the archsw struct was filled with functions pointers.
This would result in a NULL pointer derefrence of the arch_getdev field.
Fix that filling the archsw functions earlier.
Note that this matches the EFI behavoiur.

Reviewed by: imp, mw
Sponsored by: Stormshield
Obtained from: Semihalf
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D35670
2022-07-01 13:36:41 +02:00
Ed Maste
a765ac11c5 Remove "All Rights Reserved" from Foundation copyrights
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2022-06-30 10:49:09 -04:00
Warner Losh
d8f3ef8f54 kboot: rename kexec_load to host_kexec_load
And make it match the system call more closely by passing in the proper
args.

Sponsored by:		Netflix
2022-06-27 14:54:45 -06:00
Warner Losh
201c1d0d25 kboot: sort system calls
Sort the system calls. No functional change intended.

Sponsored by:		Netflix
2022-06-27 14:54:45 -06:00
Warner Losh
43ad112b93 kboot: use SYS_kexec_load insteaed of __NR_kexec_load
Make this regular with the rest of the system calls.

Sponsored by:		Netflix
2022-06-27 14:54:45 -06:00
Warner Losh
ce3e4a3a96 kboot: Sort system calls alphabetically
No functional change: sort the system calls alphbetically to make it
easier to add new ones.

Sponsored by:		Netflix
2022-06-27 14:54:45 -06:00
Toomas Soome
e417249016 loader: GELI encrypted disk should still use device name disk
geli_probe_and_attach() does pick geli_devsw structure for
encrypted disks, the implementation depends on device
name "disk" when device type is DEVT_DISK, but geli_devsw is
setting name field "gelidisk".

PR:		264282
Submitted by:	yamagi@yamagi.org
Reported by:	yamagi@yamagi.org
MFC after:	2 weeks
2022-06-20 10:10:14 +03:00
Toomas Soome
e368fb6eb6 userboot is missing vdisk_dev
Add vdisk device support in userboot configuration.

MFC after:	1 week
2022-06-19 21:29:49 +03:00
Toomas Soome
942e52f776 test_diskread(): detect end of the disk
Detect the end of the disk condition. This may happpen when
disk image is truncated and the reads are addressing blocks past
image end.

MFC after:		1 week
Differential Revision:	https://reviews.freebsd.org/D35432
2022-06-19 18:26:22 +03:00
Toomas Soome
a2e02d9d8e loader.efi: fix panic() after BS off
panic() is using multiple services - attempting to read
keyboard, accessing time functions and finally, exiting the loader.

Protect all the accessed listed above. Note, when BS are off,
we really can not just exit the loader, we only can reboot.

MFC after:	1 week
2022-06-19 17:46:35 +03:00
Mark Johnston
9a964ad561 loader: Relax the check in is_kernphys_relocatable()
The check fails in kernels compiled with KASAN because AddressSanitizer
inserts redzones around global variables, so the size of the "kernphys"
symbol is 32 rather than 8.  Thus we fall back to copying even though
it's not necessary.

Simply remove the size check.  I didn't want to extend the symbol size
check since there's no guarantee that AddressSanitizer will always emit
32 bytes for "kernphys".

Reviewed by:	kib
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35448
2022-06-15 11:39:10 -04:00
Gordon Bergling
c44b5e090d stand: Fix a common typo in source code comments
- s/independant/independent/

MFC after:	3 days
2022-06-05 09:49:51 +02:00
Martin Matuska
e3aa18ad71 zfs: merge openzfs/zfs@b9d98453f
Notable upstream pull request merges:
  #12321 Fix inflated quiesce time caused by lwb_tx during zil_commit()
  #13244 zstd early abort
  #13360 Verify BPs as part of spa_load_verify_cb()
  #13452 More speculative prefetcher improvements
  #13466 Expose zpool guids through kstats
  #13476 Refactor Log Size Limit
  #13484 FreeBSD: libspl: Add locking around statfs globals
  #13498 Cancel in-progress rebuilds when we finish removal
  #13499 zed: Take no action on scrub/resilver checksum errors
  #13513 Remove wrong assertion in log spacemap

Obtained from:	OpenZFS
OpenZFS commit:	b9d98453f9
2022-06-03 18:17:53 +02:00
Andrew Turner
0d6600b579 Set mm before passing it to the UEFI firmware
When reading the UEFI memory map we pass in a pointer to the memory to
hold the map. Unfortunately it wasn't initialised before the first use
so clang decided it was undefined behaviour so the entire loop was
removed. This leads to everything in bi_load after this to also be
removed as dead code.

The next function after bi_load in the binary is efi_copy_init. The
above caused us to enter efi_copy_init with a return address of the
start of the function. Because of this it would enter an infinite
loop of calling the function, allocating memory, then returning to
the start of the function.

PR:		264021
2022-05-21 11:45:41 +01:00
Toomas Soome
9cd45772a4 libsa: mark head_errlog feature supported.
head_errlog is new format for errlog, but we do not really
use errlog, so we can just mark it supported, to enable reading
from pool.

MFC after:	1 week
2022-05-21 09:13:06 +03:00
Mark Johnston
e097436cb2 libsa: Make the nvlist implementation more self-contained
Move declarations into a new nvlist.h rather than putting everything in
libzfs.h.  This makes this nvlist code easier to reuse elsewhere.  In
particular, the nvlist implementation in sys/contrib/libnv does not
provide XDR encoding, but this is needed when reading from or writing to
ZFS pools.

Also:
- Remove references to boolean_t.  It has to be a 32-bit int here, so
  just reference the underlying type.
- Add includes needed when compiling the nvlist code outside of stand/.

No functional change intended.

Reviewed by:	tsoome
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35255
2022-05-20 10:35:19 -04:00
Mark Johnston
bcc3148c70 libsa: Fix a bug in nvlist creation
When adding an entry to an nvlist, the data buffer might need to be
resized.  When this happens, the XDR encoder's notion of the buffer size
also needs to be updated, otherwise the operation may erroneously fail.

Reviewed by:	tsoome, imp
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35254
2022-05-20 10:34:43 -04:00
Ed Maste
f70de61e56 loader.efi: add cross-reference to loader(8)
The loader.efi man page describes UEFI-specific loader details, but not
general loader information.

MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
2022-05-18 10:33:20 -04:00
Warner Losh
7df08a14e3 stand: Initial kboot support on amd64
Get amd64 compiling. However, the current kboot supports an old way of
enumerating memory and the new way needs to be incorporated as well. The
powerpc folks could use either, it seems and newer powerpc platforms
need some changes for kboot to work anyway.

This commit includes the linker script, trampoline code to start the new
kernel, Linux system calls and the necessary configuration glue needed
to build the binaries.

This includes a quick hack to get multiboot support, but we need to
really share these defines. The multiiboot2.h is the minimum needed to
build. We have multiboot information in three places now, so a
refactoring is in order.

This should be considered, at best, preliminary and experimental for
anybody wishing to try it out.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D35100
2022-05-01 11:13:39 -06:00
Warner Losh
70b5c4ff48 stand: Install libsa.3
Turns out there is a libsa.3. It's a bit out of date, but we reference
it in a number of places so we should install it. We need to do the DO32
dance because this Makefile is included twice and we don't want it
installing twice.

Sponsored by:		Netflix
2022-04-30 12:52:19 -06:00
Warner Losh
11f49259c8 stand: Change libstand.3 to libsa.3
Changes instances of the non-existant libstand.3 to the more correct,
but also non-existant libsa.3.

Sponsored by:		Netflix
2022-04-30 08:07:52 -06:00
Warner Losh
bd001d86d6 stand: s/libstand/libsa/g to catch up with rename
We renamed libstand to libsa years ago with the move from sys/boot to
stand. Catch up in the comments.

Sponsored by:		Netflix
2022-04-30 07:34:19 -06:00
Kyle Evans
914dc91d12 stand: zfs: handle holes at the tail end correctly
This mirrors dmu_read_impl(), zeroing out the tail end of the buffer and
clipping the read to what's contained by the block that exists.

This fixes an issue that arose during the 13.1 release process; in
13.1-RC1 and later, setting up GELI+ZFS will result in a failure to
boot.  The culprit is this, which causes us to fail to load geom_eli.ko
as there's a residual portion after the single datablk that should be
zeroed out.

PR:		263407
Reviewed by:	tsoome
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D35019
2022-04-21 14:57:24 -05:00
Gordon Bergling
746cc38ec3 libsa: Fix a typo in a panic message
- s/occured/occurred/

MFC after:	3 days
2022-04-20 12:56:52 +02:00
Kyle Evans
660c1892d5 loader: userboot: provide a getsecs() implementation
We don't need it for userboot, but it avoids issues with BIND_NOW, so
just provide it.  time(3) isn't defined but ends up being provided by
libc linked into the host process, which is generally fine.

PR:	262920
Reviewed by:	imp, jhb
MFC after:	3 days
Diferential Revision:	https://reviews.freebsd.org/D34758
2022-04-12 19:33:54 -05:00
Kyle Evans
454630c725 stand: libefi: swap /Pci() printing around
Printing device followed by interface matches, e.g., edk2.  Note that
this is only a fallback, many firmware implementations will provide the
protocol that we'll use to format device paths.

Reviewed by:	imp, tsoome
Sponsored by:	Ampere Computing
Submitted by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D34539
2022-04-12 19:30:30 -05:00
Jens Schweikhardt
8e458a431e Clean up some grammos I left behind. 2022-04-11 20:24:11 +02:00
Jens Schweikhardt
67f5810e07 Correct typos and more precise wording. 2022-04-11 20:16:18 +02:00
Gordon Bergling
49f6a83ed8 stand: Remove a double word in a source code comment
- s/be be/be/

MFC after:	3 days
2022-04-09 09:27:34 +02:00
Jens Schweikhardt
f7b0434d29 Correct a grammo. 2022-04-04 11:00:09 +02:00
Gordon Bergling
ad49d7c54c loader.4th(8): Fix a typo in the manual page
- s/commmand/command/

MFC after:	3 days
2022-04-02 15:11:59 +02:00
Gordon Bergling
2d62a8653d powerpc64: Fix a typo in a source code comment
- s/converion/conversion/

MFC after:	3 days
2022-04-02 10:56:45 +02:00
Gordon Bergling
9cd75b5588 stand: Fix a common typo in source code comments
- s/existance/existence/

MFC after:	3 days
2022-03-28 19:34:30 +02:00
Mateusz Piotrowski
e405ae3097 gptboot.8: Fix a typo and fix lint warnings
MFC after:	3 days
2022-03-18 11:35:04 +01:00
Mateusz Piotrowski
9ecf6e0f9f loader.efi: Improve the manual page
- Add SPDX tag
- Add a files section describing different locations related to the
  loader
- Add an example explaining how to install a new loader.efi to ESP
- Reference uefi(8)

Reviewed by:	tsoome
Reviewed by:	Pau Amma <pauamma@gundo.com>
Reviewed by:	Jose Luis Duran <jlduran@gmail.com>
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D34592
2022-03-18 09:55:13 +01:00
Toomas Soome
9633c3d874 WITHOUT_BOOT build option appears to include stand, failing on libsa
building libsa needs to use -I${LDRSRC} for some files.

PR:		260083
Submitted by:	Ivan Rozhuk
MFC:		1 day
2022-03-17 19:42:05 +02:00
Hans Petter Selasky
a85ff2114c stand/usb: Fix build by declaring missing functions and types.
MFC after:		1 week
Sponsored by:		NVIDIA Networking
2022-03-17 15:26:24 +01:00
Ed Maste
cf8880d52b teken: color #3 is yellow not brown - use TC_YELLOW as the name
The console escape code standard (ECMA-48) specifies color #3 (escape
code 33) as yellow.  A brown console color is an artifact of the VGA
palette, which replaces dim (but not bright) yellow with brown.

Reviewed by:	adrian, imp
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D34531
2022-03-12 09:17:29 -05:00
Ed Maste
e9249ef958 loader: accept "yellow" as a named color
For historical reasons console color number 3 may be either yellow (most
consoles) or brown (VGA palette).  The console escape code standard
uses "yellow", but teken color name constants appear to be based on the
VGA scheme and use TC_BROWN for color 3.  Even so, the palette table
used 50,50,0 as the RGB percentage tuple, resulting in a dim yellow for
framebuffer consoles at the time teken was introduced.

Amusingly, in 19e2ce2d83 the comment on the palette entry was changed
from "brown" to "dark yellow" but the colour itself was changed from
a pure yellow to being somewhat brown.

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2022-03-11 15:22:13 -05:00
Ed Maste
425e57e7a2 loader: support numeric and named bright colors (8-15)
Accept "bright" or "light" prefix for named colors.

For numeric colors, update error message to specify that values 0 to 15
are allowed, and verify that values are in that range.

Reviewed by:	imp, tsoome (both earlier version)
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D34512
2022-03-11 14:20:34 -05:00
Martin Matuska
c03c5b1c80 zfs: merge openzfs/zfs@a86e08941 (master) into main
Notable upstream pull request merges:
  #9078:  log xattr=sa create/remove/update to ZIL
  #11919: Cross-platform xattr user namespace compatibility
  #13014: Report dnodes with faulty bonuslen
  #13016: FreeBSD: Fix zvol_cdev_open locking
  #13019: spl: Don't check FreeBSD rwlocks for double initialization
  #13027: Fix clearing set-uid and set-gid bits on a file when
          replying a write
  #13031: Add enumerated vdev names to 'zpool iostat -v' and
          'zpool list -v'
  #13074: Enable encrypted raw sending to pools with greater ashift
  #13076: Receive checks should allow unencrypted child datasets
  #13098: Avoid dirtying the final TXGs when exporting a pool
  #13172: Fix ENOSPC when unlinking multiple files from full pool

Obtained from:	OpenZFS
OpenZFS commit:	a86e089415
2022-03-08 18:53:02 +01:00
Jens Schweikhardt
e36c256040 Delete a blank that messed up punctuation. 2022-03-05 22:52:52 +01:00
Simon J. Gerraty
e692517517 Handle MODULE_VERBOSE_TWIDDLE in module_verbose_set
If module_verbose is set to a value below MODULE_VERBOSE_TWIDDLE
call twiddle_divisor(UINT_MAX).

This makes more sense here than when we are loading the kernel.

Sponsored by:	Juniper Networks, Inc.
2022-02-23 21:26:41 -08:00
Colin Percival
5c73b3e0a3 Add support for getting early entropy from UEFI
UEFI provides a protocol for accessing randomness. This is a good way
to gather early entropy, especially when there's no driver for the RNG
on the platform (as is the case on the Marvell Armada8k (MACCHIATObin)
for now).

If the entropy_efi_seed option is enabled in loader.conf (default: YES)
obtain 2048 bytes of entropy from UEFI and pass is to the kernel as a
"module" of name "efi_rng_seed" and type "boot_entropy_platform"; if
present, ingest it into the kernel RNG.

Submitted by:	Greg V
Reviewed by:	markm, kevans
Approved by:	csprng (markm)
MFC after:	3 weeks
Differential Revision:	https://reviews.freebsd.org/D20780
2022-02-17 13:01:11 -08:00
Simon J. Gerraty
01b0c35984 module_verbose should also affect non-ELF modules. 2022-02-14 10:44:46 -08:00
Simon J. Gerraty
ec042f46e9 Add support for module_verbose
Set module_verbose to control the printing of information
about loaded modules and kernel:

0	MODULE_VERBOSE_SILENT	None
1	MODULE_VERBOSE_SIZE	Pathname and size
2	MODULE_VERBOSE_TWIDDLE	as for 1 but also twiddle for progress
3	MODULE_VERBOSE_FULL	extra detail

When the loader is verifying modules we already have a
running indication of progress and module_verbose=0 makes sense.

Reviewed by:	rpokala
Differential Revision:	https://reviews.freebsd.org/D34245
2022-02-13 12:45:57 -08:00
Dimitry Andric
74f7afdfd2 Disable clang 14 warning about bitwise operators in one more place
Follow up 5f2aca8394, where I missed the -Werror warning still being
emitted in libsa.

Fixes:		5f2aca8394
MFC after:	3 days
2022-02-10 19:48:31 +01:00
Warner Losh
27e64c99e4 stand/uboot: Fix building of ubldr.bin
Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D34189
2022-02-07 13:14:48 -07:00
John Baldwin
8bd5e2f15c stand/efi: Pass --no-dynamic-linker to ld.bfd >= 2.34.
ld.bfd in binutils 2.34+ now reports an error in more cases for custom
ldscripts that do not place PHDRs in a LOAD segment.  However, EFI
binaries are not dynamic binaries which need PHDRs, so pass
--no-dynamic-linker to disable this check.

Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D34124
2022-02-02 12:18:43 -08:00
Ed Maste
6f6fbfa3a8 Remove quotes around Makefile .error/.warn/.info strings
The text after .error et al is emitted verbatim.

Reviewed by:	sjg
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33904
2022-01-22 14:03:07 -05:00
John Baldwin
c7721958ff geliboot: Use the correct IV length for AES-XTS.
- Use AES_XTS_IV_LEN instead of the key length as the IV length.
- Use G_ELI_IVKEYLEN as the size of the zeroed iv[] array in
  g_eli_crypto_cipher() to match geli_io().

PR:		261172
Reported by:	Malcolm Matalka <mmatalka@gmail.com>, mikael
Reviewed by:	markj
Sponsored by:	FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33884
2022-01-13 17:19:54 -08:00
John Baldwin
b156362338 geliboot: Use the multi-block functions for AES-XTS.
Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D33530
2022-01-11 14:18:12 -08:00
Emmanuel Vadot
01cad73192 loader: tslog: Add more log for module loading
This helps mesuring what's happening when we load the kernel/modules/mfsroot.

This also adds TSENTER2 which uses the third argument of TSRAW, same
as in the kernel.

MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33699
2022-01-11 09:14:10 +01:00
Warner Losh
44796b7e82 mips: remove saf1761
The saf1761 OTG support was only for mips targets (BERI?). Retire it.

Sponsored by:		Netflix
Reviewed by:		brooks
Differential Revision:	https://reviews.freebsd.org/D33706
2022-01-04 16:01:14 -07:00
Jessica Clarke
5b13fa7987 ufs: Rework shortlink handling to avoid subobject overflows
Shortlinks occupy the space of both di_db and di_ib when used. However,
everywhere that wants to read or write a shortlink takes a pointer do
di_db and promptly runs off the end of it into di_ib. This is fine on
most architectures, if a little dodgy. However, on CHERI, the compiler
can optionally restrict the bounds on pointers to subobjects to just
that subobject, in order to mitigate intra-object buffer overflows, and
this is enabled in CheriBSD's pure-capability kernels.

Instead, clean this up by inserting a union such that a new di_shortlink
can be added with the right size and element type, avoiding the need to
cast and allowing the use of the DIP macro to access the field. This
also mirrors how the ext2fs code implements extents support, with the
exact same structure other than having a uint32_t i_data[] instead of a
char di_shortlink[].

Reviewed by:	mckusick, jhb
Differential Revision:	https://reviews.freebsd.org/D33650
2022-01-02 20:55:36 +00:00
Warner Losh
5974cfe1ba kboot: move to generic syscall interface
Just have the MD code provide syscall and have generic code for the
rest.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D33515
2021-12-30 16:07:20 -07:00
Warner Losh
6497250f6f kboot: Split out powerpc build
Split the powerpc specific parts into kboot/arch/powerpc64. More may be
needed here.

Sponsored by:		Netflix
Reviewed by:		jhibbits
Differential Revision:	https://reviews.freebsd.org/D33514
2021-12-30 16:07:13 -07:00
Warner Losh
4366199644 kboot: Move powerpc kboot to top level
As the first step at making this more generic, move kboot to top level.

Sponsored by:		Netflix
Reviewed by:		luporl, tsoome
Differential Revision:	https://reviews.freebsd.org/D33513
2021-12-30 16:07:06 -07:00
Emmanuel Vadot
dfc9c1d493 loader: tftp: Copy the first block into the cache
tftp_open reads the first block so copy it in the cached data.
If we have more than one block (i.e. we called tftp_read before
tftp_preload) simply just reset the transfer.

Reported by:	mmel
Reviewed by:	mmel, tsoome
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33697
2021-12-30 16:30:13 +01:00
Toomas Soome
221376db0c loader.efi: to preserve heap space, use AllocatePages() for shadow_fb
shadow FB size could be rather large and depends on resolution,
instead of using heap, allocate dedicated space outside of heap.

Reviewed by: manu
Differential Revision: https://reviews.freebsd.org/D33600
MFC after: 2 weeks
2021-12-22 11:39:28 +02:00
Gordon Bergling
b5e0a70193 gfx_fb: Fix a typo in a source code comment
- s/decriptor/descriptor/

MFC after:	3 days
2021-12-22 10:00:42 +01:00
Andrew Turner
c399283c71 Add an loader command on arm64 to sync the cache
On boot we don't need to perform any CPU cache management when the IDC
and DIC fields in the ctr_el0 register are set. Add a command to tell
loader to ignore these fields. This could be useful, for example, if the
hardware is misreporting the values and we are missing a quirk to enable
it.

It is not expected this will be needed, but is only intended as a
workaround to ensure the kernel can still boot.

Sponsored by:	The FreeBSD Foundation
2021-12-20 13:58:36 +00:00
Andrew Turner
c1381f07f6 Don't sync the I/D caches when they are coherent
In the arm64 loader we need to syncronise the I and D caches. On some
newer CPUs the I and D caches are coherent so we don't need to perform
these operations.

While here remove the arguments to cpu_inval_icache as they are unneeded.

Reported by:	cperciva
Tested by:	cperciva
Sponsored by:	Innovate UK
2021-12-20 13:58:13 +00:00
Alexander Motin
02732f945e loader.efi: Do not use as frame buffer BLT-only GOPs.
Kernel needs physical frame buffer address and size, which Block
Transfer-only Graphics Output Protocol instances do not have.

Some recent ASUS boards like PRIME Z690M-PLUS D4 and PRIME H570-Plus
report two GOPs, out of which the second one support ConOut protocol,
that made it preferable, but is BLT-only, that made console unusable.

Discussed with:	tsoome (previous version)
MFC after:	1 week
2021-12-16 11:44:34 -05:00
Emmanuel Vadot
c4dc907254 loader: lua: test that /boot exists first
Otherwise on fs like tftp where no directory listing is possible we fail
on the .dir method.

Reviewed by:	imp, kevans
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33414
2021-12-16 11:50:45 +01:00
Emmanuel Vadot
8ed8b4203a loader: bcache: Fix debug printf
Use %j to it works on 64 and 32 bits system.

Reviewed by:	imp, tsoome
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33430
2021-12-16 11:50:43 +01:00
Emmanuel Vadot
3eb019000c loader: tftp: Add preload method
The preload method will transfer the whole file in a buffer and cache it
so read/lseek operations are faster.

Reviewed by:	imp, tsoome
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33410
2021-12-16 11:50:41 +01:00
Emmanuel Vadot
c25d9aff46 loader: Add preload operation to fs_ops
When we load an ELF file (kernel or module) we do seek(2) a lot to
parse/load the different sections of the ELF file.
Protocol like TFTP suffers a lot from this as there is no resume or
a way to start the tranfer from a specified offset in the file.
fs_preload is added to help those protocol.
Call preload just after opening the ELF file that we need to load so
the underlying method can cache the hole file and then read/lseek operations
are faster.

Reviewed by:	imp
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33409
2021-12-16 11:50:38 +01:00
Emmanuel Vadot
c5f24f5e0d loader: ip: Do not call getsecs so much
getsecs is very costly, reuse the values we got before.

Fetching a ~30MB kernel with the tftp command use to take ~26 seconds
and now it's ~18 seconds.

Reviewed by:	imp, tsoome
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33408
2021-12-16 11:50:36 +01:00
Emmanuel Vadot
4f36ed513c loader: tftp: Don't let tftp timeout
When we load a kernel or module we open/close it a few times.
Since we're using the same port number each time and that we requested
the same file the ACK that we send are valid on the server side and the
server send us the file multiple times.
This makes tftp loading time very inconsistant due to the UDP "flood" that
we have to process.

Reviewed by:	imp, tsoome
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33407
2021-12-16 11:50:34 +01:00
Emmanuel Vadot
70661eaafa loader: Add a readtest command
readtest will simply load the file in memory, useful for timing
loading on some filesystems.

Reviewed by:	tsoome
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33411
2021-12-16 11:50:31 +01:00
Emmanuel Vadot
bf07f2f862 loader: tftp: Don't error on tftp error 0
tftp-hpa sends NAK with tftp error set to 0 when trying to get
a directory and this is the first thing that loader tries to do
and this make it hangs.

Reviewed by:	imp, tsoome
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33406
2021-12-16 11:50:29 +01:00
Warner Losh
f037731345 stand/module: skip is only used by veriexec
Sponsored by:		Netflix
2021-12-15 19:58:33 -07:00
Warner Losh
7a7a464c7e stand/userboot: Kill set but unused variables
We never use 'dev' after fetching it from the varargs list. Skip the
whole bother of fetching it, or setting up the meachinery to fetch it.

Sponsored by:		Netflix
2021-12-15 19:48:40 -07:00
Warner Losh
58e354ec8b stand: netif kill set but unused variables
Sponsored by:		Netflix
2021-12-15 19:44:28 -07:00
Warner Losh
9dc70af83e stand/uboot: reorg
Build uboot ubldr and friends like we build efi binaries
o move everything to be under stand/uboot
o md code goes in arch/$ARCH
o move everything over from the library
  - Had to rename console.c, disk.c and module.c due to conflicts
o update version to 1.5 to reflect the new way of building

This results in a more consistent build system and should represent no
functional change, apart from powerpc version getting new help
file. Also, moved to exlcuding uboot on powerpc64le by using
BROKEN_OPTION instead of the incidental exclusion we had before due to
Makefile reorgs.

Sponsored by:		Netflix
Feedback by:		stevek, jrtc27
Differential Revision:	https://reviews.freebsd.org/D33362
2021-12-14 21:09:53 -07:00
Warner Losh
91d462192d loader: move all gfx_fb.c stubs to common/gfx_fb_stub.c
All these files are the same, modulo one comment. Move them all into
common/gfx_fb_stub.c and adjust Makefiles accordingly.

Sponsored by:		Netflix
Reviewed by:		manu
Differential Revision:	https://reviews.freebsd.org/D33428
2021-12-14 15:27:47 -07:00
Warner Losh
aaaa5a2e68 loader: narrow the scope of gfx frame buffer wrt tg supported kernels
Store whether or not we found a vbefb module (eg, a tg supported kernel)
in the preloaded_file structure. This automatically resets on reload and
eliminates load_elf knowing about any gfx_* interface. Restrict this to
i386, which is the only place it's used. Update libi386 to check in the
preloaded_file struct. Eliminate this from the teken_gfx
structure. Rewrite the parsing code to be more inline. Check this from
the same place we check for a relocatable amd64 kernel.

Sponsored by:		Netflix
Reviewed by:		manu, tsoome
Differential Revision:	https://reviews.freebsd.org/D33427
2021-12-14 15:27:47 -07:00
Warner Losh
0630a06b2a loader/kboot: minor style nit
Kill trailing white space.

Sponsored by:		Netflix
2021-12-13 16:55:39 -07:00
Warner Losh
5c68a21697 loader:prefix is only used for LOADER_VERIEXEC
Only define and set prefix when LOADER_VERIEXEC is defined. It's only
used by the LOADER_VERIEXEC code.

Sponsored by:		Netflix
2021-12-13 12:04:53 -07:00
Toomas Soome
6102f43cf0 loader: framebuffer should only be written into
Reading from Write Combining memory can be very-very slow. Try to use
shadow buffer to avoid such reads.

MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D33305
2021-12-11 13:25:35 +02:00
Warner Losh
20b23ae74b stand: remove mips support
As part of decommissioning mips support, remove the boot loader
support. Do this in advance of other boot loader work to limit the
amount of work that will be thrown away.

Sponsored by:		Netflix
Reviewed by:		jrtc27
Differential Revision:	https://reviews.freebsd.org/D33377
2021-12-10 11:05:31 -07:00
Warner Losh
2220b759d6 loader.mk: Simplify a little bit
The elf loader needs to know how to reach into the gfx_fb code, so
simplify how we include files to find that stuff.

Sponsored by:		Netflix
Reviewed by:		manu, tsoome
Differential Revision:	https://reviews.freebsd.org/D33376
2021-12-10 11:04:37 -07:00
Warner Losh
f953785b3d kboot: remove host_seek
host_llseek has replaced all instances of host_seek, so retire the
latter. It's unused.

Sponsored by:		Netflix
2021-12-09 01:25:41 -07:00
Warner Losh
1d66269db3 kboot: simplify _start
_start can be implemented directly like this. The code generated is
identical. It's also portable.

Reviewed by:	md5
Sponsored by:	Netflix
2021-12-09 01:25:40 -07:00
Gordon Bergling
54c1a65736 ficl: Fix a typo in a comment
- s/segement/segment/

MFC after:	3 days
2021-11-30 10:36:29 +01:00
Warner Losh
77e3db0789 loader: abstract boot services exiting to libefi function
Move direct call of ExitBootServices to efi_exit_boot_services.  This
function sets boot_services_active to false so callers don't have to do
it everywhere (though currently only loader/bootinfo.c is affected).

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D32226
2021-11-21 09:05:07 -07:00
Alfonso
1f629966d6 ANSIify libsa functions
Convert libsa files to use ANSI function definitions.

Pull request: https://github.com/freebsd/freebsd-src/pull/508
[ cut and paste error corrected ]
2021-11-18 22:43:02 -07:00
Emmanuel Vadot
123b5b8763 loader: Do not force comconsole for arm and arm64
This makes GOP not probed on some situation (AMD Card on PCIe slot
with EDK2 as we have a SERIAL_IO_PROTOCOL compatible uart).

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D32992
Sponsored by: Beckhoff Automation GmbH & Co. KG
2021-11-16 10:11:56 +01:00
Emmanuel Vadot
2e0d67c3ed loader: lsefi: Print more information
Printing the EFI_HANDLE pointer isn't very useful.
If the handle have a IMAGE_DEVICE_PATH or a DEVICE_PATH protocol print it.
This makes it easier to see which devices are present and what protocol they
expose.

Reviewed by:	imp, tsoome
Differential Revision:	https://reviews.freebsd.org/D32991
Sponsored by: Beckhoff Automation GmbH & Co. KG
2021-11-16 10:11:53 +01:00
Kirk McKusick
b366ee4868 Consolodate four copies of the STDSB define into a single place.
The STDSB macro is passed to the ffs_sbget() routine to fetch a
UFS/FFS superblock "from the stadard place". It was identically defined
in lib/libufs/libufs.h, stand/libsa/ufs.c, sys/ufs/ffs/ffs_extern.h,
and sys/ufs/ffs/ffs_subr.c. Delete it from these four files and
define it instead in sys/ufs/ffs/fs.h. All existing uses of this macro
already include sys/ufs/ffs/fs.h so no include changes need to be made.

No functional change intended.

Sponsored by: Netflix
2021-11-14 22:10:16 -08:00
Emmanuel Vadot
4c0c353d0e loader: Add more bus name to pnpautoload
Add ofwbus, iicbus and spibus to pnpautoload so modules under those
buses will be loaded.
On my rockpro64 now :
OK pnpautoload -v
Autoloading modules for simplebus
Using DTB provided by EFI at 0x8100000.
Autoloading modules for ofwbus
/boot/kernel/rk_spi.ko text=0x14b2 text=0xd4c data=0x4d0+0x8 syms=[0x8+0xa98+0x8+0x807]
/boot/kernel/dwwdt.ko text=0x12e2 text=0x78c data=0x4c8+0x10 syms=[0x8+0x990+0x8+0x6e1]
Autoloading modules for iicbus
Autoloading modules for spibus
/boot/kernel/mx25l.ko text=0x1613 text=0x114c data=0x6e8+0x8 syms=[0x8+0xa08+0x8+0x665]
loading required module 'fdt_slicer'
/boot/kernel/fdt_slicer.ko text=0x95e text=0x340 data=0x290 syms=[0x8+0x6c0+0x8+0x4a0]
2021-11-14 15:41:30 +01:00
Emmanuel Vadot
d4874307fd loader: Fix pnpload and add some usage
pnpload needs a busname and a compat data.
2021-11-14 15:41:30 +01:00
Emmanuel Vadot
544af629a4 loader: Fix pnpmatch and add some usage
pnpmatch needs a busname and a compat data.
2021-11-14 15:41:30 +01:00
Gordon Bergling
2b0f6ad444 efi(8): Fix a typo in a source code comment
- s/writting/writing/

MFC after:	3 days
2021-11-07 14:07:24 +01:00
Warner Losh
305ef653bc efi: switch boot_services_gone to boot_services_active
Turn the presence or absence of boot services into a positive bool (and
change its type to bool). Move declaration to efi.h in the global
variables section.

Sponsored by:		Netflix

Reviewed by:	tsoome, kib
Differential Revision:	https://reviews.freebsd.org/D31814
2021-11-04 10:07:54 -06:00
Katsuyuki Miyoshi
bb4c691299 lualoader: fix the autoboot_delay countdown message
When the timer drops from double to single digits, a spare 'e' is left
on the end of the line as we don't overwrite it. Include an extra space
at the end to account for this and overwrite the leftover character.

PR:		259429
MFC after:	3 days
Reviewed by:	emaste
2021-10-26 11:24:29 -05:00
Leandro Lupori
a23e18ea54 powerpc64: tell kernel when radix is not available
If CAS detects that radix is not supported, set radix_mmu to 0
to avoid the kernel trying to use it and panic.

MFC after:	2 weeks
Sponsored by:	Instituto de Pesquisas Eldorado (eldorado.org.br)
2021-10-22 13:44:21 -03:00
Leandro Lupori
f83288645c powerpc64le: stand fixes
Fix boot1 and loader on PowerPC64 little-endian (LE).

Due to endian issues, boot1 couldn't find the UFS boot partition
and loader wasn't able to load the kernel. Most of the issues
happened because boot1 and loader were BE binaries trying to access
LE UFS partitions and because loader expects the kernel ELF image
to use the same endian as itself.

To fix these issues, boot1 and loader are now built as LE binaries
on PPC64LE. To support this, the functions that call OpenFirmware
were enhanced to correctly perform endian conversion on its input
and output arguments and to change the CPU into BE mode before
making the calls, as OpenFirmware always runs in BE. Besides that,
some other small fixes were needed.

Submitted by:		bdragon (initial version)
Reviewed by:		alfredo, jhibbits
Sponsored by:		Instituto de Pesquisas Eldorado (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D32160
2021-10-20 15:48:33 -03:00
Toomas Soome
98e805b4a1 loader: net_open() should not replace f->f_devdata
net_open() does replace f_devdata with pointer to netdev_sock,
this will cause memory leak when device is closed, but also does
alter the devopen() logic.

We should store &netdev_sock to dev->d_opendata instead, this
would preserve and follow the devopen() logic.

Fixes network boot on aarch64 (tested by bz).

Reviewed-by:	imp
MFC After:	2 weeks
Differential Revision: https://reviews.freebsd.org/D32227
2021-10-19 19:43:56 +03:00
Leandro Lupori
8ecf9a8bab powerpc64: make radix with superpages default
As Radix MMU with superpages enabled is now stable, make it the
default choice on supported hardware (POWER9 and above), since its
performance is greater than that of HPT MMU.

Reviewed by:		alfredo, jhibbits
Sponsored by:		Instituto de Pesquisas Eldorado (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D30797
2021-10-14 13:13:27 -03:00
Kyle Evans
d586c978b9 stand: fix build after recent opencrypto changes
Pass the ivlen along through, and just drop this KASSERT() if we're
building _STANDALONE for the time being.

Fixes:	1833d6042c ("crypto: Permit variable-sized IVs ...")
2021-10-06 20:23:44 -05:00
Colin Percival
248682a589 loader bcache: Allow readahead up to 256 kB I/Os
Prior to this commit, the loader would perform readaheads of up to
128 kB; when booting on a UFS filesystem this resulted in a series
of 160 kB reads (32 kB request + 128 kB readahead).

This commit allows readaheads to be longer, subject to a total I/O
size limit of 256 kB; i.e. 32 kB read requests will have added
readaheads of up to 224 kB.

In my testing on an EC2 c5.xlarge instance, this change reduces the
boot time by roughly 80 ms.

Reviewed by:	tsoome
MFC after:	1 week
Sponsored by:	https://www.patreon.com/cperciva
Differential Revision:	https://reviews.freebsd.org/D32251
2021-10-03 14:55:10 -07:00
Colin Percival
04b9b7c507 loader bcache: Track unconsumed readahead
The loader bcache attempts to determine whether readahead is useful,
increasing or decreasing its readahead length based on whether a
read could be serviced out of the cache.  This resulted in two
unfortunate behaviours:

1. A series of consecutive 32 kB reads are requested and bcache
performs 16 kB readaheads.  For each read, bcache determines that,
since only the first 16 kB is already in the cache, the readahead
was not useful, and keeps the readahead at the minimum (16 kB) level.

2. A series of consecutive 32 kB reads are requested and bcache
starts with a 32 kB readahead resulting in a 64 kB being read on
the first request.  The second 32 kB request can be serviced out of
the cache, and bcache responds by doubling its readahead length to
64 kB.  The third 32 kB request cannot be serviced out of the cache,
and bcache reduces its readahead length back down to 32 kB.

The first syndrome converts a series of 32 kB reads into a series of
(misaligned) 32 kB reads, while the second syndrome converts a series
of 32 kB reads into a series of 64 kB reads; in both cases we do not
increase the readahead length to its limit (currently 128 kB) no
matter how many consecutive read requests are made.

This change avoids this problem by tracking the "unconsumed
readahead" length; readahead is deemed to be useful (and the
read-ahead length is potentially increased) not only if a request was
completely serviced out of the cache, but also if *any* of the request
was serviced out of the cache and that length matches the amount of
unconsumed readahead.  Conversely, we now only reduce the readahead
length in cases where there was unconsumed readahead data.

In my testing on an EC2 c5.xlarge instance, this change reduces the
boot time by roughly 120 ms.

Reviewed by:	imp, tsoome
MFC after:	1 week
Sponsored by:	https://patreon.com/cperciva
Differential Revision:	https://reviews.freebsd.org/D32250
2021-10-03 14:54:09 -07:00
Colin Percival
b841148bbb loader: Refactor readahead adjustment in bcache
While I'm here, add an explanatory comment.

No functional change intended.

Reviewed by:	imp, tsoome (previous version)
MFC after:	1 week
Sponsored by:	https://patreon.com/cperciva
Differential Revision:	https://reviews.freebsd.org/D32249
2021-10-03 12:10:36 -07:00
Colin Percival
ce73f768b7 EFI loader: Don't free bcache for DEVT_DISK devs
Booting on an EC2 c5.xlarge instance, this reduces the number of I/Os
performed from 609 to 432, reduces the total number of blocks read
from 61963 to 60797, and reduces the time spent in the loader by 39 ms.

Note that b4cb3fe0e3 allowed the bcache to be retained for most of
the boot process, but relies on mounting filesystems; this commit
allows the bcache to be retained at the start of the boot process,
before the root filesystem has been located.

Reviewed by:	imp, tsoome
MFC after:	1 week
Sponsored by:	https://www.patreon.com/cperciva
Differential Revision:	https://reviews.freebsd.org/D32239
2021-09-30 14:48:14 -07:00
Warner Losh
8ea95b2fba loader.efi: remove extra extern ST
The definition for 'ST' is in efilib.h, so we don't need extern ST here.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D32225
2021-09-29 20:07:13 -06:00
Warner Losh
9aa29457d5 loader_lua.8: Fix first version
Lua bindings appeared in FreeBSD 12.0. Delete the authors section of the
man page, since it's unclear who wrote different parts of the man
page.

Noted by:	Trond Endrestol
Sponsored by:	Netflix
2021-09-29 17:18:51 -06:00
Warner Losh
9e1dc7bec3 loader: create separate man pages for each of the loaders
Create a man page per loader. Loader(8) will have information common to
all of them, while loader_${INTERP}(8) will have information relevant to
that specific loader. Rewrite loader(8) to give an overview and point to
the appropriate man page. Rewrite each of the loader_${INTER}(8) man
pages to contain only the relevant information to that loader. Put all
the common commands, environment variables, etc in loader_simp(8) and
refernce that from the loader_lua or loader_4th man pages. The
loader_lua(8) could use more details about the Lua
integration. Additional organization may be benefitial.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D31340
2021-09-29 09:24:47 -06:00
Colin Percival
7457840230 loader: Set twiddle globaldiv to 16 by default
Booting FreeBSD on an EC2 c5.xlarge instance, the loader "twiddles"
810 times over the course of 510 ms, a rate of 1.59 kHz. Even accepting
that many systems are slower than this particular VM and will take
longer to boot (especially if using spinning-rust disks), this seems
like an unhelpfully large amount of twiddling when compared to the
~60 Hz frame rate of many displays; printing the twiddles also consumes
roughly 10% of the boot time on the aforementioned VM.

Setting the default globaldiv to 16 dramatically reduces the time spent
printing twiddles to the console while still twiddling at roughly 100
Hz; this should be ample even for systems which take longer to boot and
consequently twiddle slower.

Note that this can adjusted via the twiddle_divisor variable in
loader.conf, but that file is not processed until nearly halfway
through the loader's runtime.

Reviewed by:	allanjude, jrtc27, kevans
MFC after:	1 week
Sponsored by:	https://www.patreon.com/cperciva
Differential Revision:	<https://reviews.freebsd.org/D32163>
2021-09-28 15:24:02 -07:00
Colin Percival
19e4f2f289 efi loader: Call tslog_init from efi_main
We were calling tslog_init from main; no reason to wait that long.

Fixes:		f49381ccb6 efi/loader: Call tslog_init
Sponsored by:	https://www.patreon.com/cperciva
2021-09-25 12:06:07 -07:00
Colin Percival
0a35c4b3ca loader printf: Profile with TSLOG
Now that the loader tslog code doesn't call printf, we can profile
printf using TSLOG.  On an EC2 c5.xlarge instance, we spend roughly
45 ms here (out of roughly 500 ms), presumably due to the time spent
writing output to the console.

MFC after:	1 week
Sponsored by:	https://www.patreon.com/cperciva
2021-09-24 20:23:49 -07:00
Colin Percival
242923eb84 loader tslog: Don't use sprintf
Instead, append the log entry "manually".

MFC after:	1 week
Sponsored by:	https://www.patreon.com/cperciva
2021-09-24 20:23:37 -07:00
Toomas Soome
1a25c51e38 loader: dev_net.c should use __func__ with printf
We have printf calls with function name hardwired to string,
sometimes wrong name. Use __func__ instead.

MFC after:	1 week
2021-09-24 17:12:19 +03:00
Leandro Lupori
680ca73945 powerpc64: fix loader regression
After b4cb3fe0e3, loader started crashing on PowerPC64, with a
Program Exception (700) error. The problem was that archsw was
used before being initialized, with the new mount feature. This
change fixes the issue by initializing archsw earlier, before
setting currdev, that triggers the mount.

Reviewed by:		tsoome
MFC after:		1 month
X-MFC-With:		b4cb3fe0e3
Sponsored by:		Instituto de Pesquisas Eldorado (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D32027
2021-09-21 17:22:42 -03:00
Mark Johnston
0e3ce6d082 efi loader: Typo
MFC after:	3 days
2021-09-21 12:09:55 -04:00
Colin Percival
5a01dea7e8 style: Fix leading whitespace in bcache.c
MFC after:	2 weeks
X-MFC-with:	Further bcache changes to come
2021-09-19 15:24:00 -07:00
Leandro Lupori
a58abcde2c powerpc64: change CAS to support Radix MMU
Use radix_mmu environment variable to select between Hash or Radix
MMU, when performing the CAS method call. This matches kernel's
behavior, by selecting Hash MMU by default and Radix if radix_mmu
is not zero, to make sure that both loader and kernel always select
the same MMU.

The device tree is queried to detect Radix/GTSE support and to
find out if CAS is supported, making the old CPU version and HV
bit checks unnecessary now.

Reviewed by:		jhibbits
MFC after:		2 weeks
Sponsored by:		Instituto de Pesquisas Eldorado (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D31951
2021-09-15 15:24:40 -03:00
Kyle Evans
ed107537b4 lualoader: use more concise verbiage for autoboot
The behavior remains the same, but lualoader now uses the more concise
verbiage that forthloader used.  This is particularly important because
the previous line would exceed the right boundary of the menu and run
straight into space that would typically be allowed for the logo.

This makes it slightly easier to port logos from forthloader to
lualoader.
2021-09-09 02:01:50 -05:00
Kyle Evans
e19d9a9b6e lualoader: allow brands to specify a shift
Some brands will want to specify a shift to make sure they're properly
centered; let it happen.
2021-09-09 02:01:50 -05:00
Kyle Evans
763bcebe0b lualoader: remove shadowed local from graphics:drawitem()
for loop vars are local already and distinct from this earlier
declaration; remove it.
2021-09-09 02:01:50 -05:00
Toomas Soome
b4cb3fe0e3 loader: implement mount/unmount rootfs
We want to keep our root file system open to preserve bcache segment
between file accesses, thus reducing physical disk IO.

Reviewed by:	imp, allanjude, kevans (previous version)
Differential Revision:	https://reviews.freebsd.org/D30848
MFC after:	1 month
2021-09-08 04:01:20 +03:00
Dimitry Andric
c90cab0d66 i386 loaders: avoid lld 13 garbage collecting linker sets
Because lld 13 and higher default to garbage collecting start/stop
symbols when using --gc-sections, the linker sets used in the i386 boot
loaders will disappear. This leads to the loaders not recognizing any
commands, and failure to boot.

Until we have a good set of linker scripts for the loaders, work around
it by disabling the start-stop-gc feature.

MFC after:	1 week
2021-09-08 14:04:13 +02:00
Toomas Soome
4c7a3a70e0 loader.efi: fix console output after BS off
When Boot Services (BS) are switched off, we can not use BS
functions any more. Since drawn console does implement our own
Blt(), we can use it to draw the console.

However, SimpleTextOutput protocol based console output must be
blocked.

Tested by inserting printf() after ExitBootServices() call.

MFC after:	1 week
2021-09-03 00:48:56 +03:00
Gordon Bergling
005fe24f2a libsa: Fix a typo in source code comments
- s/mininum/minimum/

MFC after:	3 days
2021-08-29 10:09:58 +02:00
Konstantin Belousov
b54eec8366 efi loader: disallow user to configure staging area size less than default
We need to round it up to 2M, for instance.  Having staging area too small
might cause the first resize to use negative size for memmove()/memcpy(),
which kills loader.

Tested by:	Harry Schmalzbauer <freebsd@omnilan.de>
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2021-08-27 19:49:01 +03:00
Konstantin Belousov
b850806921 Restore the definition of EFI_STAGING_SIZE
The definition can be overridden by users, and before f75caed644 it
was in MBs.  Make the symbol' unit MB, to be compatible with users
customizations.

Reported and tested by:	Harry Schmalzbauer <freebsd@omnilan.de>
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2021-08-27 19:48:53 +03:00
Kyle Evans
3daa8e165c pxeboot: improve and simplify rx handling
This pushes the bulk of the rx servicing into a single loop that's only
slightly convoluted, and it addresses a problem with rx handling in the
process.  If we hit a tx interrupt while we're processing, we'd
previously drop the frame on the floor completely and ultimately
timeout, increasing boot time on particularly busy hosts as we keep
having to backoff and resend.

After this patch, we don't seem to hit timeouts at all on zoo anymore
though loading a 27M kernel is still relatively slow (~1m20s).

Reviewed by:	tsoome
Triage by:	Ash Gokhale <ashfixit gmail com>
Sponsored By:	National Bureau of Economic Research
Sponsored by:	Klara, Inc.
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D31512
2021-08-25 21:59:08 -05:00
Konstantin Belousov
6032b6ba95 amd64 UEFI loader: enable automatic disable of staging area copying
Discussed with:	emaste
Sponsored by:	The FreeBSD Foundation
MFC after:	1 month
2021-08-25 22:26:52 +03:00
Toomas Soome
7b0d05d56d loader: loader_lua can run command_more twice
When we quit pager, the return value 1 is returned and command_more()
interprets it as error.

when lua loader gets error from command, it will try to
interpret it once more, so we get the same file shown once more.

There is no reason why we should return error from command_more().

MFC after:	1 week
2021-08-21 21:28:54 +03:00
Toomas Soome
e5a50b0329 loader: FB console does leave garbage on screen while scrolling
Scrolling screen will leave "trail" of chars from first column.
Apparently caused by cursor location mismanagement.
Make sure we do not [attempt to] set cursor out of the screen.

MFC after:	1 week
2021-08-21 19:17:25 +03:00
Maxim Sobolev
0d13f5343f Only trigger read-ahead if two adjacent blocks have been requested.
The change makes block caching algorithm to work better for remote
media on low-BW/high-delay links.

This cuts boot time over IP KVMs noticeably, since the initialization
stage reads bunch of small 4th (and now lua) files that are not in
the same cache stripe (usually), thus wasting lot of bandwidth and
increasing latency even further.

The original regression came in 2017 with revision 87ed2b7f5. We've
seen increase of time it takes for the loader to get to the kernel
loading from under a minute to 10-15 minutes in many cases.

Reviewed by:	tsoome
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D31623
2021-08-20 14:08:01 -07:00
Toomas Soome
3ec0714d6d libsa: cstyle cleanup of dosfs.c
No functional changes intended.

MFC after:	1 week
2021-08-19 17:36:25 +03:00
Gordon Bergling
fa7a635f7e Fix a few typos in source code comments
- s/becase/because/

MFC after:	5 days
2021-08-14 09:06:09 +02:00
Toomas Soome
5d5a621664 loader: cstyle cleanup of userboot/devicename.c
No functional changes intended.

MFC after:	1 week
2021-08-11 10:13:46 +03:00
Roger Pau Monné
5e4279a8f3 loader: fix multiboot loading on UEFI
The Xen kernel has no symbol tables, so calling lookup_symbol against
it triggers the following Divide by Zero fault:

Loading Xen kernel...
/boot/xen data=0x2809c8+0x149638 |
!!!! X64 Exception Type - 00(#DE - Divide Error)  CPU Apic ID - 00000000 !!!!

Fix lookup_symbol to prevent the #DE fault from happening if the
symbol table is not loaded and also fix loadfile_raw to mark multiboot
kernels as relocatable, since the only multiboot kernel supported is
Xen and was already unconditionally booted as relocatable.

Fixes: f75caed644 ('amd64 UEFI loader: stop copying staging area to 2M physical')
Reviewed by: imp, kib
Differential Revision: https://reviews.freebsd.org/D31507
2021-08-12 09:18:33 +02:00
Toomas Soome
97cbd5e722 loader: open file list should be dynamic
Summary:
Open file list is currently created as statically allocated array (64 items).
Once this array is filled up, loader will not be able to operate with files.
In most cases, this mechanism is good enough, but the problem appears, when
we have many disks with zfs pool(s). In current loader implementation, all
discovered zfs pool configurations are kept in memory and disk devices open -
consuming the open file array. Rewrite the open file mechanism to use
dynamically allocated list.

Reviewed by:	imp
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D31364
2021-08-10 21:54:32 +03:00
Warner Losh
879675e9a0 stand: Add MK_PIE=no to defs.mk
There's no need to build both pie and non-pie .o's for stand. There's
some other build thing with MK_BEAR_SSL=yes and/or MK_LOADER_VERIEXEC=yes
that causes the pie build to fail that the 'ar' stage now. Since we don't
need the PIE stuff and the non-PIE stuff, disable PIE for the boot loader.

Reviewed by:	emaste
Sponsored by:	Netflix
2021-08-11 11:03:19 -06:00
Konstantin Belousov
f75caed644 amd64 UEFI loader: stop copying staging area to 2M physical
On amd64, add a possibility to activate kernel with staging area in place.
Add 'copy_staging' command to control this.  For now, by default the
old mode of copying kernel to 2M phys is retained.  It is going to be
changed in several weeks.

On amd64, add some slop to the staging area to satisfy both requirements
of the kernel startup allocator, and to have space for minor staging data
increase after the final size is calculated.  Add a new command
'staging_slop' to control its size.

Improve staging area resizing, in particular, reallocate it anew if
we cannot grow it neither down nor up.

Reviewed by:	kevans, markj
Discussed with:	emaste (the delivery plan)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D31121
2021-08-08 22:52:29 +03:00
Mitchell Horne
61ed578ee6 Prefer MK_SSP=no to SSP_CFLAGS=
It is more idiomatic. CFLAGS is only augmented with $SSP_CFLAGS when
$MK_SSP != "no".

Reviewed by:	imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D31401
2021-08-04 15:23:22 -03:00
Alex Richardson
5e9226f063 Fix build of stand/ when building world with ASAN
The userboot/test  program links against the default userspace libraries
(e.g. shared libgcc_s.so) that will be instrumented if WITH_ASAN is set.
All other programs link against libsa instead of libc and therefore can't
use the sanitizer runtime library. To fix the stand/ build with
sanitizers, we disable MK_ASAN/MK_UBSAN if -nostdlib is found in the
LDFLAGS (i.e. we are using libsa instead of libc).

Reviewed By:	imp, tsoome
Differential Revision: https://reviews.freebsd.org/D31047
2021-08-02 14:33:24 +01:00
Toomas Soome
1b1bb6f178 loader: tftp client should use server address from rootip
servip is set from bootp bp_siaddr (if present) and rootip is
set immediately from servip in tha sane bootp code.

However, the common/dev_net.c does only set rootip (based on
url processing etc). Therefore, we should also use rootip in tftp
reader.

Fixes hung tftp based boot when bp_siaddr is not provided.

MFC after: 1 week
2021-08-02 15:43:54 +03:00
Toomas Soome
bbb539b83c loader: cstyle cleanup of libsa/lseek.c
Clean up lseek.c, no functional changes intended. This is pre-patch
for open file list rewrite.

MFC after:	1 week
2021-08-01 10:11:17 +03:00
Li-Wen Hsu
de0c7fbe28
loader.conf(5): mention "efi" option for "console" parameter
PR:		213467
Reviewed by:	imp
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D31368
2021-08-01 06:41:49 +08:00
Warner Losh
6b51baf6a8 cli.lua.8: make the command match the code
It's disable-device, not device-disable

Spotted by:		jrtc27
Sponsored by:		Netflix
2021-07-28 20:54:14 -06:00
Warner Losh
07c4b78d0a lua loader: Add disable-device to disable a device.
disable-device fooX will set hint.foo.X.disabled=1 as a way to easily
disable a device attaching during boot.

Reviewed by:		tsoome
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D31297
2021-07-28 16:53:00 -06:00
John Hood
dbdf2b52f5 loader: support.4th resets the read buffer incorrectly
Large nextboot.conf files (over 80 bytes) are not read correctly by the
Forth loader, causing file parsing to abort, and nextboot configuration
fails to apply.

Simple repro:

nextboot -e foo=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
shutdown -r now

That will cause the bug to cause a parse failure but shouldn't otherwise
affect the boot.  Depending on your loader configuration, you may also
have to set beastie_disable and/or reduce the number of modules loaded
to see the error on a small console screen.  12.0 or CURRENT users will
also have to explicitly use the Forth loader instead of the Lua loader.
The error will look something like:

Warning: syntax error on file /boot/loader.conf.local
foo="xxxxxxxxxxxxxxnextboot_enable="YES"
                                    ^
/boot/support.4th has crude file I/O buffering, which uses a buffer
'read_buffer', defined to be 80 bytes by the 'read_buffer_size'
constant.  The loader first tastes nextboot.conf, reading and parsing
the first line in it for nextboot_enable="YES".  If this is true, then
it reopens the file and parses it like other loader .conf files.

Unfortunately, the file I/O buffering code does not fully reset the
buffer state in the reset_line_reading word.  If the last file was read
to the end, that doesn't matter; the file buffer is treated as empty
anyway.  But in the nextboot.conf case, the loader will not read to the
end of file if it is over 80 bytes, and the file buffer may be reused
when reading the next file.  When the file is reread, the corrupt text
may cause file parsing to abort on bad syntax (if the corrupt line has
<>2 quotes in it), the wrong variable to be set, no variable to be set
at all, or (if the splice happens to land at a line ending) something
approximating normal operation.

The bug is very old, dating back to at least 2000 if not before, and is
still present in 12.0 and CURRENT r345863 (though it is now hidden by
the Lua loader by default).

Suggested one-line attached.  This does change the behavior of the
reset_line_reading word, which is exported in the line-reading
dictionary (though the export is not documented in loader man pages).
But repo history shows it was probably exported for the PNP support
code, which was never included in the loader build, and was removed 5
months ago.

One thing that puzzles me: how has this bug gone unnoticed/unfixed for
nearly 2 decades?  I find it hard to believe that nobody's tried to do
something interesting with nextboot, like load a kernel and filesystem,
which is what I'm doing.

Tested by:		Gary Jennejohn
PR:			239315
MFC After:		3 weeks
Reviewed by:		imp (and correctly applied this time)
Differential Revision:	https://reviews.freebsd.org/D31328
2021-07-28 13:50:38 -06:00
Warner Losh
4783fb730f Revert "loader: support.4th resets the read buffer incorrectly"
This reverts commit 9c1c02093b. It seems
to have broken all old nextboot.conf files causing hangs on boot.

Sponsored by:		Netflix
2021-07-26 16:40:41 -06:00
Warner Losh
2b720db8d4 type: becauce -> because
Noticed by:	Piotr P. Stefaniak
Sponsored by:	Netflix
2021-07-21 20:03:35 -06:00
Warner Losh
7a0c0ff7ee loader: make sure CPUTYPE is ignored when building
CPUTYPE?=native causes -march=native to be added to the command
line. When the host machine is haswell, this causes some versions of
clang to generate code that can't execute in the efi boot loader
environment. Set _CPUCFLAGS= to undo what's done bsd.cpu.mk. bsd.cpu.mk
is included too early to control with NO_CPU_CFLAGS here. The only other
option is to put that in all the Makefiles, and this is less tedious and
error prone.

PR:			194641
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D31187
MFC After:		1 week
2021-07-14 21:06:19 -06:00
Warner Losh
9873c807da loader: Create loader_simp(8) to document simple version of loader
loader_simp is a much simplified version of loader that will process a
linear sequence of commands from loader.rc. It has neither Forth nor Lua
built in and is much smaller. Document it. This is largely copied from
loader.8 since it implements those built-in commands. Future revisions
will fix this duplication.

Sponsored by:		Netflix
2021-07-14 16:59:51 -06:00
Warner Losh
13c98cd06b loader(8): fix path to be correct loader.4th.
boot.4th was a thing for only a few months around FreeBSD 3.1. The
correct name has been loader.4th for a long time.

MFC After:   		2 days
Sponsored by:		Netflix
2021-07-14 16:34:43 -06:00
Warner Losh
29c8295312 loader: small Makefile style change
Move to using M.${option} and M.yes to collecting man pages to install.

Sponsored by:		Netflix
2021-07-14 08:33:01 -06:00
Emrion
0ca9f1d4a3 Fix pmbr issues > 2TB
These issues have low impact because they require precise circumstances
to trigger one of them. The disk must be > 2 TiB in size and either:
- The primary GPT header is dammaged.
- The freebsd-boot partiton is located farther than the first 2 TiB of
  the disc and one of its sectors takes place at a lba value that makes
  the higher 32 bits of this very value change.
Errors and corrections folow:
- decl and incl don't affect CF, so replace with subl/addl $1
- repe uses %cx, so move size to it with movw
- moving a 64-bit value with %cx of 2 (should be 4) so addresses
  > 2TB will work.

PR:			233180
Reviewed by:		imp@ (applied patch using description in bug)
Differential Revision:	https://reviews.freebsd.org/D31100
2021-07-13 15:40:44 -06:00
Warner Losh
297e9f364b loader: Don't reserve space for symbols twice.
The current code bumps lastaddr twice for the symbol table
location. However, the first bump is bogus and results in wasted
space. Remove it.

PR:			110995
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D31017
2021-07-12 15:30:27 -06:00
Daniel Gerzo
71f6aea415 loader: update autoboot description and move to loader.conf.5
Document "NO" special value for the autoboot_delay and move the
description to loader.conf.5.

imp reworked some of the wording from danger's patch.

Reviewed by:		imp
PR:			85128
Differential Revision:	https://reviews.freebsd.org/D11887
2021-07-12 15:13:03 -06:00
John Hood
9c1c02093b loader: support.4th resets the read buffer incorrectly
Large nextboot.conf files (over 80 bytes) are not read correctly by the
Forth loader, causing file parsing to abort, and nextboot configuration
fails to apply.

Simple repro:

nextboot -e foo=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
shutdown -r now

That will cause the bug to cause a parse failure but shouldn't otherwise
affect the boot.  Depending on your loader configuration, you may also
have to set beastie_disable and/or reduce the number of modules loaded
to see the error on a small console screen.  12.0 or CURRENT users will
also have to explicitly use the Forth loader instead of the Lua loader.
The error will look something like:

Warning: syntax error on file /boot/loader.conf.local
foo="xxxxxxxxxxxxxxnextboot_enable="YES"
                                    ^
/boot/support.4th has crude file I/O buffering, which uses a buffer
'read_buffer', defined to be 80 bytes by the 'read_buffer_size'
constant.  The loader first tastes nextboot.conf, reading and parsing
the first line in it for nextboot_enable="YES".  If this is true, then
it reopens the file and parses it like other loader .conf files.

Unfortunately, the file I/O buffering code does not fully reset the
buffer state in the reset_line_reading word.  If the last file was read
to the end, that doesn't matter; the file buffer is treated as empty
anyway.  But in the nextboot.conf case, the loader will not read to the
end of file if it is over 80 bytes, and the file buffer may be reused
when reading the next file.  When the file is reread, the corrupt text
may cause file parsing to abort on bad syntax (if the corrupt line has
<>2 quotes in it), the wrong variable to be set, no variable to be set
at all, or (if the splice happens to land at a line ending) something
approximating normal operation.

The bug is very old, dating back to at least 2000 if not before, and is
still present in 12.0 and CURRENT r345863 (though it is now hidden by
the Lua loader by default).

Suggested one-line attached.  This does change the behavior of the
reset_line_reading word, which is exported in the line-reading
dictionary (though the export is not documented in loader man pages).
But repo history shows it was probably exported for the PNP support
code, which was never included in the loader build, and was removed 5
months ago.

One thing that puzzles me: how has this bug gone unnoticed/unfixed for
nearly 2 decades?  I find it hard to believe that nobody's tried to do
something interesting with nextboot, like load a kernel and filesystem,
which is what I'm doing.

PR: 239315
Reviewed by: imp
2021-07-11 08:47:29 -06:00
Emmanuel Vadot
b464c459ea loader: Fix dtb loading
When calling file_findfile with only a type it returns
the first file matching the type. But in fdt_apply_overlays we
then iterate on the next files and try loading them as dtb overlays.
Fix this by checking the type one more time.

Sponsored by:	Diablotin Systems
Reported by:	Mark Millard <marklmi@yahoo.com>
2021-07-05 15:53:08 +02:00
Colin Percival
e6caac717b libsa: Add tslog support for arm64
The original code only supported x86 and used rdtsc(); we now also
support arm64 and use the CNTVCT_EL0 special register.
2021-06-23 22:21:23 -07:00
Colin Percival
313724bab9 loader: Use tslog to instrument some functions
In my initial testing, these are the functions which showed up as
being worth instrumenting.  More may be added later.

common/console.c: cons_probe
common/gfx_fb.c: read_list, insert_font, autoload_font
common/interp.c: interact
common/interp_lua.c: interp_init, interp_run
efi/libefi/efipart.c: efipart_readwrite
i386/libi386/biosdisk.c: bd_init, bd_open, bd_edd_io, bd_chs_io, bd_io
libsa/open.c: open
libsa/read.c: read
libsa/twiddle.c: twiddle

Note that profiling interp_run may be of questionable utility as it
may depend on user behaviour (e.g. pressing keys).

Reviewed by:	kevans (earlier version)
2021-06-20 20:09:48 -07:00
Colin Percival
537a44bf28 stand/common command_boot: Pass tslog to kernel
Pass the recorded tslog buffer to the kernel as a "preloaded module".

Reviewed by:	kevans
2021-06-20 20:09:46 -07:00
Colin Percival
f49381ccb6 efi/loader: Call tslog_init
This allows the EFI loader to start recording timestamps.
2021-06-20 20:09:45 -07:00
Colin Percival
c4b65e954f i386/loader: Call tslog_init
This allows the i386 loader to start recording timestamps.

Reviewed by:	kevans
2021-06-20 20:09:44 -07:00
Colin Percival
c8dfc327db stand/common: Add support for timestamp logging (tslog)
This adds tslog_init, which allocates a 2MB buffer for recording
timestamped events; and tslog_publish, which takes the buffer and
passes it to the kernel as a "preloaded module".  These functions
will be used in a later commit.

Reviewed by:	kevans
2021-06-20 20:09:43 -07:00
Colin Percival
e193d3ba33 libsa: Add support for timestamp logging (tslog)
At present this only supports x86, due to the use of the rdtsc
instruction; and is inert unless a buffer is allocated and passed to
the tslog code (which will be done by a future commit).

Reviewed by:	kevans
2021-06-20 20:09:42 -07:00
Colin Percival
60a978bec9 stand/common: Add file_addbuf()
This provides an interface for a memory buffer to be passed from the loader
to the kernel as a "preloaded module".

Reviewed by:	kevans
2021-06-20 20:09:41 -07:00
Mark Johnston
1ea87e2a70 stand: Fix __elfN(loadimage) return value
Caller functions expect __elfN(loadimage) to return a value of zero on
failure and the file size on success.

PR:		256390
Reviewed by:	markj
MFC after:	2 weeks
2021-06-06 16:44:46 -04:00
Andrew Turner
0a0d6ce34d Use the arm virtual counter in the arm64 loader
It exist on all ARMv8+ CPUs, and other boot loaders rely on it being
present.

Sponsored by:	Innovate UK
Differential Revision: https://reviews.freebsd.org/D30410
2021-06-02 10:58:20 +00:00
David Bright
3df4c387d2 libsa: Fix infinite loop in bzipfs & gzipfs
A bug in the loader's bzipfs & gzipfs filesystems caused compressed
kernel and modules not to work on EFI systems with a veriexec-enabled
loader. Since the size of files in these filesystems are not known
_a priori_ `stat` would initialize the size to -1 and the loader would
then hang in an infinite loop while trying to seek (read) to the end
of file since the loop termination condition compares the current
offset to that negative target position.

Reviewers:	vangyzen, imp, Bret Ketchum (Bret.Ketchum@dell.com)
Differential Revision:	https://reviews.freebsd.org/D30414
Sponsored by:	Dell EMC Isilon
MFC to:	     stable/12, stable/13
MFC after:   1 week
2021-06-01 11:08:20 -05:00
Toomas Soome
5365af662c loader: gfx_fb_drawrect should use GfxFbBltVideoFill
The gfx_fb_drawrect() is drawing rectangle by pixels, this can be very
slow on some systems. Use Blt() video fill primitive instead.

Testing done: Tested on mac mini 2012 where the issue was revealed

Reviewed by:	yuripv
MFC after:	1 week
2021-05-16 11:22:37 +03:00
Andrew Turner
93f7be080f Update the EFI timer to be called once a second
There is no need to call it evert 10ms when we need 1s granularity.
Update to update the time every second.

Reviewed by:	imp, manu, tsoome
Sponsored by:	Innovate UK
Differential Revision: https://reviews.freebsd.org/D30227
2021-05-12 14:12:34 +00:00
Warner Losh
e713d3a013 boot: fix OBJS to not include BTX's crt0.o
According to comments in the Makefile, to make pxeboot work we need to
have crt0.o first. This is needed because the simplified loader in
pxeboot assumes that the startup code is at offset 0 in this binary. In
normal booting, the start address can be obtained from headers of the
binary, but since pxeboot encodes this as a pure binary, it has no way
of knowing where that is and assumes 0. Added comments to that effect
in the Makefile.

We've done this by adding it to OBJS before all the other .o's are
added. However, there's a problem. This also adds it to the CLEANFILES
variable, which causes it to be removed from multiple places. The
dependencies may also cause it to be re-built at a time that's after
boot2 is built. This causes installs to fail because at install time
boot2 is considered to be out of date and the programs to rebuild it are
no longer in the path.

Cope with this problem by just adding it to LDFLAGS instead.

Glanced at by:		kevans ("I thought that went in ages ago")
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D28876
2021-05-06 13:08:30 -06:00
Eric van Gyzen
eda28feb2e EFI secure boot VECTX related changes
When VECTX is enabled as a kernel option and non-EFI loaders are
built, many reads will fail due to the mis-match of whether
LOADER_VERIEXEC_VECTX or not in readin.h.  Source that includes
bootstrap.h must ensure the kernel option agrees with the compile
time CFLAGS in the various make related files.

Submitted by:	bret_ketchum@dell.com (original revision)
Reviewed by:	sjg, bdrewery, dab, bret_ketchum@dell.com
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D29993
2021-04-30 12:53:45 -05:00
Toomas Soome
4ba91fa073 loader: do not output empty menu title
As we output spaces around the menu title, we should also check,
if the title is actually empty string.

PR:		255299
Submitted by:	Jose Luis Duran
Reported by:	Jose Luis Duran
MFC after:	1 week
2021-04-21 14:50:23 +03:00
Hans Petter Selasky
7497dd5889 Fix build of stand/usb .
MFC after:	1 week
Sponsored by:	Mellanox Technologies // NVIDIA Networking
2021-04-12 16:13:33 +02:00
Yongbo Yao
5984246f96 Loader: support booting OS from memory disk (MD)
Until now, the boot image can be embedded into the loader with
/sys/tools/embed_mfs.sh, and memory disk (MD) is already supported
in loader source. But due to memory disk (MD) driver isn't registered
to the loader yet, the boot image can't be boot from embedded memory
disk.

Reviewed by:	dab, tsoome
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D29512
2021-04-07 13:40:57 -05:00
Warner Losh
42cd37dfbd gptboot.efi: Add man page
Add a man page for gptboot.efi. Describe when and how to use this as it differs
from the BIOS cases. Include cross reference for the preferred method described
in efibootmgr(8) as well as cross links in both gptboot(8) and gptboot.efi(8) to
the other.

This man page was heavily copied from the gptboot.8 man page by Warren Block.
They are different enough to need separate man pages for clarity, but there's
enough similarity that I worry about the duplication. In the really long term,
gptboot(8) will disappear, so having the same info here will help when that
day comes. In the short to medium term, the information is likely to not
change in gptboot(8) and any changes to gptboot.efi(8) will be easier to
make in a separate copy.

loader.efi(8) needs a complete rewrite from scratch, otherwise I'd have
referenced gptboot.efi(8) from there.

Suggetions from:	cress@, mhorne@
Reviewed by:		rpokala@
Differential Revision:	https://reviews.freebsd.org/D29591
2021-04-05 23:57:57 -06:00
Toomas Soome
d36341f7b8 loader: we should support pools without features
nvlist_check_features_for_read() does return error when there
are no features for read.

MFC after: 5 days
2021-04-04 02:01:03 +03:00
Warner Losh
556e66b7b0 luaboot: visible must be a function
Visible needs to be a function. Looks like I tested the wrong thing.
2021-03-31 22:35:52 -06:00
Warner Losh
e7ccd5b418 loader: create a generic vendor sub-menu place holder
Add a dummy vendor menu entry on the main welcome menu. Vendors can override
this in their local.lua file to create whatever sub-menu they need for their
products.

Also fix the adding a 'welcome' entry as well based on a suggestion from Kyle.
Silly option menu code also from Kyle. They seem to work for me, but any
transcription error is likely mine.

Reviewed by: kevans@ (the vendor stuff)
2021-03-31 22:02:02 -06:00
Alex Richardson
59b2caef05 libsa: Remove conflicting .global/.weak directive
LLVM12 complains if you change the symbol binding:
`error: _longjmp changed binding to STB_GLOBAL`
In this case LLVM actually ignored the weak directive and used the
later .global, but GNU as would mark the symbol as weak.
None of the other architectures mark the libsa _setjmp as weak so
just drop this directive.
2021-03-30 14:59:41 +01:00
Toomas Soome
62ffcaab8f loader: insert spaces around menu title
Small visual nit, make menu title more clean

MFC after: 3 days
2021-03-23 09:31:36 +02:00
Alex Richardson
c8c62548bf Don't add -Winline for WARNS=6
This warning is very rarely useful (inline is a hint and not mandatory).
This flag results in many warnings being printed when compiling C++
code that uses the standard library with GCC.

This flag was originally added in back in r94332 but the flag is a no-op
in Clang ("This diagnostic flag exists for GCC compatibility, and has no
effect in Clang"). Removing it should make the GCC build output slightly
more readable.

Reviewed By:	jrtc27, imp
Differential Revision: https://reviews.freebsd.org/D29235
2021-03-22 11:55:45 +00:00
Mark Johnston
7b1b5aad95 stand: Load INIT_ARRAY and FINI_ARRAY sections
This is required for preloading modules into a KASAN-configured kernel.

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2021-03-16 15:01:41 -04:00
Gordon Bergling
5666643a95 Fix some common typos in comments
- occured -> occurred
- normaly -> normally
- controling -> controlling
- fileds -> fields
- insterted -> inserted
- outputing -> outputting

MFC after:	1 week
2021-03-13 18:26:15 +01:00
Toomas Soome
d708f23ebb loader: cursor off should restore display content
When drawing cursor, we should store original display
content because there may be image data we would like to restore
when the cursor is removed.

PR:		254054
Reported by:	Jose Luis Duran
MFC after:	3 days
2021-03-06 12:23:54 +02:00
Toomas Soome
6a3095aa6d loader_4th: brand image is aligned right
With screen border removed, I forgot to update forth brand image
coordinates to avoid image alignment.
2021-03-06 10:59:35 +02:00
Andrew Turner
773fc43fb0 Revert "Split out the loader efifb setup to a new function"
It was broken by a rebase. Revert until it can be fixed.

This reverts commit c8db60c067.
2021-03-03 16:10:12 +00:00
Andrew Turner
c8db60c067 Split out the loader efifb setup to a new function
This makes bi_load_efi_data cleaner to add common acpi setup code.

Reviewed by:	imp, tsoome
Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D28936
2021-03-03 14:18:02 +00:00
Ed Maste
7f72497ef7 libc: Use musl's optimized strchr and strchrnul
Parentheses added to HASZERO macro to avoid a GCC warning, and formatted
with clang-format as we have adopted these and don't consider them
'contrib' code.

Obtained from:	musl (snapshot at commit 4d0a82170a25)
Reviewed by:	kib (libc integration), mjg (both earlier)
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D17630
2021-03-01 21:09:59 -05:00
Toomas Soome
becaac3972 loader: use display pixel density for font autoselection
Calculate font size from 16 density independent pixels (dp) by using:
size = 16 * ppi/160 * display_factor

We are specifying font size 16dp, and assuming 1dp = 160ppi.
Also apply scaling factor 2 (display_factor).

MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D28849
2021-02-27 11:26:02 +02:00
Marcin Wojtas
19cd12a32a Disable PIE for MIPS BERI boot loader
MIPS BERI boot loader is built with -mno-abicalls and -fno-pic
so prevent adding PIE-related build flags.

Fix build after 9a227a2fd6 ("Enable PIE by default on 64-bit architectures")

Obtained from: Semihalf
Sponsored by: Stormshield
2021-02-25 06:41:35 +01:00
Marcin Wojtas
3aa023643e Disable PIE for powerpc bootloaders.
Bootloaders for powerpc are not built as position independent
code. Since bsd.prog.mk is used for building, when PIE is enabled,
the PIE flags are added and that causes the build to fail.
Adding MK_PIE=no stops bsd.prog.mk from adding PIE specific flags.

Submitted by: Dawid Gorecki <dgr@semihalf.com>
Reviewed by: emaste
Obtained from: Semihalf
Sponsored by: Stormshield
Differential Revision: https://reviews.freebsd.org/D28893
2021-02-25 00:26:11 +01:00
Marcin Wojtas
cd992885bc Disable PIE for MIPS ubldr
When performing buildworld for MIPS with PIE enabled, the build fails
with "position-independent code requires '-mabicalls'" message.
-mno-abicalls and -fno-pic flags are explicitly set in MIPS ubldr
makefile, so to work around this problem, set MK_PIE=no for MIPS
ubldr.

Submitted by: Dawid Gorecki <dgr@semihalf.com>
Reviewed by: emaste
Obtained from: Semihalf
Sponsored by: Stormshield
Differential Revision: https://reviews.freebsd.org/D28370
2021-02-25 00:26:11 +01:00
Roger Pau Monné
0eaa97f0e8 stand/multiboot2: fix header length check
Check whether we have reached the end of the buffer using search_size
instead of MULTIBOOT_SEARCH, which is the maximum defined by the
specification, but the file can be shorter than that.

This prevents printing a harmless error message when loading a file
that is smaller than MULTIBOOT_SEARCH.

Sponsored by: Citrix Systems R&D
MFC after: 3 days
Fixes: adda2797eb ('stand/multiboot2: add support for booting a Xen dom0 in UEFI mode')
2021-02-23 16:05:03 +01:00
Roger Pau Monné
ab379c15af stand/multiboot2: fix error message format
Add a missing space in one error message.

Sponsored by: Citrix Systems R&D
MFC after: 3 days
Fixes: adda2797eb ('stand/multiboot2: add support for booting a Xen dom0 in UEFI mode')
2021-02-23 16:04:58 +01:00
Toomas Soome
61c50cbc09 loader: autoload_font will hung loader when there is no local console
If we start with console set to comconsole, the local
console (vidconsole, efi) is never initialized and attempt to
use the data can render the loader hung.

Reported by:	Kamigishi Rei
MFC after: 3 days
2021-02-21 12:45:36 +02:00
Martin Matuska
ba27dd8be8 zfs: merge OpenZFS master-9312e0fd1
Notable upstream changes:
  778869fa1 Fix reporting of mount progress
  e7adccf7f Disable use of hardware crypto offload drivers on FreeBSD
  03e02e5b5 Fix checksum errors not being counted on repeated repair
  64e0fe14f Restore FreeBSD resource usage accounting
  11f2e9a49 Fix panic if scrubbing after removing a slog device

MFC after:	2 weeks
2021-02-22 13:01:17 +01:00
Hans Petter Selasky
d23b583dfd Bump the FreeBSD kernel version in kernel boot shim.
Sponsored by:	Mellanox Technologies // NVIDIA Networking
2021-02-17 16:46:34 +01:00
Roger Pau Monné
97527e9c4f bi_load: only add MODULEP on arches that have it defined
Do not attempt to add MODINFOMD_MODULEP to the kernel medatada on
arches that don't have it defined.

This fixes the build for arches different than amd64 after
7d3259775c.

Sponsored by:	Citrix Systems R&D
Reported by:	lwhsu, arichardson
2021-02-16 16:14:32 +01:00
Roger Pau Monné
adda2797eb stand/multiboot2: add support for booting a Xen dom0 in UEFI mode
Add some basic multiboot2 infrastructure to the EFI loader in order to
be capable of booting a FreeBSD/Xen dom0 when booted from UEFI.

Only a very limited subset of the multiboot2 protocol is implemented
in order to support enough to boot into Xen, the implementation
doesn't intend to be a full multiboot2 capable implementation.

Such multiboot2 functionality is hooked up into the amd64 EFI loader,
which is the only architecture that supports Xen dom0 on FreeBSD.

The options to boot a FreeBSD/Xen dom0 system are exactly the same as
on BIOS, and requires setting the xen_kernel and xen_cmdline options
in loader.conf.

Sponsored by:		Citrix Systems R&D
Reviewed by:		tsoome, imp
Differential revision:	https://reviews.freebsd.org/D28497
2021-02-16 15:26:11 +01:00
Roger Pau Monné
7d3259775c stand/efi: add modulep to kernel metadata
This mirrors the functionality of the BIOS amd64 bi_load function,
that stashes the absolute address of the module metadata. This is
required for booting as a Xen dom0 that does relocate the modulep and
the loaded modules, and thus requires adjusting the offset.

No functional change introduced, further patches will make use of this
functionality for Xen dom0 loading.

Sponsored by:		Citrix Systems R&D
Reviewed by:		imp
Differential revision:	https://reviews.freebsd.org/D28496
2021-02-16 15:26:11 +01:00
Roger Pau Monné
ed87efbe24 stand/efi: allow not exiting boot services
Xen requires that UEFI BootServices are enabled in order to boot, so
introduce a new parameter to bi_load in order to select whether BS
should be exited.

No functional change introduced in this patch, as all current users of
bi_load request BS to be exited. Further changes will make use of this
functionality.

Note the memory map is still appended to the kernel metadata, even
when it could be modified by further calls to the Boot Services, as it
will be used to detect if the kernel has been booted from UEFI.

Sponsored by:		Citrix Systems R&D
Reviewed by:		tsoome, imp
Differential revision:	https://reviews.freebsd.org/D28495
2021-02-16 15:26:10 +01:00
Guangyuan Yang
c90fb7acf0 pxeboot(8): remove antiquated information
While I was there:
- Fix some typos
- Fix an excessive argument "indent" reported by mandoc -Tlint
- Replace a dead link with the one suggested by
  https://www.uefi.org/uefi

Submitted by:	linimon (in part)
Reviewed by:	bcr
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D27774
2021-02-15 22:03:37 +00:00
Toomas Soome
5d8c062fe3 loader_lua: consider userboot console as serial
We use ascii box chars with serial console because we do not know
if terminal can draw unixode box chars. Same problem is about userboot
console.

MFC after: 5 days
2021-02-14 21:49:23 +02:00
Toomas Soome
a26f735858 loader: do not autoselect smaller font than 8x16 with high res display
The VT screen buffer size is calculated based on our default
built in (8x16) font.

With high-resolution display, we want to use at least 8x16 font,
or we will have large unused areas on screen.

MFC after: 1 week
2021-02-09 13:46:58 +02:00
Toomas Soome
96bef2053a loader: remove BORDER_PIXELS
BORDER_PIXELS is left over from picking up the source from illumos
port. Since FreeBSD VT does not use border in terminal size
calculation, there is no reason why should loader use it.

MFC after: 1 week
2021-02-09 13:45:07 +02:00
Toomas Soome
2bd4ff2d89 loader.efi: There are systems without ConOut, also use ConOutDev
Conout does contian the default output device name.
ConOutDev does contain all possible output device names, so we can
use it as fallback, when there is no ConOut.

PR: 253253
2021-02-04 23:29:38 +02:00
Roger Pau Monné
45ecda8ebf stand/amd64: remove unused addr parameter from bi_load64
All callers of bi_load64 pass 0 as the addr parameter, so just remove
it and always calculate the last load address from the module chain.

No functional change.

Sponsored by:		Citrix Systems R&D
Reviewed by:		tsoome, imp
Differential revision:	https://reviews.freebsd.org/D28412
2021-02-01 15:41:26 +01:00
Kyle Evans
b24872cf7b lualoader: position hyphens at the beginning of character classes
According to the Lua 5.4 manual section 6.4.1 ("Patterns"), the interaction
between ranges and classes is not defined and hyphens must be specified at
either the beginning or the end of a set if they are not escaped.

Move all such occurrences to the beginning.

Reported-by:	_parv (twitter)
MFC-after:	3 days
2021-01-31 09:57:59 -06:00
Toomas Soome
d51cc252a0 userboot: provide stub gfx functions
Make sure we have needed functions present, to avoi getting undefined
symbols error(s).

PR: 253088
Reported by: John Kennedy
2021-01-30 21:20:27 +02:00
Kyle Evans
e25ee296c9 stand: lua: enhance lfs.dir() to speed up kernels_autodetect
This eliminates a lot of stat() calls that happen when lualoader renders the
menu with the default settings, and greatly speeds up rendering on my
laptop.

ftype is nil if loader/loader.efi hasn't been updated yet, falling back to
lfs.attributes() to test.

This is technically incompatible with lfs, but not in a particularly
terrible way.

Reviewed-by:	cem
MFC-after:	4 days
Differential Revision:	https://reviews.freebsd.org/D27542
2021-01-29 12:47:29 -06:00
Roger Pau Monné
b6d85a5f51 stand/multiboot: adjust the protocol between loader and kernel
There's a currently ad-hoc protocol to hand off the FreeBSD kernel
payload between the loader and the kernel itself when Xen is in the
middle of the picture. Such protocol wasn't very resilient to changes
to the loader itself, because it relied on moving metadata around to
package it using a certain layout. This has proven to be fragile, so
replace it with a more robust version.

The new protocol requires using a xen_header structure that will be
used to pass data between the FreeBSD loader and the FreeBSD kernel
when booting in dom0 mode. At the moment the only data conveyed is the
offset of the start of the module metadata relative to the start of the
module itself.

This is a slightly disruptive change since it also requires a change
to the kernel which is contained in this patch. In order to update
with this change the kernel must be updated before updating the
loader, as described in the handbook. Note this is only required when
booting a FreeBSD/Xen dom0. This change doesn't affect the normal
FreeBSD boot protocol.

This fixes booting FreeBSD/Xen in dom0 mode after
3630506b9d.

Sponsored by:		Citrix Systems R&D
MFC after:		3 days
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D28411
2021-01-29 15:23:26 +01:00
Andrew Turner
4e76e4c301 Remove obsolete code gated on _ARM_ARCH_*
This is all code only run on ARMv4 and ARMv5. Support for these have
been dropped from FreeBSD.

Differential Revision:	https://reviews.freebsd.org/D28314
2021-01-28 10:41:45 +00:00
Toomas Soome
9b388ac303 loader: unload command should reset tg_kernel_supported in gfx_state
While loading kernel, we check if vt/vbe backend support is included in
kernel and set the tg_kernel_supported flag in gfx_state. unload
command needs to reset this flag to allow next load to perform
this check with new kernel.

Reported by: jhb
2021-01-28 09:52:20 +02:00
Dimitry Andric
6e26189be4 Fix loader detection of vbefb support on !amd64
On i386, after 6c7a932d0b, the vbefb vt
driver was no longer detected by the loader, if any kernel module was
loaded after the kernel itself.

This was caused by the parse_vt_drv_set() function being called multiple
times, resetting the detection flag. (It was called multiple times,
becuase i386 .ko files are shared objects like the kernel proper, while
this is not the case on amd64.)

Fix this by skipping the set_vt_drv_set lookup if vbefb was already
detected.

Reviewed by:	tsoome
2021-01-27 22:28:43 +01:00
Kyle Evans
7012461c9b stand: ensure that the efi directory's dependencies are correct
efi, like the various ${MACHINE} directories, should have a dependency on
the enabled interpreters.

The general rule here is that any top-level directory that has a program at
any depth within that includes loader.mk should add ${INTERP_DEPENDS} added
to its dependencies so that the appropriate ficl/lua bits are ready before
they begin.

Note that the only directories in-tree that require it but will not get it
in a more appropriate manner are i386 (on amd64), efi, and userboot. i386
and userboot are handled explicitly in Makefile.amd64 where they are added
to S.yes.

Reported-by:	bcran
MFC-after:	3 days
2021-01-27 13:02:51 -06:00
Toomas Soome
6c7a932d0b loader: start kernel in text mode when there is no vbefb vt driver
If kernel is built without VT vbefb driver, make sure
we start kernel in text mode.
2021-01-27 01:07:34 +02:00
Kyle Evans
576562856e lualoader: improve loader.conf var processing
lualoader was previously not processing \ as escapes; this commit fixes
that and does better error checking on the value as well.

Additionally, loader.conf had some odd restrictions on values that make
little sense. Previously, lines like:

kernel=foo

Would simply be discarded with a malformed line complaint you might not
see unless you disable beastie.

lualoader tries to process these as well as it can and manipulates the
environment, while forthloader did minimal processing and constructed a
`set` command to do the heavy lifting instead. The lua approach was
re-envisioned from building a `set` command so that we can appropriately
reset the environment when, for example, boot environments change.

Lift the previous restrictions to allow unquoted values on the right hand
side of an expression.  Note that an unquoted value is effectively:

[A-Za-z0-9-][A-Za-z0-9-_.]*

This commit also stops trying to weirdly limit what it can handle in a
quoted value. Previously it only allowed spaces, alphanumeric, and
punctuation, which is kind of weird. Change it here to grab as much as it
can between two sets of quotes, then let processEnvVar() do the needful and
complain if it finds something malformed looking.

My extremely sophisticated test suite is as follows:

<<EOF
X_01_simple_string="simple"
X_02_escaped_string="s\imple"

X_03_unquoted_val=3
X_04_unquoted_strval=simple_test

X_05_subval="${X_03_unquoted_val}"
X_06_escaped_subval="\${X_03_unquoted_val}"

X_07_embedded="truth${X_03_unquoted_val}"
X_08_escaped_embedded="truth\${X_03_unquoted_val}"

X_09_unknown="${unknown_val}"
X_10_unknown_embedded="truth${unknown_val}"

X_11_crunchy="crunch$unknown_val crunch"
X_12_crunchy="crunch${unknown_val}crunch"

Y_01_badquote="te"lol"
Y_02_eolesc="lol\"
Y_02_noteolesc="lol\\"
Y_03_eolvar="lol$"
Y_03_noteolvar="lol\$"
Y_04_badvar="lol${"

exec="echo Done!"
EOF

Future work may provide a stub loader module in userland so that we can
formally test the loader scripts rather than sketchy setups like the above
in conjunction with the lua-* tools in ^/tools/boot.
2021-01-24 13:54:47 -06:00
Toomas Soome
6c789c55c4 loader: create built in font from bold font face
We did replace full version of default font 8x16v with bold, also
use bold version for built in font.
2021-01-23 10:53:30 +02:00
Andrew Turner
f6f0b849fb Reuse the amd64 loader relocation code on arm64
There is no need to keep multiple copies of the relocation code. The
amd64 code works on arm64 with a few small changes to relocation types.

Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D28213
2021-01-20 17:59:38 +00:00
Toomas Soome
4bbfe4bf08 loader: comment on rgb_to_color_index()
Add small comment block about rgb_to_color_index().
2021-01-19 22:15:26 +02:00
Toomas Soome
52e3a7300d loader: handle malloc failures in vbe_init, use consistent naming
Handle malloc failures in vbe_init().

If it should so happen and we do get malloc failure in vbe_init(),
use original mode list.

Replace nitems with nentries to have naming consistency and avoid
confusion with nitems() macro.

Reported by: yuripv, rpokala
2021-01-19 21:58:46 +02:00
Toomas Soome
1caed70c62 loader: update gfx module
Update from illumos review process.
Add more comments, drop memory buffer from blt functions.
2021-01-18 00:15:36 +02:00
Emmanuel Vadot
d002814d6b loader: Use TERM_EMU for arm and arm64
Even if it didn't behave well previously this is fixed.
Tested on: OrangePi One (armv7 u-boot) (serial only and serial + HDMI)
Tested on: Pine64-LTS (aarch64 u-boot) (serial only and serial + HDMI)
Tested on: Honeycomb (aarch64 EDK2) (serial only)

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D28153
2021-01-17 17:44:16 +01:00
Emmanuel Vadot
0f2434ea00 loader: Partial revert of 987eabdc2a
The arm relocation code doesn't not work and make loader not loading
dependancies.

Reported by:	Dr. Rolf Jansen <freebsd-rj@obsigna.com>
2021-01-17 17:41:25 +01:00
Toomas Soome
52ec89a93c loader.efi: commands gop, uga and autoresize should use cached data
We are setting up pointers for gop or uga protocol in
efi_find_framebuffer(), reuse those pointers.
2021-01-17 15:33:48 +02:00
Toomas Soome
9adce1aedd loader.efi: variable 'hlist' is uninitialized
framebuffer.c:481:65: error: variable 'hlist' is uninitialized
2021-01-17 13:46:00 +02:00
Toomas Soome
fb3a792a88 loader.efi: unused variable 'mode'
framebuffer.c:707:8: error: unused variable 'mode' [-Wunused-variable]
        u_int mode;
2021-01-17 13:39:44 +02:00
Toomas Soome
ef698fabe4 loader.efi: handle multiple gop instances
Some systems may provide multiple GOP instances and not all are
bound to hardware. The current loader is picking up the first GOP,
which may not be usable. Instead we load the GOP handle array,
and test every handle to have registered ConOut protocol. If ConOut is
present, we can use this GOP handle to open GOP protocol.
2021-01-17 01:29:35 +02:00
Toomas Soome
3ddf7eade0 loader.efi: Use Blt with gop as default
System with FB address 0x4000000000 does not draw, Blt() is doing fine.
I think, we can assume the Blt will usually work.
2021-01-16 17:39:40 +02:00
Toomas Soome
ad1ebbe5ce loader: create local copy of mode list provided by vbeinfoblock
Apparently some systems do corrupt mode list memory area, so we need
to use local copy instead.
2021-01-16 12:23:22 +02:00
Kyle Evans
994e1f40f6 lualoader: use floor division to get correct type
This fixes the positioning of the "Welcome to FreeBSD" heading, which was
misplaced after the recent update to Lua 5.4. The issue was previously
masked by a compatibility knob in Lua 5.3 that would cause float-tagged
numbers to render faithfully without the decimal component. Lua 5.4 dropped
that and ensures that it always prints a decimal component, even if it has
to append a ".0" to the value.

Standard division produces a "float", floor division (//) can be used to
guarantee an integer. Floating point operations have been completely ripped
out of the liblua compiled for the bootloader, so this is a nop. This is
decidedly better than trying to hack out the float tag entirely.

Reported-by:	mjg, probably others
MFC-after:	3 days
2021-01-15 15:02:38 -06:00
Toomas Soome
0974bfa3a8 loader: do not update palette in text mode (real fix)
Apparently palette update while in text mode, will cause
some adapters to end up with blank display. Previous update had
condition reversed.
2021-01-15 15:43:14 +02:00
Simon J. Gerraty
b14cfecbf0 pkgfs_open: follow symlinks
Caller is not interested in symlinks follow them.
Throw an error if too many links encountered.

Reviewed by:	stevek
Sponsored by:	Juniper Networks
--This line, and those below, will be ignored--
> Description of fields to fill in above:                     76 columns --|
> PR:                       If a GNATS PR is affected by the change.
> Differential Revision:    https://reviews.freebsd.org/D### (*full* phabric URL needed).
> Submitted by:             If someone else sent in the change.
> Reviewed by:              If someone else reviewed your modification.
> Approved by:              If you needed approval for this commit.
> Obtained from:            If the change is from a third party.
> MFC after:                N [day[s]|week[s]|month[s]].  Request a reminder email.
> MFH:                      Ports tree branch name.  Request approval for merge.
> Relnotes:                 Set to 'yes' for mention in release notes.
> Security:                 Vulnerability reference (one per line) or description.
> Sponsored by:             If the change was sponsored by an organization.
> Empty fields above will be automatically removed.

Change-Id: I4ef92ff256f503c620dc5bba79ed93b32cb2330d
2021-01-14 17:33:05 -08:00
Kyle Evans
0495ed398c contrib/lua: update to 5.4.2
Merge commit '0ea45b9cd43ce1247eb3eee9bfd5cee3d19068e7' into main
2021-01-13 23:56:18 -06:00
Toomas Soome
fdaf9cb942 Revert "loader.efi: disable workaround for serial console on non-x86"
This patch is creating some issues, reverting it.

This reverts commit 8b18395487.
2021-01-13 20:18:35 +02:00
Toomas Soome
98c15d4dc2 loader.efi: initial terminal size should base on UEFI terminal size
We do select font based on desired terminal size, we do query
UEFI terminal size with conout->QueryMode(), but by mistake, the fallback
values are used.
2021-01-13 19:05:51 +02:00
Toomas Soome
8b18395487 loader.efi: disable workaround for serial console on non-x86
As efi console is drawn and with functional comconsole driver,
we can use proper terminal emulator on efi framebuffer console.
2021-01-12 13:09:11 +02:00
Toomas Soome
50180d2b52 loader.efi: reworked framebuffer setup
Pass gfx_state to efi_find_framebuffer(), so we can pick between
GOP and UGA in efi_find_framebuffer(), also we can then
set up struct gen_fb in gfx_state from efifb and isolate efi fb data
processing into framebuffer.c.

This change does allow us to clean up efi_cons_init() and reduce
BS->LocateProtocol() calls.

A little downside is that we now need to translate gen_fb back to
efifb in bootinfo.c (for passing to kernel), and we need to add few
-I options to CFLAGS.
2021-01-12 13:07:27 +02:00
Toomas Soome
1a816c7560 loader.efi: efifb_mask_from_pixfmt is missing PixelBltOnly
We are missing way to set RGB masks for BLT only framebuffer.
2021-01-11 21:16:42 +02:00
Toomas Soome
89632acb50 loader: term_image_display() should test screen_buffer
Make sure screen_buffer is not NULL.
2021-01-10 21:59:52 +02:00
Toomas Soome
20fb2ea2c7 loader: really use bold font for vga text mode
8x16v turns out to be too thin and hard to read,
use bold font instead.
2021-01-08 01:24:30 +02:00
Kyle Evans
27e90f70e0 stand: remove bogus dependency from libsa32
libsa32 is independent of libsa, they can build in parallel if needed.
2021-01-07 16:28:21 -06:00
Kyle Evans
e41367e3ae stand: avoid adding fdt SUBDIR_DEPEND if WITHOUT_FDT is set
This unbreaks the efi build if WITHOUT_FDT is set.

Reported by:	peterj
2021-01-07 16:28:20 -06:00
Mateusz Piotrowski
79eca6520e Fix date
It's 2021 already.

Reported by:	delphij
2021-01-07 21:15:26 +01:00
Toomas Soome
1790f5e654 loader: do not update palette in text mode
Apparently palette update while in text mode, will cause
some adapters to end up with blank display.
2021-01-07 17:07:53 +02:00
Mateusz Piotrowski
3efe9b3e77 Fix a couple of typos and formatting issues 2021-01-06 16:19:15 +01:00
Toomas Soome
babda0952f loader: instead of hw.vga.textmode, use screen.textmode
hw.vga.textmode is directing VT VGA backend to use text mode.

The default screen mode for BIOS loader is text, and default
screen mode for VT VGA backend is graphics (unless we are running on
hypervisor or hw.vga.textmode is set to 1). Using hw.vga.textmode
for loader does remove possibility to have graphical mode VT VGA with
text mode loader.

screen.textmode can have possible values "0" to disable text mode,
and "1" to set text mode.
2021-01-06 14:38:55 +02:00
Toomas Soome
31c2bcad7e loader: remove left over call to unsetenv()
We do not touch kern.vt.fb.default_mode.
2021-01-06 14:35:26 +02:00
Toomas Soome
99870c70ba loader: rewrite vidc_install_font
Instead of trying to set reasonable register values, save significant
register values, then prepare for font upload and then restore
registers from saved data.

This seems to fix text mode for most cases where text mode breakage
was reported.
2021-01-06 10:20:04 +02:00
Toomas Soome
58661b3ba9 loader: only use vidc_install_font() with vga controller
If the controller does not support VGA, we should not
touch VGA registers.
2021-01-05 00:49:18 +02:00
Toomas Soome
8c1dda1171 loader: vidc_load_palette() does not need arguments
Remove left over argument from vidc_load_palette.
2021-01-05 00:49:08 +02:00
Toomas Soome
b2a8d7a9b5 loader: fix powerpc build with gfx_fb
Need to add stub data and gfx functions to make linking happy.
2021-01-04 16:57:58 +00:00
Toomas Soome
e24d4e72c0 loader: fix mips build with gfx_fb
Need to add stub data and gfx functions to make linking happy.
2021-01-04 16:57:50 +00:00
Toomas Soome
4f9139397e loader: fix uboot build with gfx_fb
Need to add stub data and gfx functions to make linking happy.
2021-01-03 20:45:37 +02:00
Toomas Soome
a3479cfd22 loader: fix build on non-x86 platforms
Need to build pnglite with all.

Reported by: Herbert J. Skuhra
2021-01-03 00:04:56 +02:00
Toomas Soome
3630506b9d loader: implement framebuffer console
Draw console on efi.
Add vbe framebuffer for BIOS loader (vbe off, vbe on, vbe list,
vbe set xxx).
autoload font (/boot/fonts) based on resolution and font size.
Add command loadfont (set font by file) and
variable screen.font (set font by size). Pass loaded font to kernel.

Export variables:
screen.height
screen.width
screen.depth

Add gfx primitives to draw the screen and put png image on the screen.
Rework menu draw to iterate list of consoles to enamble device specific
output.

Probably something else I forgot...

Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D27420
2021-01-02 21:41:36 +02:00
Eric van Gyzen
670d2ad820 efi loader: fix typos in a comment
...mostly because it's a harmless way to try the shiny new git repo.

Sponsored by:	Dell EMC Isilon
2021-01-01 11:38:39 -06:00
Kyle Evans
8b4c3a03f9 stand: fix WITHOUT_FORTH/WITHOUT_LOADER_LUA build
Previously having ficl/liblua in LIB32LIST with their respective option
turned OFF would be relatively harmless, as we wouldn't act on it unless we
were building the non-32 variant. As of ac5f382a9d, however, these are
now used for dependencies in some cases and must reflect what's actually
going to be built.
2021-01-01 00:22:48 -06:00
Kyle Evans
ac5f382a9d stand: properly declare subdir deps or .WAIT, do parallel build
buildworld already runs the stand build in parallel[1], so make it easier to
identify ordering issues by properly establishing dependencies or adding
.WAIT where needed.

Everything in stand/ relies on libsa, either directly or indirectly, because
libsa build is where the stand headers get installed and it gets linked in
most places.

Interpreters depend on their libs, machine dirs usually depend on top-level
libs that are getting built and at least one of the interpreter flavors.

For i386, order btx/libi386/libfirewire before everything else using a
big-ol-.WAIT hammer. btx is the most common dependency, but the others are
used sporadically. This seems to be where the race reporting on the mailing
list is- AFAICT, the following sequence is happening:

1.) One of the loaders gets built based on stale btx/btxldr
2.) btx/btxldr gets rebuilt
3.) installworld triggers loader rebuild because btx was rebuilt after

This seems like the most plausible explanation, as they've verified system
time and timestamps.

While we're here, let's switch stand/ over to a completely parallel build so
we can work out these kinds of issues in isolation rather than in the middle
of a larger build.

Reviewed by:	bdragon, sjg, tsoome
Tested by:	bdragon (-j1024, no failures, significant speed improvement)
Differential Revision:	https://reviews.freebsd.org/D23411
2020-12-31 11:15:45 -06:00
Kyle Evans
72cf7db3aa lualoader: add loader_conf_dirs support (loader.conf.d)
loader_conf_dirs is the supporting mechanism for the included
/boot/loader.conf.d directory.  When lualoader finishes processing all of
the loader_conf_files it finds after walking /boot/defaults/loader.conf,
it will now check any and all loader_conf_dirs and process files ending
in ".conf" as if they were a loader.conf.

Note that loader_conf_files may be specified in a loader.conf.d config
file, but loader_conf_dirs may *not*. It will only be processed as specified
in /boot/defaults/loader.conf and any loader_conf_files that were loaded
from there.

Reviewed by:	allanjude, freqlabs, rpokala, tsoome
Includes suggestion from:	imp
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D25608
2020-12-31 10:37:05 -06:00
Toomas Soome
2ae5841472 libsa: xdrproc_t should return bool
Since our xdr translation function are returning bool, so should
xdrproc_t.

Issue reported by gcc 10 build.
2020-12-27 23:25:18 +02:00
Kyle Evans
29842cb36e lualoader: fix lua-lint run
luacheck rightfully complains that i is unused in the show-module-options
loop at the end (it was used for some debugging in the process).

We've added a new pager module that's compiled in, so declare that as an
acceptable global.
2020-12-17 18:29:30 +00:00
Kyle Evans
7ed84fa14b lualoader: cli: provide a show-module-options loader command
This effectively dumps everything lualoader knows about to the console using
the libsa pager; that particular lua interface was added in r368591.

A pager stub implementation has been added that just dumps the output as-is
as a compat shim for older loader binaries that do not have lpager. This
stub should be moved into a more appropriate .lua file if we add anything
else that needs the pager.
2020-12-17 18:24:36 +00:00
Warner Losh
4d6047edb6 Drop EFI_STAGING_SIZE back down to 64M
vmware can't cope with anything larger than 64MB. Drop this back to
64MB everywhere but arm.

PR: 251866
MFC After: 1 week
2020-12-17 17:02:09 +00:00
Toomas Soome
d3eae37553 loader: allow loader to accept zfs feature com.delphix:bookmark_written
We do not need to actually read bookmarks, just whitelist this feature.

Reported by:	mjg
2020-12-15 22:37:03 +00:00
Toomas Soome
eba724f361 loader: allow loader to accept zfs feature com.datto:bookmark_v2
We do not need to actually read bookmarks, just whitelist this feature

Reported by:	jpaetzel
2020-12-15 21:48:35 +00:00
Jessica Clarke
f32672272f loader: Ignore the .interp section on RISC-V
Without this we risk having the .interp section be placed earlier in the
file and mess with section offsets; in particular it has been seen to be
placed at the start of the file and cause the PE/COFF header to not be
at address 0. This is the same fix as was done for arm64 in r365578.

Reviewed by:	mhorne, imp
Approved by:	mhorne, imp
Differential Revision:	https://reviews.freebsd.org/D27603
2020-12-14 00:54:05 +00:00
Jessica Clarke
c46f7610d4 loader: Print autoboot countdown immediately, not at 9
For the first second otime and ntime are equal so no message gets
printed. Instead we should print the countdown right from the start,
although we do it at the end of the first iteration so that if a key has
already been pressed then the message is suppressed.

Reviewed by:	imp
Approved by:	imp
Differential Revision:	https://reviews.freebsd.org/D26935
2020-12-14 00:46:24 +00:00
Kyle Evans
0a0d522b36 stand: liblua: add a pager module
This is nearly a 1:1 mapping of the pager API from libsa.  The only real
difference is that pager.output() will accept any number of arguments and
coerce all of them to strings for output using luaL_tolstring (i.e. the
__tostring metamethod will be used).

The only consumer planned at this time is the upcoming "show-module-options"
implementation.

MFC after:	1 week
2020-12-12 21:25:38 +00:00
Kyle Evans
10aeb6cdab lualoader: config: fix module enabled check
A last minute rewrite left this logically wrong; if it's present in
modules_blacklist, then we do not load it.
2020-12-12 14:53:34 +00:00
Kyle Evans
4634bb1f40 lualoader: provide module-manipulation commands
Specifically, we have:
- enable-module
- disable-module
- toggle-module

These can be used to add/remove modules to be loaded or force modules to be
loaded in spite of modules_blacklist. In the typical case, a user is
expected to use them to recover an issue happening due to a module directive
they've added to their loader.conf or because they discover that they've
under-specified what to load.

MFC after:	1 week
2020-12-12 05:57:42 +00:00
Hans Petter Selasky
eb2f5fa4dc Properly define the bool type in the BSD kernel shim.
MFC after:	1 week
Sponsored by:	Mellanox Technologies // NVIDIA Networking
2020-12-07 16:08:31 +00:00
Toomas Soome
9de6a13e0f loader: xdr_array is missing count
The integer arrays are encoded in nvlist as counted array <count, i0, i1...>,
loader xdr_array() is missing the count. This will affect the pool import when
there are hole devices in pool.

Also fix the new data add and print functions.
2020-12-07 11:25:18 +00:00
Hans Petter Selasky
cc7b5411e6 Add missing busdma prototypes for load and unload and implement dummy sync
function for kernel bootloader shim code.

MFC after:	1 week
Sponsored by:	Mellanox Technologies // NVIDIA Networking
2020-12-07 10:51:19 +00:00
Hans Petter Selasky
34602358c0 Tidy up code a bit. Add missing section comments.
No functional change.

MFC after:	1 week
Sponsored by:	Mellanox Technologies // NVIDIA Networking
2020-12-07 10:21:01 +00:00
Conrad Meyer
78599c32ef Add CFI start/end proc directives to arm64, i386, and ppc
Follow-up to r353959 and r368070: do the same for other architectures.

arm32 already seems to use its own .fnstart/.fnend directives, which
appear to be ARM-specific variants of the same thing.  Likewise, MIPS
uses .frame directives.

Reviewed by:	arichardson
Differential Revision:	https://reviews.freebsd.org/D27387
2020-12-05 00:33:28 +00:00
Hans Petter Selasky
abbf48c558 Fix mis-spelled macro in the kernel shim.
MFC after:	1 week
Sponsored by:	Mellanox Technologies // NVIDIA Networking
2020-12-04 16:51:59 +00:00
Hans Petter Selasky
454f1fdec1 Add more macros, types and prototypes for building kernel code into bootloaders.
MFC after:	1 week
Sponsored by:	Mellanox Technologies // NVIDIA Networking
2020-12-04 14:52:41 +00:00
Hans Petter Selasky
1784a6d64a Fix definition of int64_t and uint64_t when long is 64-bit. This gets the kernel
shim code in line with the rest of the kernel, sys/x86/include/_types.h.

MFC after:	1 week
Sponsored by:	Mellanox Technologies // NVIDIA Networking
2020-12-04 14:50:55 +00:00
Toomas Soome
cd56ababd3 ficl: make dump a bit friendlier
would be nice to have dump to output hex and ascii.
2020-12-01 23:07:05 +00:00
Toomas Soome
dba7640e44 ficl: instead of pad, emit can use local variable
Pad in forth is used as "scratchpad" and internal implementations
should not use it. Ficl does not really follow this rule and this can fire back.
emit has no need to use pad, we can use local variable instead.
2020-12-01 22:28:02 +00:00
Maxim Sobolev
fd2ef8ef5a Unobfuscate "KERNLOAD" parameter on amd64. This change lines-up amd64 with the
i386 and the rest of supported architectures by defining KERNLOAD in the
vmparam.h and getting rid of magic constant in the linker script, which albeit
documented via comment but isn't programmatically accessible at a compile time.

Use KERNLOAD to eliminate another (matching) magic constant 100 lines down
inside unremarkable TU "copy.c" 3 levels deep in the EFI loader tree.

Reviewed by:	markj
Approved by:	markj
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D27355
2020-11-25 23:19:01 +00:00
Hans Petter Selasky
a2dd1caade Fix build of USB bootloader code by adding checks for _STANDALONE being defined.
Currently the USB bootloader code is not part of buildworld.

MFC after:	1 week
Sponsored by:	Mellanox Technologies // NVIDIA Networking
2020-11-18 13:22:22 +00:00
Toomas Soome
fc7cf7241f zfsboot: add prototype for main()
Some compilers are complaining about missing prototype.

PR:		251150
Reported by:	markiyan.kushnir@gmail.com
2020-11-15 14:04:27 +00:00
Toomas Soome
3e9f0f1d29 loader: cstyle cleanup of console.c
cstyle cleanup only, no functional changes intended.
2020-11-14 10:56:40 +00:00
Toomas Soome
83a252c6a1 loader: cstyle cleanup of bootstrap.h did miss a bit
correct small issues - misplaced comment and typos.
2020-11-08 09:49:51 +00:00
Toomas Soome
90b307a897 loader: cstyle cleanup of bootstrap.h
No functional changes intended.
2020-11-08 09:35:41 +00:00
Warner Losh
1ef64e3da5 loader: add aarch64 support for zstd
We don't have NEON available in the boot loader, so we have to disable
it. OpenZFS included ZSTD which used the wrong symbol to bring in neon
support. Change to use the code that's been submitted upstream as a
pull request to both.

__ARM_NEON is the proper symbol, defined in ARM C Language Extensions
Release 2.1 (https://developer.arm.com/documentation/ihi0053/d/). Some
sources suggest __ARM_NEON__, but that's the obsolete spelling from
prior versions of the standard.

OpenZFS Pull Request: https://github.com/openzfs/zfs/pull/11055
ZSTD Pull Request: https://github.com/facebook/zstd/pull/2356
2020-10-28 21:18:04 +00:00
Toomas Soome
e416eecbb9 loader: revert r342161 and r342151
We are using asize property from pool label and we do not depend
on partition data to find last two pool labels and to validate LBA for disk IO.

This does allow us to re-enable support for partitionless disk setups.
2020-10-22 20:02:02 +00:00
Michal Meloun
5b5438c6f3 Add 'netserver' command to EFI loader.
In some environments is difficult to access bootp/dhcp
configuration as "standard user". Add a command that allows to set
or display the URI of the network server used as "net:" device.
Currently only tftp and nfs protocols are supported.

Typical usage pattern is:
netserver tftp://192.168.168.1/path_to_obj_dir/arm.armv7/sys/GENERIC/
boot net:kernel

Reviewed by:	imp, kevans
MFC after:	4 weeks
Differential Revision: https://reviews.freebsd.org/D26736
2020-10-14 13:13:14 +00:00
Andrew Turner
b9aa4537b2 Use adrp in the arm64 efi loader
On startup the arm64 efi loaders need to know PC-relative addresses.
Previously we used the adr instruction to find this address, however this
instruction is limited to +/- 1MiB.

Switch to adrp to find the 4k page the address is within and an add to
set the bottom 12 bits. This lets us address +/- 4GiB which should be
large enough for now.

Reported by:	imp
MFC after:	2 weeks
Sponsored by:	Innovate UK
2020-10-13 16:51:05 +00:00
Warner Losh
e694696956 Force __BMI__ experimental instructions off.
The OpenZFS code that uses the BMI instructions is broken. Forcibly
disable them to prevent their use. When enabled, the build breaks.
This fixes the build when compiled for a core with BMI instructions.
This is the same fix committed in r364777, for the same issue.

Submitted by: Jung-uk Kim
2020-10-13 04:37:57 +00:00
Warner Losh
df13933e33 Add back org.freebsd:zstd_compress to features_for_read
This list is the of features that are allowed on the whole pool,
not the list of features that are implemented.
2020-10-13 03:49:12 +00:00
Warner Losh
9257c69b1c Turn off zstd on aarch64
loader support for zstd and zfs doesn't work for aarch64. Disable it
to unbreak the build.
2020-10-13 02:36:16 +00:00