Commit Graph

1815 Commits

Author SHA1 Message Date
Warner Losh
6d645da0d4 stand: Search less agressively for UFS super block
The boot loader should look in the standard places for the UFS
superblock, but not go too far into the speculative realm. Supress
errors about hash being invalid, which will allow us to boot, even when
the superblock looks good, but fails the hash test. This defers any
policy decisions about booting and/or recovery to userland. This also
has the side effect of eliminating some rather spammy messages when UFS
searches devices with filesystems that are not UFS...

Sponsored by:		Netflix
Reviewed by:		mckusick
Differential Revision:	https://reviews.freebsd.org/D36253
2022-08-18 06:41:11 -06:00
Toomas Soome
d98de74405 loader: zfs reader should only store devdesc in f_devdata
Use d_opendata for device specific data.

PR:		265825
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D36202
2022-08-15 21:07:23 +03:00
Jessica Clarke
3179bb2737 stand: Fix a couple of comment typos in f8a199f28f
The commit message documented it as /etc/src.conf but the comment in the
source mentioned the non-existent /etc/loader.conf.

Fixes:	f8a199f28f ("stand: Raise limit to 550,000 bytes for loader")
2022-08-13 20:48:30 +01:00
Kirk McKusick
e688661642 Move the ability to search for alternate UFS superblocks from fsck_ffs(8)
into ffs_sbsearch() to allow use by other parts of the system.

Historically only fsck_ffs(8), the UFS filesystem checker, had code
to track down and use alternate UFS superblocks. Since fsdb(8) used
much of the fsck_ffs(8) implementation it had some ability to track
down alternate superblocks.

This change extracts the code to track down alternate superblocks
from fsck_ffs(8) and puts it into a new function ffs_sbsearch() in
sys/ufs/ffs/ffs_subr.c. Like ffs_sbget() and ffs_sbput() also found
in ffs_subr.c, these functions can be used directly by the kernel
subsystems. Additionally they are exported to the UFS library,
libufs(8) so that they can be used by user-level programs. The new
functions added to libufs(8) are sbfind(3) that is an alternative
to sbread(3) and sbsearch(3) that is an alternative to sbget(3).
See their manual pages for further details.

The utilities that have been changed to search for superblocks are
dumpfs(8), fsdb(8), ffsinfo(8), and fsck_ffs(8). Also, the prtblknos(8)
tool found in tools/diag/prtblknos searches for superblocks.

The UFS specific mount code uses the superblock search interface
when mounting the root filesystem and when the administrator doing
a mount(8) command specifies the force flag (-f). The standalone UFS
boot code (found in stand/libsa/ufs.c) uses the superblock search
code in the hope of being able to get the system up and running so
that fsck_ffs(8) can be used to get the filesystem cleaned up.

The following utilities have not been changed to search for
superblocks: clri(8), tunefs(8), snapinfo(8), fstyp(8), quot(8),
dump(8), fsirand(8), growfs(8), quotacheck(8), gjournal(8), and
glabel(8). When these utilities fail, they do report the cause of
the failure. The one exception is the tasting code used to try and
figure what a given disk contains. The tasting code will remain
silent so as not to put out a slew of messages as it trying to taste
every new mass storage device that shows up.

Reviewed by: kib
Reviewed by: Warner Losh
Tested by:   Peter Holm
Differential Revision: https://reviews.freebsd.org/D36053
Sponsored by: The FreeBSD Foundation
2022-08-13 12:43:40 -07:00
Warner Losh
4f0c9b76cf stand: Only compile decompression routines
We don't need the compress rotuines, nor zstd_opt.c. Remove them.
Expand the number of places we omit code for IN_LIBSA (which are FreeBSD
specific). Due to the agressive optimization, though, this doesn't
reduce the size of the loader. It does reduce the number of 'false
positives' for places to omit to reduce the size as well as reducing the
build time slightly.

