Commit graph

1963 commits

Author SHA1 Message Date
Warner Losh 6e28b4aa15 uboot: Use c99 initializers for the console struct
Sponsored by:		Netflix
2024-05-19 22:05:42 -06:00
Warner Losh b3551da9cd efi_console: Use c99 initializers
Sponsored by:		Netflix
2024-05-19 22:05:42 -06:00
Warner Losh 5e7b0cd93a i386/nullconsole: Use C99 initializers
Sponsored by:		Netflix
2024-05-19 22:05:41 -06:00
Warner Losh 803060b217 i386/spinconsole: Use C99 initializers
Sponsored by:		Netflix
2024-05-19 22:05:41 -06:00
Warner Losh a578e2b896 boot/i386: Use C99 initializer for textvidc
Sponsored by:		Netflix
2024-05-19 22:05:41 -06:00
Warner Losh f989ebd4de kboot: Use C99 initialiers for hostconsole.
Sponsored by:		Netflix
2024-05-19 22:05:41 -06:00
Warner Losh 0111f09ca6 kboot: Initialize hostfs_root sooner (and remove kboot.conf)
Move the initialization of hostfs_root to be a bit sooner. While it
doesn't matter for the default case, we may want to use hostfs files
sooner.

Also, while we're here, remove kboot.conf. It duplicates the command
line and has proven difficult to use. It will be replaced by an early
script that can influence the state of the boot loader before we select
a device to boot from (including strongly suggesting which one to boot
from).

Sponsored by:		Netflix
2024-05-19 22:05:41 -06:00
Warner Losh 68344c9c6c loader: separate lang init from scripting init
Create interp_preinit() to initialize the scripting language to run
scripts. Make sure you can call it multiple times, but only the first
one has effect, After it's call, you can run scripts in the scripting
language. At the moment, no functional change.

Sponsored by:		Netflix
2024-05-19 22:05:40 -06:00
Warner Losh 1d7bdae9ca kboot: Move console, acpi and smbios init
Move the console probing to as early as possible. There's no real
support for anything but hostcons, and setting it up early will show
other error messages.

ACPI and SMBIOS probing can be done just after we have the console, so
move it there. This allows other parts of the early code to use info
from that, as well as overriding and env vars set by these things on the
command line (smbios data may be wrong during initial development phases
as the automated way to populate per-board data may not be established,
etc).

Sponsored by:		Netflix
2024-05-19 22:05:40 -06:00
Warner Losh e63d20b70e stand: Spell LUA_COMPILE_SET correctly.
MFC After: 2 days
Sponsored by:		Netflix
2024-05-11 12:09:51 -06:00
Warner Losh 75e5f5916e boot1.efi: Don't redundantly include devpath.c
devpath.c is on both the comand line and in libefi. This is redundant
and was a mistake in 4cf36aa101. It never should have been here. In
practice, this just means that the devpath.o from libefi.a goes unused.
This will cause problems with some upcoming changes (D44872) to enable
LTO to reduce the size of the binaries, so go ahead and make the change
now to reduce the changeset for that. No functional change indended.

Fixes:		4cf36aa101
Co-authored-by:	sobomax
Sponsored by:	Netflix
2024-05-07 08:53:50 -06:00
Stephen J. Kiernan 46b606c8fd userboot: support environment and symlinks in test application
Pass the environment on to the loader.
Also define USERBOOT=1 in the environment varables.

Add support for symlinks in the test application open callback.

stat the root directory when opening file
Without this, running "ls" command on the root directory encounters
issues getting the directory listing.

Reviewed by:	jhb
Obtained from:	Juniper Networks, Inc.
Differential Revision:	https://reviews.freebsd.org/D44625
2024-04-30 16:40:18 -04:00
Warner Losh cfcf475a66 stand: Install gptboot.efi(8)
We need to include bsd.init.mk first when we have man pages in the boot
loader.

Sponsored by:		Netflix
2024-04-05 16:53:47 -06:00
Stephen J. Kiernan 112783ebbc userboot: allow for overriding the version file location
Use ?= when assigning VERSION_FILE

