Commit Graph

83 Commits

Author SHA1 Message Date
Ed Maste
e32fecd0c2 loader: install help files only once
Every file should be installed exactly once by `make installworld`.
This is especially important for pkgbase.

Loader help files were being installed by each loader variant (e.g.,
the simp, lua, and 4th EFI loaders).  Add a (slightly hacky) mechanism
to skip installing help files for all but one variant.

PR:		271178
Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D40021
2023-05-09 20:18:19 -04:00
Warner Losh
5ce98ee5f4 stand/userboot: Simplify code
We have way more than 8k of stack for the current value of the zfs
bootonce attribute. Allocate buf on the stack rather than the
complicated malloc / free dance.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans, jhb
Differential Revision:	https://reviews.freebsd.org/D39414
2023-05-01 15:02:53 -06:00
Simon J. Gerraty
d9a4274795 Update/fix Makefile.depend for userland 2023-04-18 17:14:23 -07:00
Michael Paepcke
4d59545d0c stand: fix build userboot without zfs
Fix regression in building userboot -DWITHOUT_LOADER_ZFS

Fixes: e307eb94ae
MFC After: 3 days
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/665
2023-02-25 10:14:07 -07:00
Mitchell Horne
8859960436 loader: always install help files
Address two issues with current help file logic:

The existing condition prevents the common help file from being
installed when there are no additional help files defined. This results
in no loader.help on EFI platforms, for example.

Second, due to the fact that we build and install multiple loader types,
each successive install will clobber the previous loader.help. The
result is that we could lose type-specific commands, or possibly list
them in loaders that do not have such commands.

Instead, give each loader type a uniquely named help file. The EFI
loader will look for /boot/loader.help.efi, userboot will look for
/boot/loader.help.userboot, etc. The interpreter variant has no effect
on which help file is loaded.

This leaves the old /boot/loader.help unused.

Some credit for the final approach goes to Mathieu <sigsys@gmail.com>
for their version of the fix in https://reviews.freebsd.org/D22951.