Sponsored by:		Netflix
Reviewed by:		tsoome, delphij
Differential Revision:	https://reviews.freebsd.org/D36145
2022-08-12 21:48:18 -06:00
Warner Losh
1482113008 stand: Compile out the extensive superblock diagnostic messages for BIOS loader
The BIOS loader operates in a very constrained environment. The messages
for the super block integrity tests take up about 12k of space. Compile
them out for the BIOS loader, while leaving it intact for all other
loaders that aren't space constrained. These aren't used in the 'super
tiny' *boot* programs, so no adjustment is needed there.

We reply on the fact that (a) i386 doesn't support 32-bit UEFI booting
and (b) LIBSA_CPUARCH is "i386" when building on both i386 and when
we're building the 32-bit libsa32 library.

This saves about 12k of space for this constrained envrionment and will
take a bit of the pressure off some machines where the loader has grown
too big for their BIOS (see comments in i386/loader/Makefile for
details).

Sponsored by:		Netflix
Reviewed by:		mckusick
Differential Revision:	https://reviews.freebsd.org/D36175
2022-08-12 21:48:17 -06:00
Warner Losh
f8a199f28f stand: Raise limit to 550,000 bytes for loader
Raise the limit for /boot/loader to be 550k. The IBM PC imposes a limit
of 640k of RAM below 1MB, which is needed for real mode calls. BTX takes
40k of that. The BIOS takes some amount (25k seems a good "99% take less
than or equal to this" estimate for that, though some systems consume
more). Most typical setups need 25k of stack.  This leaves 550k for
code. We set the limit to 550,000 which gives about an extra 13,000
bytes of buffer for machines that whose setups use a little more stack
or whose BIOS reserves a bit more...

Add this derivation in the Makefile. Also recommend setting LOADERSIZE
lower in /etc/src.conf when the loader has to run on a system whose BIOS
takes up more space, or for a complex setup. Add a recipe for how to
find how much RAM your BIOS uses as well (thanks to jhb@ for the
trick). Network cards that boot via PXE and HBAs with their BIOS enabled
are known to be large consumers of lomem space.

Sponsored by:		Netflix
Reviewed by:		jhb
Differential Revision:	https://reviews.freebsd.org/D36152
2022-08-12 21:47:02 -06:00
Warner Losh
4c8ea3efe7 stand: Go back to a.out format for /boot/loader
Turns out there's two hidden a.out dependencies. pxeldr.S assumes it has
access to the a.out header from /boot/loader and cdboot.S assumes that
/boot/loader is also a.out and doesn't use boot2.

So, go back to making a.out files for these and adjust the size checks
to use ls, but we only need to check loader.bin. Trim the size we check
against by 2,000. The difference in size between loader and loader.bin
is about 3000 bytes, but clang15 produces binaries that are a smidge
bigger so we need to relax the check just a little and accept some
additional risk for the moment.

Add some comments to loader's Makefile about this.

Sponsored by:		Netflix
Reviewed by:		emaste
Differential Revision:	https://reviews.freebsd.org/D36142
2022-08-11 17:29:10 -06:00
Warner Losh
7d72ff9057 stand: Make BIOS loader size limits settable
It's sometimes desirable to override the size limit: It's a soft limit
and there are times we exceed the limit by just a little bit and don't
want the build to fail (or we are hitting runtime failures below the
510,000 byte limit).

