Commit graph

1916 commits

Author SHA1 Message Date
Warner Losh 32568e5f24 loader: Retire CTASSERT
The project is moving away from CTASSERT in favor of
_Static_assert. Cleanup the few instances in the loader proactively.

Sponsored by:		Netflix
Reviewed by:		manu, tsoome
Differential Revision:	https://reviews.freebsd.org/D44006
2024-02-21 08:51:34 -07:00
Warner Losh 65ee8f90b7 kboot: Fix zfs bootonce protocol
This wasn't updated when the other copies were updated. Make it
identical to efi code. We should likely refactor this (with userboot),
but they are all not quite identical.

Sponsored by:		Netflix
2024-02-20 20:36:00 -07:00
Warner Losh 9a5aaa97cb loader: For the mini-stdio we have for lua, #define them to something else
To make it easier to port lua and some of the lua modules, we have a
series of routines to implement the stdio routines, even though we don't
normally implement them in the boot loader. Add a comment to this effect.

Also, some tools, like sanitizers and static analysis tools, make
unwarranted assumptions about these, so #define them to a different name
so they stop.

Sponsored by:		Netflix
2024-02-20 20:31:50 -07:00
Justin Hibbits cd6e526e26 loader/libofw: Fix disk size truncation
At present OF_ioctl first multiplies, then casts to 64-bit, meaning at
the asm level it truncates the result to 32-bit, then zero-extends it to
64-bit to return.  Cast `n` to 64-bit before multiplying, so that the
correct result is returned.
2024-02-20 22:17:26 -05:00
Warner Losh bbfc01c2d2 loader: Make MK_LOADER_BIOS_TEXTONLY work
Select between text-only and graphical frame buffer consoles for the
BIOS boot loader. Pull one or the other in with #ifdef in conf.c. Add
gfx_bios.c for the few routines that are needed for the BIOS support of
gfx. These are stubbed out for text-only mode. Move bi_load_vbe_data
here since it's only used for the graphical frame buffer.

Note: This setup also allows us to build multiple BIOS loaders if we
have to, some with text-only and some graphical. We don't do this today.
We may be forced to turn this on in the future if ZFS keeps growing.

The size savings is 41k, which helps a lot with some of our users that
want to enable more options in the BIOS boot loader than are normally
safe to do, and they don't need graphics.

Sponsored by: 		Netflix
Differential Revision:	https://reviews.freebsd.org/D43917
2024-02-17 23:29:07 -07:00
Warner Losh e36afddf11 loader: Add textvidc to build
Add textvidc to the build. And use -DTERM_EMU to build it.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D43915
2024-02-17 23:29:07 -07:00
Warner Losh 1954e5c1dc loader: bring back old text-only video console
Bring back vidconsole.c as textvidc.c from 2a0e2c88db. This console
does no graphics stuff at all, supports no fancy logos, has known bugs
in the terminal emulation, etc. However, it is small. It will be a
build-time option to select between the two. The BIOS loader is running
out of space when too many options are selected, so this allows people
to select the smaller one to spend the space elsewhere. This is only the
verbatim copy of the old vidconsole.c. It's not yet connected to the
build.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D43911
2024-02-17 23:29:07 -07:00
Warner Losh e5d1a21e50 loader: Bump the limit to 560,000 bytes for BIOS loader
Further experience suggests we do not need as much margin. This was
mistakenly bumped to 570,000 in a prior commit, so this undoes that.