Reviewed by:	imp
Obtained from:	Juniper Networks, Inc.
Differential Revision:	https://reviews.freebsd.org/D44624
2024-04-03 19:09:43 -04:00
Stephen J. Kiernan fe429e6794 stand/efi: Changes to efichar to allow it to be used in the kernel
Replace malloc/free with EFICHAR_MALLOC and EFICHAR_FREEE macros.

Obtained from:	Juniper Networks, Inc.
Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D44541
2024-03-28 14:09:37 -04:00
Ed Maste 3bd637afbd boot0: remove reference to fdisk
fdisk is obsolete and there is no need to mention a specific tool used
to update the partition table.  Just refer to it as the MBR partition
table.

Sponsored by:	The FreeBSD Foundation
2024-03-25 15:59:09 -04:00
Simon J. Gerraty a8eb3b365e loader.4th dictthreshold too small
The dictthreshold in stand/forth/loader.4th is too small
resulting in full dictionary.

Reviewed by:	stevek, imp
Sponsored by:	Juniper Networks, Inc.
Differential Revision:	https://reviews.freebsd.org/D44414
2024-03-18 16:16:29 -07:00
Simon J. Gerraty 01f3abbfcd uboot/Makefile move BINDIR
Set BINDIR before we include bsd.init.mk
so we can override it via local.init.mk

Reviewed by:	imp
Sponsored by:	Juniper Networks, Inc.
Differential Revision:	https://reviews.freebsd.org/D44413
2024-03-18 16:14:15 -07:00
Warner Losh 462af7676b kboot: kbootfdt: fix error handling
If we are able to open /sys/firmware/fdt, but aren't able to read it,
fall back to /proc/device-tree. Remove comment that's not really true,
it turns out.

Sponsored by:		Netflix
2024-03-11 15:21:52 -06:00
Warner Losh d75524b3fe kboot: Use is_linux_error to check mmap return error
Rather than checking against the (incorrect) -511, use the
is_linux_error() function to check to see if host_mmap failed.

Sponsored by:		Netflix
2024-03-11 15:21:52 -06:00
Warner Losh a9cd3b675e kboot: Print UEFI memory map
If we can read the UEFI memory map, go ahead and print the memory map.
While the kernel prints this with bootverbose, having it at this stage
is useful for debugging other problems.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D44287
2024-03-11 15:21:52 -06:00
Warner Losh d650c3efb6 kboot: hostfs -- check for llseek failure correctly
The host_* syscalls are all raw Linux system calls, not the POSIX
wrappers that glibc / musl create. So we have to ranage change the
return value of host_llseek correctly to use the negative value hack
that all Linux system calls use.

This fixes a false positive error detection when we do something like
lseek(fd, 0xf1234567, ...); This returns 0xf1234567, which is a negative
value which used to trigger the error path.  Instead, we check using the
is_linux_error() and store the return value in a long. Translate that
errno to a host errno and set the global errno to that and return
-1. lseek can't otherwise return a negative number, since it's the
offset after seeking into the file, which by definition is positive.

This kept the 'read the UEFI memory map out of physical memory' from
working on aarch64 (whose boot loader falls back to reading it since
there are restrictive kernel options that can also prevent it), since
the physical address the memory map was at on my platform was like
0xfa008018.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D44286
2024-03-11 15:21:51 -06:00
Warner Losh 8b1925f29c kboot: Avoid UB in signed shift
offset is signed. Copy it to the unsigned res before shifting. This
avoids any possible undefined behavior for right shifting signed
numbers. No functional change intended (and the code generated is the
nearly same for aarch64).

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D44285
2024-03-11 15:21:51 -06:00
Warner Losh 3ae18fdfbc kboot: Create function for error checking.
Linux has the convention of returning -ERRNO to flag errors from its
system calls. Sometimes other negative values are returned that are
success...  However, only values -1 to -4096 (inclusive) are really
errors. The rest are either truncated values that only look negative (so
use long instead of int), or are things like addresses or legal unsigned
file offsets or similar that are successful returns. Filter out the
latter.