Sponsored by:		Netflix
2022-08-11 10:27:17 -06:00
Warner Losh
3623222940 stand: i386_fmtdev can be reduced to devformat
devformat produces the same output as i386_fmtdev, so just use it to
reduce on the dependencies.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D35927
2022-08-11 10:27:17 -06:00
Warner Losh
add8154e45 stand: uboot_fmtdev can be reduced to devformat
devformat produces the same output as uboot_fmtdev, so just use it to
reduce on the dependencies.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D35926
2022-08-11 10:27:17 -06:00
Warner Losh
1e9b23448a stand: userboot_fmtdev can be reduced to devformat
devformat produces the same output as userboot_fmtdev, so just use it to
reduce on the dependencies. In addition, we don't need to use the
incomplete struct userboot_devdesc type, we can use struct devdesc
instead (in fact, there's no userboot_devdesc defined anywhere).

Sponsored by:		Netflix
Reviewed by:		jhb (prior version)
Differential Revision:	https://reviews.freebsd.org/D35925
2022-08-11 10:27:17 -06:00
Warner Losh
1e7a2eb93a stand: efi_fmtdev can be reduced to devformat
devformat produces the same output as efi_fmtdev, so just use it to
reduce on the dependencies.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D35924
2022-08-11 10:27:16 -06:00
Warner Losh
edb26097cb stand: Replace zfs_fmtdev with generic devformat()
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D35973
2022-08-11 10:27:16 -06:00
Warner Losh
654b7837a6 stand: For zfs, set dv_fmtdev to zfs_fmtdev
Add a generic way to get the string representation of a zfs device / mount.

Sponsored by:		Netflix
Reviewed by:		tsoome (prior version)
Differential Revision:	https://reviews.freebsd.org/D35923
2022-08-11 10:27:16 -06:00
Warner Losh
0b3a4a588f stand: Use devformat instead of disk_devfmt
Use devformat instead of disk_devfmt. This allows us to avoid knowing
the details of the device that's underneath us. Remove disk.h include
and the -I${LDRSRC} from the build of ufs.c since they are no longer
needed.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D35922
2022-08-11 10:27:16 -06:00
Warner Losh
ec9f3e776f stand: Use devformat rather than disk_devfmt
Fix layering violation and use devformat to get the string
representation of the device to see if we're mounted yet or not. Remove
added include to pickup disk.h.

Sponsored by:		Netflix
Reviewed by:		tsoome (prior version)
Differential Revision:	https://reviews.freebsd.org/D35919
2022-08-11 10:27:16 -06:00
Warner Losh
ad759c7352 stand: Add disk_fmtdev for dv_fmtdev for all the disk devices
All of the archsw fmtdev functions treat DEVT_DISK as a call to
disk_fmtdev. Set all disks' dv_fmtdev to disk_fmtdev so devformat
will return the same thing.

Sponsored by:		Netflix
Reviewed by:		tsoome (prior version)
Differential Revision:	https://reviews.freebsd.org/D35917
2022-08-11 10:27:16 -06:00
Warner Losh
dc472f6702 stand: Add devformat to return formatted string for a device
Use dv_fmtdev to return a formatted string for a device. If this is a
null pointer, return the device name and unit followed by a colon (eg
disk3:).

Sponsored by:		Netflix
Reviewed by:		tsoome (prior version)
Differential Revision:	https://reviews.freebsd.org/D35916
2022-08-11 10:27:16 -06:00
Warner Losh
4d4b1a298c stand: Add dv_devfmt to return a string represenation of the device
Add a new pointer, dv_devfmt, to allow devices to format themselves. We
will use this to simplify many of the fmtdev functions in the tree as
they are all almost the same, or all are isomorphic to each other.

Sponsored by:		Netflix
Reviewed by:		tsoome (prior version)
Differential Revision:	https://reviews.freebsd.org/D35915
2022-08-11 10:27:16 -06:00
Warner Losh
d2d4e1271b stand: Change zfs_fmtdev to take a struct devdesc *
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D35974
2022-08-11 10:27:15 -06:00
Warner Losh
c32dde3166 stand: Change disk_fmtdev to take a struct devdesc *
We do a number of games with ploymorphism for different types struct
*devdesc. Adjust one place that this affects to take the address of the
base class (most others have void * at the moment). This is more type
safe than a bare void *.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D35914
2022-08-11 10:27:15 -06:00
Warner Losh
f197c0bf3e stand: Move i386_devdesc to a union
Rather than have the magic, hand-crafted fields that have to align with
fields in other structures at the end of i386_devdesc, make it into
anonymous union and adjust the code accordingly. This is safer and
similar to what CAM does.

Sponsored by:		Netflix
Reviewed by:		kevans, tsoome (prior version)
Differential Revision:	https://reviews.freebsd.org/D35965
2022-08-11 10:27:15 -06:00
Warner Losh
bec11d9631 stand: Remove unnecessary include
stdbool.h is implied by stand.h, so remove it.

Sponsored by:		Netflix
2022-08-11 10:27:15 -06:00
Warner Losh
39fdad34e2 stand: impose 510,000 byte limit for /boot/loader and /boot/pxeldr
The BIOS method of booting imposes an absolute limit of 640k for the
size of the program being run due to btx. In practice, this means that
programs larger than about 500kiB will fail in odd ways as the stack /
heap will overflow.

Pick 510,000 as the cutoff line semi-arbitrarily. loader_lua is now
almost too big and we want to break the build when it crosses this
threshold. In my experience, below 500,000 always works, above 520,000
always seems to fail with things getting bad somewhere between 512,000
to 515,000. 510,000 is as close to the line as I think we can go, though
experience may dictate we need to lower this in the future.

This is at-best a stop-breakage until we have a better way to subset the
boot loader for BIOS booting to allow better, more fined-tuned
/boot/loaders for the many different environments they have to run
in. This likely means we'll have a graphical loader than understands a
few filesystmes for installation, and a non-graphical loader that
understands the most filesystems possible for everything else in the
future. Our build infrastructure needs some work before we can do that,
however.

At this late date, it likely isn't worth the efforts to move parts of
the loader into high memory. There's a number of assumptions about where
the stack is, where buffers reside, etc that are fulfilled when it lives
in the first 640k that would need bounce buffers and/or other counter
measures if we were to split it up. All BIOS calls are done in 16-bit
mode with SEG:OFF addresses, requiring them to be in the first 640k of
RAM. And nearly all machines in the last decade can boot with UEFI
(though there's some exceptions, so it isn't worth killing outright
yet).

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D36129
2022-08-10 21:29:20 -06:00
Warner Losh
e2295b9117 stand: i386/amd64: Always use elf format for /boot/loader and pxeldr
The first level boot blocks have understood how to load ELF code since
1999. Switch /boot/loader and /boot/pxeldr over to being ELF format so
that in-tree tools can examine them more closely. In addition, one
could, in theory, now have a 'lo-mem' and a 'hi-mem' segment (though a
lot of work would need to be done with bounce buffers, btx, code segment
marking, etc for an arrangement like that to work).

As far as I can tell, this is the last a.out binary in the tree. There
are several raw binaries left, but everything else is ELF.

Reviewed by:		emaste, kevans
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D36130
2022-08-10 21:28:22 -06:00
Warner Losh
f863970a82 stand: Reduce number of files that need -I${LDRSRC}
geliboot.c and geliboot_crypto.c don't need anything from stand/common,
so remove them from the list of things to add it.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D35921
2022-08-03 11:24:38 -06:00
Warner Losh
4333168b1d stand: Remove unneeded include from geli
bootstrap.h isn't needed at all by geil, so remove it.

Sponsored by:		Netflix
Reviewed by:		tsoome (earlier version)
Differential Revision:	https://reviews.freebsd.org/D35920
2022-08-03 11:24:38 -06:00
Warner Losh
a23c26b2fe stand: use snprintf here
This code was written prior to snprintf being in the then libstand (now
libsa). Since we have it, use it for extra safety. The code already
tries to be safe, but since we have snprintf as well, the added layer of
protection will suffice. The current code reserves 16 bytes (plus a NUL)
at the end for worst case of inet_ntoa, which is still a little
pessimal, but safe from overflow.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D35102
2022-08-03 11:24:38 -06:00
Kirk McKusick
b21582ee03 Add a flags parameter to the ffs_sbget() function that reads UFS superblocks.
Rather than trying to shoehorn flags into the requested superblock
address, create a separate flags parameter to the ffs_sbget()
function in sys/ufs/ffs/ffs_subr.c. The ffs_sbget() function is
used both in the kernel and in user-level utilities through export
to the sbget() function in the libufs(3) library (see sbget(3)
for details). The kernel uses ffs_sbget() when mounting UFS
filesystems, in the glabel(8) and gjournal(8) GEOM utilities,
and in the standalone library used when booting the system
from a UFS root filesystem.

The ffs_sbget() function reads the superblock located at the byte
offset specified by its sblockloc parameter. The value UFS_STDSB
may be specified for sblockloc to request that the standard
location for the superblock be read.

The two existing options are now flags:

UFS_NOHASHFAIL will note if the check hash is wrong but will still
   return the superblock. This is used by the bootstrap code to
   give the system a chance to come up so that fsck can be run to
   correct the problem.

UFS_NOMSG indicates that superblock inconsistency error messages
   should not be printed. It is used by programs like fsck that
   want to print their own error message and programs like glabel(8)
   that just want to know if a UFS filesystem exists on a partition.

One additional flag is added:

UFS_NOCSUM causes only the superblock itself to be returned, but does
   not read in any auxiliary data structures like the cylinder group
   summary information. It is used by clients like glabel(8) that
   just want to check for possible filesystem types. Using UFS_NOCSUM
   skips the superblock checks for csum data which allows superblocks
   that have corrupted csum data to be read and used.

The validate_sblock() function checks that the superblock has not
been corrupted in a way that can crash or hang the system. Unless
the UFS_NOMSG flag is specified, it will print out any errors that
it finds. Prior to this commit, validate_sblock() returned as soon
as it found an inconsistency so would print at most one message.
It now does all its checks so when UFS_NOMSG has not been specified
will print out everything that it finds inconsistent.

Sponsored by: The FreeBSD Foundation
2022-07-30 22:51:38 -07:00
Warner Losh
206203f530 stand: Add a helper 'universe' target
Add a shortcut for invokging ${SRCTOP}/tools/boot/universe.sh by
creating a 'universe' target in src/stand. This will make it easier to
test out all the different combinations of boot loaders that we build.

Sponsored by:		Netflix
2022-07-30 05:01:47 -06:00
Warner Losh
2101541ff1 stand: Move quit command to common commands
Since both EFI and the future kboot will benefit from a 'quit' command,
move it from efi/loader/main.c to common/commands.c. In EFI this command
exits back to the boot loader (which will cause the next BootXXXX in the
BootOrder list to be attempted). In kboot, this will exit back to
whatever called loader.kboot. In uboot this will cause a reset (which
will restart uboot, not quite a simple exit, but will look similar)
and in OFW it will execute OF_exit which should return to the
openfirmware prompt.

Sponsored by:		Netflix
2022-07-30 04:48:35 -06:00
Alfredo Dal'Ava Junior
0df5a06864 loader: fix powerpc64le ofw loader
This is similar to 5d48fb3b16.
With LLVM14 the .data.rel.ro ELF section appears after .data,
making loader behave erractly and kernel is not loaded.
This patch makes ensures the correct order.

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-29 05:13:19 -03:00
Warner Losh
9579540144 kboot: Make console raw when we start
Put the console into raw mode on startup. This allows the menus to work
as expected. Boot is now interruptable.

Note: Likely should restore the terminal settings on most exists.  It's
not clear the best way to do this, and most shells have an auto stty
sane anyway, so note it for future improvement.

Sponsored by:		Netflix
2022-07-28 15:35:42 -06:00
Warner Losh
963037786f kboot: implement stripped down termios
Implement a stripped down termios, obtained from various files in musl
and HOST_ or host_ prepended to most things and a few unavoidable style
tweaks. Only implements the bits of termios we need for the boot loader:
put the terminal into raw mode, restore terminal settings and speed
stuff.

Sponsored by:		Netflix
2022-07-28 15:35:42 -06:00
Warner Losh
54e6e0deb4 kboot: Implement host_ioctl
Sponsored by:		Netflix
2022-07-28 15:35:42 -06:00
Warner Losh
f56d7a73be kboot: Add host_exit and use it to implement exit()
Clients of libsa are expected to implement exit(). The current exit just
loops forever. It is better to really exit: when running as init that
will reboot the system. When not running as init, other programs can
recover (not that we support running as init, but when we do in the
future, this is still the rigtht thing).

Sponsored by: Netflix
2022-07-28 15:35:42 -06:00
Warner Losh
75cbdbc983 kboot: aarch64 support
Add support for aarch64. exec.c and ldscript are copied from the EFI
version with #ifdefs for the differences. Once complete, I'll refactor
them. host_syscall.S implements a generic system call. tramp.S is a
first attempt to create a tramoline that we can use to jump to the
aarch64 kernel. Add aarch64-specific startup and stat files as well.
exec.c tweaked slightly to avoid bringing in bi_load(), which will come
in later. Includes tweaks to stat due to name differences between names
on different Linux architectures.

Sponsored by:		Netflix
2022-07-28 15:35:42 -06:00
Warner Losh
a0c075229f kboot: Move conf.c up to top level
conf.c is the same now between powerpc64 and amd64, so move it up to
kboot. Move powerpc file formats defines to ppc64_elf_freebsd.c

Sponsored by:		Netflix
2022-07-28 15:35:42 -06:00
Warner Losh
309a263fe6 kboot: Remove RELOC defines, it's unused
This was copied from powerpc/ofw and has never been used. We also don't
care about -DAIM. It's only relevant for in-kernel structures, which we
don't use in this userland program.

Sponsored by:		Netflix
2022-07-27 23:11:12 -06:00
Warner Losh
3a1b966ae0 kboot: Convert from getdents to getdents64
Linux 2.4 introduced getdents64. Switch to using it because aarch64
doesn't have getdents as that syscall was obsoleted before that port was
created.

Sponsored by:		Netflix
2022-07-27 22:29:27 -06:00
Warner Losh
065cbc7707 kboot: Do a style(9) pass on kbootfdt.c
Mostly just properly indent.

Sponsored by:		Netflix
2022-07-27 22:29:27 -06:00
Warner Losh
60cb4f9a8e stand: tftp.c doesn't need bootinfo.h
tftp.c includes bootinfo.h, but doesn't need it. Remove it, and remove
the -Istand/common from CFALGS since that's the only reason we had it.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D35928
2022-07-27 09:04:13 -06:00
Warner Losh
e98f952c82 stand: Make sure nobody has a NULL pointer for dv_cleanup
dv_cleanup is specified almost everywhere. Use nullsys instead of NULL
to indicate 'do nothing'. Also, be consistent in trailing commas that
were missing before.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D35913
2022-07-27 09:04:13 -06:00
Warner Losh
079f02e8c0 stand: Small comment correction
While in theory, once upon a time, dv_type was arch specific, that's
never been the case in FreeBSD (and certaintly isn't in the surviving
drivers). Remove that notation.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D35911
2022-07-27 09:04:12 -06:00
Warner Losh
4932a6e41d stand: Create DEV_NAMLEN for the length of a device name
Rather than hard coding 8 for the device name length, create a #define for it.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D35910
2022-07-27 09:04:12 -06:00
Warner Losh
d2c0ec8d19 stand: Spell License correctly
An e got dropped and then cut and pasted into far too many places.

Sponsored by:		Netflix
Noticed by:		freqlabs on irc
2022-07-26 16:31:13 -06:00
Warner Losh
f4d71d0c1a stand: Fix set but unused warning
Make interp_identifier global to avoid a set but not used warning. For a
global, llvm can't optimize it out (yet?)

Sponsored by:		Netflix
2022-07-25 22:50:13 -06:00
Warner Losh
865a58d2fc stand/disk: Trivial formatting nit
style(9) wants a space here.

Sponsored by:		Netflix
2022-07-25 07:32:49 -06:00
Warner Losh
16ebddc9a7 stand/zfs: Update comment about blake3_impl_hack.c
Fix a typo by reworking the comment for blake3_impl_hack.c and amplify
the nature of the hack and its temporary reason for existing.

Sponsored by:		Netflix
Reviewed by:		delphij
Differential Revision:	https://reviews.freebsd.org/D35895
2022-07-24 16:53:36 -06:00
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