PR:		267134
Reported by:	Daniel O'Connor <darius@dons.net.au>
Reviewed by:	imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D28591
2023-02-03 16:35:06 -04:00
Warner Losh
ad70f2e22e stand: create common set_currdev
Pull together the nearly identical copies of set_currdev in i386,
userboot and efi. Other boot loaders have variances that might be fine
to use the common routine, or not. Since they are harder to test for me,
and ofw and uboot do handle these setting differently, leave them be for
now.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38005
2023-01-11 15:15:15 -07:00
Warner Losh
1c1783d66b stand: Create common gen_setcurrdev and replace code
Replace 4 identical copies of *_setcurrdev with gen_setcurrdev to avoid
having to create a 5th copy. uboot_setcurrdev is actually different and
needs to remain separate (even though it's quite similar).

Sponsored by:		Netflix
Reviewed by:		fuz@fuz.su, kevans
Differential Revision:	https://reviews.freebsd.org/D38003
2023-01-11 15:15:14 -07:00
Warner Losh
71bbe6fb70 stand/zfs: Add a third argument to zfs_probe_dev: part_too
Pass in 'true' if you'd like to search this device's partitions or
'false' if you should just search the device. EFI and (in the future)
kboot have discrete partitions that aren't accessed via the full disk
device. Weird things happen if you try to search in these cases.

Sponsored by:		Netflix
2023-01-08 09:45:11 -07:00
Warner Losh
66012c8fc4 stand: create devinit
devinit() marches through all the devices, calling the inint routines if
any exist. Replace all the identical copies of this code.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37349
2022-11-30 15:30:33 -07:00
Warner Losh
910de60a7e stand/userboot: Move to using common devparse()
We no longer need to have to hand-code this for each boot loader since
devparse() handles them all with dv_parsedev().

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37342
2022-11-30 15:30:32 -07:00
Warner Losh
8337ab69ba stand: For all disk drivers, connect dv_parsedev to disk_parsedev
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37339
2022-11-30 15:30:32 -07:00
Warner Losh
ba11bc368e stand: Change zfs_parsedev() API
Change the first argument to zfs_parsedev() to be a pointer to a struct
devdesc *. This now gets filled in with a malloc'd structure that's
returned to the caller that the caller is repsonsible for freeing. Most
nplaces in the tree passed in a malloc'd pointer anyway, and this moves
knowledge of zfs_devdesc more firmly into the zfs.c code.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37336
2022-11-30 15:30:31 -07:00
Warner Losh
17276525fa stand: Change disk_parsedev() API
Change the first argument to disk_parsedev() to be a pointer to a struct
devdesc *. This now gets filled in with a malloc'd structure that's
returned to the caller that the caller is repsonsible for freeing. Most
places in the tree passed in a malloc'd pointer anyway, and this moves
knowledge of disk_devdesc more firmly into the disk.[ch] code.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37335
2022-11-30 15:30:31 -07:00
Warner Losh
d43bcf62a2 stand: Stop support booting 4.x and earlier kernels
FreeBSD 4.x and earlier used the bi_bios_geom to get the geometry of the
device. Starting in 5.x, with the wdc -> ata rewrite, it was used only
in pc98 kernels to report geometry of the drives. It can be safely
removed as booting kernels this old is no longer supported. This saves
176 bytes in the BIOS loader.

Sponsored by:		Netflix
Reviewed by:		adrian, emaste
Differential Revision:	https://reviews.freebsd.org/D36543
2022-09-16 09:18:57 -06:00
Warner Losh
e895ab3fbd stand: Remove dead store to bi_kernelname
We set this value twice: once to 0 and once to the VA that has the name
of the kernel. The first store is redundant. In addition, these two
stores of 0 are also redundant. Since we never set them, they will
always be zero, even if we're called multiple times. This saves 21
bytes on BIOS loader.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D36541
2022-09-16 09:18:56 -06:00
Warner Losh
fc352701ff stand: collapse all copies of *copyenv into md_copyenv
Use the efi's bi_copyenv to md_copyenv and place it in modinfo.c. Remove
all other nearly identical and efi's has the best error handling.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D36574
2022-09-16 09:18:56 -06:00
Warner Losh
5d1531d9d4 stand: Move md_copymodules into modinfo.c and reduce copies
md_copymodules, bi_copymdoules, bi_copymodules32 (x2) and
bi_copymodules64 (x2) are all the same routine... Replace them all with
md_copymodules. This saves about 800 bytes on i386 BIOS loader, which is
a nice bonus.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D36572
2022-09-16 09:18:56 -06:00
Warner Losh
bca9c87b61 stand: Create common/modinfo.h
Move all the MOD_xxx macros to this header. Each user of this interface
is currently required to define MOD_ALIGNMENT(l). modinfo was selected
because it sits inbetween modules and metadata and will make it easier
to migrate to new, shared intefaces.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D36571
2022-09-16 09:18:56 -06:00
Warner Losh
8b19d28d68 stand: Create MOD_ALIGN macro and use it everywhere
To further reduce the differences between the different MOD_xxx macros,
use MOD_ALIGN to do the proper alignment for the given use.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D36570
2022-09-16 09:18:56 -06:00
Warner Losh
4c670b53a0 stand: use archsw.arch_copyin instead of direct call
This replaces the CALLBACK(copyin, ...) with a call to
archsw.arch_copyin which points to a function that does the
callback. More diff reduction for the multiple copies of these routines
in the tree.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D36569
2022-09-16 09:18:56 -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
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
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
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
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
b3f43ee031 stand: Use c99 structure initialization for userboot's host_fsops
Sponsored by:		Netflix
2022-07-24 16:53:35 -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
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
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
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
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
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
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
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
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
d51cc252a0 userboot: provide stub gfx functions
Make sure we have needed functions present, to avoi getting undefined
symbols error(s).

PR: 253088
Reported by: John Kennedy
2021-01-30 21:20:27 +02:00
Toomas Soome
3630506b9d loader: implement framebuffer console
Draw console on efi.
Add vbe framebuffer for BIOS loader (vbe off, vbe on, vbe list,
vbe set xxx).
autoload font (/boot/fonts) based on resolution and font size.
Add command loadfont (set font by file) and
variable screen.font (set font by size). Pass loaded font to kernel.

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

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

Probably something else I forgot...

Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D27420
2021-01-02 21:41:36 +02:00
Toomas Soome
e307eb94ae loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.

By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.

By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.

bootonce dataset name is recorded in boot pool labels, bootenv area.

in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.

bootonce and nextboot features are usable in both UEFI and BIOS boot.

To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).

At this time, only lua loader is updated.

Sponsored by:	Netflix, Klara Inc.
Differential Revision:	https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00
Matt Macy
1ea0b9a5a9 Fix userboot after r364355
r364355 replaced init_zfs_bootenv with init_zfs_boot_options and
neglected to update userboot in the process.
2020-08-25 17:23:33 +00:00
Alex Richardson
0b862b0399 Avoid adding duplicates to SRCS/OBJS/SOBJS/POBJS
This is a change in preparation for stopping to use lorder.sh (D26044) and
instead assume that we have a linker newer than ~1990. Without lorder.sh
duplicates end up being passed to the linker when building .so files and this
can result in duplicate symbol definition errors.

There is one minor change: libcompiler_rt.a will no longer provide
gcc_personality_v0 and instead we now only have it in libgcc_eh.a/libgcc_s.so.
This matches GCC's behaviour.