Sponsored by:		Netflix
2024-02-15 21:16:36 -07:00
Warner Losh 26c8dedef1 loader: line line per src file in libi386
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D43913
2024-02-15 21:02:37 -07:00
Warner Losh 588ff0748f loader: Simplify build a little
Confine -DDISK_DEBUG to biosdisc.c, the only file it affects.
Use modern variable arrays instead of alloca and add a sanity
size minimum for biospnp nodes. These nodes are tiny enough that
we needn't do a malloc/free pair: the stack is fine.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D43914
2024-02-15 20:59:23 -07:00
Warner Losh e34fd722ca kboot: Add our own lua bindings
Create a small wrapper around the new flua hash module so we can use it
here too. There's no 4th bindings, nor will they be created.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D43874
2024-02-15 20:59:23 -07:00
Warner Losh 0fd98b8a76 loader: Move drawer.lua over to gfx table.
Drawer.lua is the only bit of lua code in the base that uses any of the
functons moved from the loader table to the gfx table. Move the main
code to using the gfx dispatch. Add compat code for running on old
loaders that creates the newer-style gfx table with the term_* functions
we call in it populated. This will even work on the super old versions
of the loader that don't have them (we'll still skip using them).

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D43908
2024-02-15 20:59:23 -07:00
Warner Losh a8f8c53761 loader: Move gfx functions to gfx.lua.8
Now that the fb_* and term_* functions are available in the gfx table,
move the documentation to gfx.lua.8. Add information about backwards
compatibility.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D43907
2024-02-15 20:59:23 -07:00
Warner Losh 0921a771da loader: Move to using linker sets to bring in optional bits
The graphics stuff is optional. When it is pulled into the system, we
use a linker set to initialize the lua bindings for it now.

Sponsored by:		Netflix
Reviewed by:		kevans, jhb
Differential Revision:	https://reviews.freebsd.org/D43906
2024-02-15 20:59:23 -07:00
Warner Losh 23d9b5c9fe loader: Remove gfx_fb_stub.c, it's no longer needed
Now that we draw in the gfx bindings for all our interpreters only when
graphics support is compiled in, we can eliminate this from all the
loaders that don't have graphics support.

Sponsored by:		Netflix
Reviewed by:		kevans, jhb
Differential Revision:	https://reviews.freebsd.org/D43905
2024-02-15 20:59:23 -07:00
Warner Losh 9c8bf69a53 loader: Only create gfx 4th bindings when gfx is available
Only create the gfx bindings for 4th when it's compiled into the
loader. We do this with a linker set that only gets brought in to those
loaders that call gfx_framework_init. This calls gfx_interp_md() will
will drag in gfx_loader.c which will add to the linker set that
registers these bindings.

Sponsored by:		Netflix
Reviewed by:		kevans, jhb
Differential Revision:	https://reviews.freebsd.org/D43904
2024-02-15 20:59:22 -07:00
Warner Losh 60e199d9fd loader: Add prototype for gfx_interp_md
This function will be used to draw in the graphics bindings when the
loader is compiled with graphics (gfx) support. Provide definitions
for lua and the simple interpreter. 4th support is forthcoming.

Sponsored by:		Netflix
Reviewed by:		kevans, jhb
Differential Revision:	https://reviews.freebsd.org/D43903
2024-02-15 20:59:22 -07:00
Warner Losh 9b16231032 loader: Create new gfx table
Create a new gfx global table. Put into it all the graphics bindings
that we have in loader today. For now, have compatability binding for
loader. Remove them from loader.

Sponsored by:		Netflix
Reviewed by:		kevans, jhb
Differential Revision:	https://reviews.freebsd.org/D43902
2024-02-15 20:59:22 -07:00
Warner Losh 061b68a760 loader: Separate gfx to a new file.
Move gfx lua hook registration to a new file.

Sponsored by:		Netflix
Reviewed by:		kevans, jhb
Differential Revision:	https://reviews.freebsd.org/D43901
2024-02-15 20:59:22 -07:00
Warner Losh 1dac5a34b6 loader: Register the gfx stuff separately.
Move registration of the gfx stuff to separate function. However, no
change in functionality is intended.

Sponsored by:		Netflix
Reviewed by:		kevans, jhb
Differential Revision:	https://reviews.freebsd.org/D43900
2024-02-15 20:59:22 -07:00
Warner Losh 7fc95c31f0 loader: Simplify the loader.has_command
luaL_checkstring already checks for the right number of
arguments. There's no need to do that by hand here. Now an exception
will be thrown like any other function with the wrong args. Also,
push a boolean instead of an int.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D43820
2024-02-15 20:59:22 -07:00
Warner Losh a27c1350e4 loader: Make vidc_biosputchar static
It's currently unused outside of vidconsole.c. Gerald Hicks' fix to the
beep code from de37e4a6d2333/1998 introduced the funciton as
static. Maxim Sobolev (sobomax) made it non-static since his spinconsole
called it in c4c3b35172d67/2009. When sobomax dropped the direct call
after making spinconsole console independent in b35172d67/2017,
vidc_biosputchar remained a harmless unreferenced global. Make it static
once again.