Sponsored by:		Netflix
2024-03-11 15:21:51 -06:00
Warner Losh 552f3072af loader/lua: Remove workaround for command_error
loader.command_error was available prior to stable/12 branching. No need
to check if it is available or not.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D44144
2024-02-29 10:58:59 -07:00
Warner Losh ab97d42add loader/lua: Remove compat shim for loader.lua_path
loader.lua_path was committed before stable/13 was branched, and merged
in to for 12.2. Remove workaround for it not being present.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D44143
2024-02-29 10:58:52 -07:00
Warner Losh 8b9178cd0d loader/lua: Remove pager shim
Just after 12.2 and before the stable/13 branch, kevans added lpager.c
to provide a pager interface for commands written in lua.  It was merged
into 12.3. Now that 12.2 is long since EOL, we can remove the pager shim
here. Nobody needs that old loader + new lua scripts.  Plus only one
command is affected.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D44142
2024-02-29 10:58:43 -07:00
Warner Losh 2425dbdff3 loader/efi: Small diff reduction
Make doing the boot once protocol more similar to copies of this code.

Sponsored by:		Netflix
Reviewed by:		manu
Differential Revision:	https://reviews.freebsd.org/D44007
2024-02-29 09:14:47 -07:00
Warner Losh 525e6d6c89 loader/zfs: Fix to actually return the last error
The last fix, to try to return the last error, really returns the first
return code after the last error, which could be zero. Instead, return
the last error. Also, change rc to err to make it visually distinct from
rv, which is the cause of my error in e54bb0ad80.

Reported by:		Bill Sommerfeld <sommerfeld@hamachi.org>
Fixes:			e54bb0ad80
Sponsored by:		Netflix
2024-02-29 09:12:21 -07:00
Warner Losh 07d600649e stand: Remove dangling mips references
Remove mips support files from ficl.

Sponsored by:		Netflix
2024-02-28 07:09:41 -07:00
Warner Losh 9398a495eb loader: Add loader.exit
Add loader.exit(status). While one can get alomst this behavior with
loader.perform("quit"), quit doesn't allow a value to be returned to the
firmware. The interpretation of 'status' is firmware specific. This can
be used when autobooting doesn't work in scripts, for example, to allow
the firmware to try something else...

Sponsored by:		Netflix

Reviewed by:	kevans
Differential Revision:	https://reviews.freebsd.org/D44094
2024-02-26 20:49:46 -07:00
Toomas Soome 1b3f4ccb7d loader: we can only env_discard() existing variable
While dropping nvpair from nvstore, we also remove the corresponding
environment variable. By doing so, we should be careful not to try
to unset non-existing variable.