Reviewed By:	emaste, cem
Differential Revision: https://reviews.freebsd.org/D26042
2020-08-24 09:20:33 +00:00
Toomas Soome
3830659e99 loader: create single zfs nextboot implementation
We should have nextboot feature implemented in libsa zfs code.
To get there, I have created zfs_nextboot() implementation based on
two sources, our current simple textual string based approach with added
structured boot label PAD structure from OpenZFS.

Secondly, all nvlist details are moved to separate source file and
restructured a bit. This is done to provide base support to add nvlist
add/update feature in followup updates.

And finally, the zfsboot/gptzfsboot disk access functions are swapped to use
libi386 and libsa.

Sponsored by:	Netflix, Klara Inc.
Differential Revision:	https://reviews.freebsd.org/D25324
2020-06-20 06:23:31 +00:00
Mark Johnston
5c17092568 Stop setting PG_U in bootstrap mappings.
These mappings are never visible to userspace as they get replaced when
the amd64 pmap is bootstrapped, but there is no need to set PG_U in the
first place.

Reviewed by:	alc, kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D24547
2020-04-24 13:53:40 +00:00
Kyle Evans
b3a1768824 userboot: mark host_fsops as extern
This is already defined elsewhere; mark this declaration extern to the fix
the -fno-common build.

MFC after:	3 days
2020-03-29 02:29:06 +00:00
Simon J. Gerraty
53f151f906 Fix pkgfs stat so it satisfies libsecureboot
We need a valid st_dev, st_ino and st_mtime
to correctly track which files have been verified
and to update our notion of time.

ve_utc_set(): ignore utc if it would jump our current time
by more than VE_UTC_MAX_JUMP (20 years).

Allow testing of install command via userboot.
Need to fix its stat implementation too.

bhyveload also needs stat fixed - due to change to userboot.h

Call ve_error_get() from vectx_close() when hash is wrong.

Track the names of files we have hashed into pcr

For the purposes of measured boot, it is important
to be able to reproduce the hash reflected in
loader.ve.pcr
so loader.ve.hashed provides a list of names in the order they
were added.

Reviewed by:	imp
MFC after:	1 week
Sponsored by:	Juniper Networks
Differential Revision:	https://reviews.freebsd.org//D24027
2020-03-25 19:12:19 +00:00
Simon J. Gerraty
afc571b1a6 veloader use vectx API for kernel and modules
The vectx API, computes the hash for verifying a file as it is read.
This avoids the overhead of reading files twice - once to verify, then
again to load.

For doing an install via loader, avoiding the need to rewind
large files is critical.

This API is only used for modules, kernel and mdimage as these are the
biggest files read by the loader.
The reduction in boot time depends on how expensive the I/O is
on any given platform.  On a fast VM we see 6% improvement.

For install via loader the first file to be verified is likely to be the
kernel, so some of the prep work (finding manifest etc) done by
verify_file() needs to be factored so it can be reused for
vectx_open().

For missing or unrecognized fingerprint entries, we fail
in vectx_open() unless verifying is disabled.

Otherwise fingerprint check happens in vectx_close() and
since this API is only used for files which must be verified
(VE_MUST) we panic if we get an incorrect hash.

Reviewed by:	imp,tsoome
MFC after:	1 week
Sponsored by:	Juniper Networks
Differential Revision:	https://reviews.freebsd.org//D23827
2020-03-08 17:42:42 +00:00
Toomas Soome
bcbb1e60a1 loader: userboot/test should accept more than one disk
allow to specify multiple -d options, test -d disk1 -d disk2 ..
2019-11-03 09:14:29 +00:00
Toomas Soome
96b2f9c996 userboot/test should use PRIx64 as one would expect from prefix 0x
Test is printing decimal value after prefix 0x.
2019-10-24 07:49:33 +00:00
Ian Lepore
14243f8de7 Distinguish between "no partition" and "choose best partition" with a constant.
The values of the d_slice and d_partition fields of a disk_devdesc have a
few values with special meanings in the disk_open() routine. Through various
evolutions of the loader code over time, a d_partition value of -1 has
meant both "use the first ufs partition found in the bsd label" and "don't
open a bsd partition at all, open the raw slice."

This defines a new special value of -2 to mean open the raw slice, and it
gives symbolic names to all the special values used in d_slice and
d_partition, and adjusts all existing uses of those fields to use the new
constants.

The phab review for this timed out without being accepted, but I'm still
citing it below because there is useful commentary there.

Differential Revision:	https://reviews.freebsd.org/D19262
2019-03-24 18:51:52 +00:00
Kyle Evans
7325df02c5 stand: Improve some debugging experience
Some of these files using <FOO>_DEBUG defined a DEBUG() macro to serve as a
debug-printf. -DDEBUG is useful to enable some debugging output across
multiple ELF/common parts, so switch the DEBUG-as-printf macros over to
something more like DPRINTF that is more commonly used for this kind of
thing and less likely to conflict.

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

MFC after:	1 week
2019-03-12 16:21:39 +00:00