Fixes:		c7e10205ae
Sponsored by:	Netflix
2024-02-14 11:22:57 -07:00
Warner Losh 62a52c1542 loader: export the CMD_ constants in loader table
Export the CMD_OK, etc constants in the loader table. They are the
return values of loader.perform, etc.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D43821
2024-02-14 10:55:38 -07:00
Warner Losh cd147a2a02 loader: Fetch initial script from loader_lua env
Sometimes it is nice to override the initial script that we run. Make it
possible by fetching loader_lua from the env and using that instead of
the default if prsent.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D43819
2024-02-14 10:55:38 -07:00
Simon J. Gerraty f616d61ab6 libsecureboot do not report expected unverified files
By default only report unverified files at severity VE_WANT
and above.  This inlcudes *.conf but not *.hints, *.cookie
or *.tgz which get VE_TRY as their severity.

If Verbose is set to 0, then VerifyFlags should default to 0 too.
Thus the combination of

	module_verbose=0
	VE_VEBOSE=0

is sufficient to make the loader almost totally silent.

When verify_prep has to find_manifest and it is verified ok
return VE_NOT_CHECKED to verify_file so that it can skip
repeating verify_fd

Also add better debugging output for is_verified and add_verify_status.

vectx handle compressed modules

When verifying a compressed module (.ko.gz or .ko.bz2)
stat() reports the size as -1 (unknown).
vectx_lseek needs to spot this during closing - and just read until
EOF is hit.

Note: because of the way libsa's open() works, verify_prep will see
the path to be verified as module.ko not module.ko.bz2 etc.  This is
actually ok, because we need a separate module.ko.bz2 entry so that
the package can be verified, and the hash for module.ko is of the
uncompressed file which is what vectx will see.

Re-work local.trust.mk so site.trust.mk need only set
VE_SIGN_URL_LIST (if using the mentioned signing server)

interp.c: restrict interactive input

Apply the same restrictions to interactive input as for
unverified conf and hints files.

Use version.veriexec when LOADER_VERIEXEC is yes

Reviewed by:	kevans
Sponsored by:	Juniper Networks, Inc.
Differential Revision:	https://reviews.freebsd.org/D43810
2024-02-12 14:35:01 -08:00
Warner Losh 621dae89f3 loader: Document the lua loader table.
Document all the public functions from the "loader" table.

Sponsored by:		Netflix
Reviewed by:		pauamma_gundo.com, tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D43701
2024-02-10 11:49:09 -07:00
Warner Losh 064fa628ce loader: For EFI, if we don't have ConOut, try ConIn
Try ConIn if we don't have a ConOut variable. ConIn will contain HID
devices and/or serial devices. We currently just search for serial
devices and will use them instead of video with the current code. While
ConIn w/o ConOut is fairly common on laptops, is kinda rare on servers.
Some refinement may be needed in the future if servers come to
light. This is also minimal to allow possible integration into 13.3
release.

MFC After:		1 week
Sponsored by:		Netflix
Reviewed by:		dab, tsoome
Differential Revision:	https://reviews.freebsd.org/D43714
2024-02-04 14:09:48 -07:00
Warner Losh 18968b8274 loader: Move build_font_module to gfx_fb.c
The font module is part and parsel of the gfx_fb support. Move it to
gfx_fb.c where it can access the data it needs.

Sponsored by:		Netflix
2024-02-02 14:01:04 -07:00
Warner Losh 784f925e50 loader: Font module is EFI dependent
The font module is part of the gfx_fb support. Since we share this file
between EFI and kboot, we only want to pass the font data to the kernel
when we're booting from EFI, not kboot.

Sponsored by:		Netflix
2024-02-02 14:01:04 -07:00
Warner Losh fd577b59b2 libsa: Move hash functions up a level
This should have no functional change. Move compiling the sha256, sha512
and md5 hash functions up into libsa to allow them to be used elsewhere
in the boot loader when geli isn't configured. Since libsa is a .a, these
won't wind up in any boot loader that doesn't reference them, so should
be a nop.