Reviewed by:	imp
MFC after:      2 week
Differential revision:  https://reviews.freebsd.org/D44083
2024-02-26 14:56:52 +02:00
Warner Losh f5f08e41aa loader/efi: Only include interpreter's linker script
For safety, only include the interpreter's linker script. Note that the
simple loader doesn't have one, but it's not an error to copy a ELF
section that does not exist. No functional change, however.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D44064
2024-02-24 17:57:29 -07:00
Warner Losh 8ec8413faa loader/ficl: Rename the ficl compile set to X4th_compile_set
And upcoming change will need this set to be named this. Since it's only
used in the efi Makefile, and inside if ficl itself, the change should
be a nop.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D44063
2024-02-24 17:57:21 -07:00
Warner Losh b4e85f760b loader/efi: Use unique linker set for lua
After the linker set cleanup in ldscripts, there's now only one place we
need to know the linkerset name, so go ahead and change the lua
interpreter augmentation linker set to be uniquely named.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D44062
2024-02-24 17:57:13 -07:00
Warner Losh d024bc7ff5 loader/efi: Linker sets not needed.
We don't need linker sets listed as sections. They are explicitly
included in the objcopy we use to create the .efi file. This practice
was added in 2002 by peter@ in a6d81d83a2 to make ia64 builds
self-hosted. However, it was added back to the objcopy in 2010 by rpaulo
in 8df7a05edd for i386 EFI support, though the ldscript file then
retained them needlessly. The gcc/binutils bug having been fixed in the
interim. We've not needed them since then, but the redundancy didn't
matter.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D44061
2024-02-24 17:57:04 -07:00
Warner Losh ec6cbe468f loader/kboot: simplify linker set inclusion a little
Linker set sections are included by default. No need to do so
explicitly.  These were bogusly copied from the efi ldscripts. They were
there due to a workaround introduced in 2002 by peter@ for a gcc
upgrade, but whatever bugs necessitated it were filed by 2010 when
rpaulo@ imported the i386 support (though they were copied even though
the objcopy retained them correctly, the gcc bug having been
fixed). They've never been needed.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D44060
2024-02-24 17:56:56 -07:00
Warner Losh 3d6239d244 loader/uboot: Move to foo.ldconfig
Move to the foo.ldconfig convention to match the rest of the boot
loader. No functional change intended.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D44059
2024-02-24 17:56:48 -07:00
Warner Losh fe4ab1fdb0 loader/powerpc: Share ldscript
Share ldscript between the different ppc versions. There's two different
scripts since we build 32-bit binaries for all types of powerpc, but
have little endian and big endian variations that are different by only
two lines. Set the output format and include the rest.

Move to foo.ldscript as well.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D44058
2024-02-24 17:56:31 -07:00
Warner Losh acb474c084 kboot: Centralize ldscript addition
Make the pattern for ldscripts always be
arch/$MACHINE_ARCH/$MACHINE_ARCH.ldscript so we can add it from a
central Makefile. This also moves from ldscript.arch to arch.ldscript to
match the loader's new convention.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D44057
2024-02-24 17:56:23 -07:00
Warner Losh 5b3b9a5858 loader: Move ldscripts to match more standard practices
In the larger open source community, ld scripts are foo.ldscrpt rather
than ldscript.arch like we use here. This moves the EFI ldscripts.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans, emaste
Differential Revision:	https://reviews.freebsd.org/D44056
2024-02-24 17:56:14 -07:00
Warner Losh 6faf55c86d loader: rename gfx_interp_md to gfx_interp_ref
We have the call to gfx_interp_ref to bring in the .o so that we get the
linker set item to add the language bindings at the right time. Where we
call it is not the right time... So the _ref name is better. Change it
before we have too many others like it.

Sponsored by:		Netflix
2024-02-23 21:22:08 -07:00
Warner Losh 27c0f2a544 loader: These files have no copyrightable material
These files have no copyrightable material, and so are in the public
domain.

Sponsored by:		Netflix
2024-02-22 09:31:57 -07:00
Warner Losh 3e15b01d69 libsa: Remove redundant sys/cdefs.h
Sponsored by:		Netflix
2024-02-22 09:31:57 -07:00
Warner Losh e54bb0ad80 loader: return errors from writing ZFS labels
vdev_write_bootenv_impl can only return success. Instead, return the
last error.  This will make any write errors more visible. The old code
masked kboot's inability to write bootenv.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D44018
2024-02-22 09:31:56 -07:00
Warner Losh b3e76e3d9e kboot: Implement write support for hostdisk
Don't assume that strategy is only called for read. Check the passed
flag for F_READ or F_WRITE and fail if it is neither. Open the disks for
writing and call host_read/host_write depending on that flag.

Sponsored by:		Netflix
Reviewed by:		kevans, gallatin
Differential Revision:	https://reviews.freebsd.org/D44016
2024-02-22 09:31:55 -07:00
Warner Losh b2822c40f6 loader/efi: Make gcc friendlier by move md_dev
Move the extern struct devsw md_dev out of the function. gcc is happier
with this arrangemnt often. However, we really should move it to a
header file, but that requires a bit of a rework of md support and
config.

Sponsored by:		Netflix
Reviewed by:		manu, tsoome
Differential Revision:	https://reviews.freebsd.org/D44008
2024-02-21 08:51:34 -07:00
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