Sponsored by:		Netflix
2024-02-02 14:01:03 -07:00
Warner Losh 7c8b126c1a libsa: Move include file creation to the end of the Makefile
The include file symblic links, etc are out of place where they
are. Move them to the end of the file. No functional change intended.

Sponsored by:		Netflix
2024-02-02 14:01:03 -07:00
Stéphane Rochoy c475e61f66 stand/lua: always allow overriding with local config files
Loader now also read configuration files listed in local_loader_conf_files.
Files listed here are the last ones read. And /boot/loader.conf.local was
moved from loader_conf_files to local_loader_conf_files leaving only
loader.conf and device.hints in loader_conf_files by default.

The idea is to ensure local_loader_conf_files, i.e., /boot/loader.conf.local,
can always be used to override other user defined settings.

So the sequencing is now as follow:

 1. Bootstrap:
     /boot/defaults/loader.conf

 2. Read loader_conf_files files:
     /boot/device.hints
     /boot/loader.conf

 3. Read loader_conf_dirs files:
     /boot/loader.conf.d/*.conf

 4. And finally, rread local_loader_conf_files files:
     /boot/loader.conf.local

Reviewed by: imp, kevans
Pull Request: https://github.com/freebsd/freebsd-src/pull/759
2024-02-02 12:04:57 -07:00
Stéphane Rochoy c343eedc6d stand/lua: per-product conf if requested via product_vars
If product_vars is set, it must be a space separated list of environment
variable names to walk through to guess the product. Each time a product can be
guessed (i.e., the corresponding variable is defined), prepend
/boot/loader.conf.d/PRODUCT/ to loader_conf_dirs.

It can be typically used as follow:

    smbios.system.planar.maker="PLANAR_MAKER"
    smbios.system.planar.product="PLANAR_PRODUCT"
    smbios.system.product="PRODUCT"
    uboot.m_product="M_PRODUCT"
    product_vars="smbios.system.planar.maker smbios.system.planar.product smbios.system.product uboot.m_product"

to read files found in the following directories, in that order:

    /boot/loader.conf.d/PLANAR_MAKER
    /boot/loader.conf.d/PLANAR_PRODUCT
    /boot/loader.conf.d/PRODUCT
    /boot/loader.conf.d/M_PRODUCT

Reviewed by: imp, kevans
Pull Request: https://github.com/freebsd/freebsd-src/pull/759
2024-02-02 12:04:57 -07:00
Warner Losh 994865caf2 Revert "stand/lua: per-product conf if requested via product_vars"
This reverts commit 754cac4b28. No mail
went out and commit message was wrong.

Sponsored by:		Netflix
2024-02-02 12:04:57 -07:00
Warner Losh 5fdf01dbee Revert "stand/lua: always allow overriding with local config files"
This reverts commit d3d0b73557. no mail
sent out, and the commit message was wrong.

Sponsored by:		Netflix
2024-02-02 12:04:57 -07:00
Stéphane Rochoy d3d0b73557 stand/lua: always allow overriding with local config files
Loader now also read configuration files listed in local_loader_conf_files.
Files listed here are the last ones read. And /boot/loader.conf.local was
moved from loader_conf_files to local_loader_conf_files leaving only
loader.conf and device.hints in loader_conf_files by default.

The idea is to ensure local_loader_conf_files, i.e., /boot/loader.conf.local,
can always be used to override other user defined settings.

So the sequencing is now as follow:

 1. Bootstrap:
     /boot/defaults/loader.conf

 2. Read loader_conf_files files:
     /boot/device.hints
     /boot/loader.conf

 3. Read loader_conf_dirs files:
     /boot/loader.conf.d/*.conf

 4. And finally, rread local_loader_conf_files files:
     /boot/loader.conf.local
2024-02-02 11:58:28 -07:00
Stéphane Rochoy 754cac4b28 stand/lua: per-product conf if requested via product_vars
If product_vars is set, it must be a space separated list of environment
variable names to walk through to guess the product. Each time a product can be
guessed (i.e., the corresponding variable is defined), prepend
/boot/loader.conf.d/PRODUCT/ to loader_conf_dirs.

It can be typically used as follow:

    smbios.system.planar.maker="PLANAR_MAKER"
    smbios.system.planar.product="PLANAR_PRODUCT"
    smbios.system.product="PRODUCT"
    uboot.m_product="M_PRODUCT"
    product_vars="smbios.system.planar.maker smbios.system.planar.product smbios.system.product uboot.m_product"

to read files found in the following directories, in that order:

    /boot/loader.conf.d/PLANAR_MAKER
    /boot/loader.conf.d/PLANAR_PRODUCT
    /boot/loader.conf.d/PRODUCT
    /boot/loader.conf.d/M_PRODUCT
2024-02-02 11:57:52 -07:00
Warner Losh 8f7327dcee kboot: update copyright on these files.
host_syscalls.c: I've written, so put Netflix copyright on. It's
possible in the confusion that Nathan wrote the host_gettimeofday
implementation.

syscall_nr: These files likely can't enjoy copyright protection since
they are just facts (the per-arch Linux system calls), so add a note
they are in the public domain.

Sponsored by:		Netflix
2024-01-28 13:04:32 -07:00
Warner Losh 2b7918f13c kboot: Assert copyright here
According to git blame I've 95%+ rewritten this file. Update copyright to
reflect that, but give nod to Nathan for the original I started with.

Sponsored by:		Netflix
2024-01-28 13:04:32 -07:00
Warner Losh 36ef238cb6 kboot: Move termios to libkboot
Sponsored by:		Netflix
2024-01-28 13:04:31 -07:00
Warner Losh 2e3f49888e kboot: Move system calls to libkboot
Sponsored by:		Netflix
2024-01-28 13:04:31 -07:00
Warner Losh 099335814d kboot: Move syscall stubs to libkboot
Sponsored by:		Netflix
2024-01-28 13:04:31 -07:00
Warner Losh 4aabaa1890 kboot: Cleanup libkern reference
For aarch64 and amd64, we don't pull in anything from libkern, so we
don't need it in our path.  However, powerpc needs ucmpdi2 from libkern,
so bring it into libkboot's build and omit it from loader.kboot.

Sponsored by:		Netflix
2024-01-28 13:04:31 -07:00
Warner Losh a03411e847 kboot: Move _start out of kboot and into libkboot
Move the startup code from kboot/kboot to kboot/libkboot and add the
necessary infrastructure for it to build. move start_arch.h, a private
header for libkboot, over as well.

Sponsored by:		Netflix
2024-01-28 13:04:31 -07:00
Warner Losh 091c255b5b kboot: Move to kboot/kboot
In anticipation of separating the library elements from the kboot
prorgam elements, move kboot down a level into a subdirectory. There
will be libkboot and include directories in subsequent commits,
mirroring other subsystems like i386 and efi.

Sponsored by:		Netflix
2024-01-28 13:04:31 -07:00
Warner Losh dcc20bced5 stand: Use modern function definitions
Use modern function definitions for functions with no args.

Sponsored by:		Netflix
2024-01-28 13:04:31 -07:00
Dag-Erling Smørgrav 7edbf69b79 stand: Add 1440p to the list of known resolutions.
MFC after:	1 week
Reviewed by:	manu, kevans, imp
Differential Revision:	https://reviews.freebsd.org/D43391
2024-01-23 15:20:27 +01:00
Jose Luis Duran ed76a9506a stand: Fix typo (triple S)
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/955
2023-12-27 20:24:31 -07:00
Warner Losh 64db9a0f82 Add kenv .Xr in kldload(8) and loader.conf(5)
Sponsored by:		Netflix
2023-12-20 21:17:38 -07:00
Kyle Evans d04415c520 loader: lua: remove the default kernel if it doesn't exist
The `kernel` env var provides the default kernel, usually "kernel".  It
may be the case that the user doesn't have a "kernel" kernel, just
"kernel.*" kernels, but have left `kernel` to the default because we
autodetect entries by default anyways.

If we're doing autodetection, take note of whether the default kernel
exists or not and remove it from the list if it doesn't and we had found
any other kernels.  We avoid it in the #kernels == 1 case because
something fishy has likely happened and we should just trust the
configuration.

Reviewed by:	imp, manu
Differential Revision:	https://reviews.freebsd.org/D42967
2023-12-13 10:52:14 -06:00