Commit Graph

1806 Commits

Author SHA1 Message Date
Warner Losh
eb1795782c kboot: Use standard set_currdev
Use the standard set_currdev instead of the (now very old) copy of
setting currdev and loaddev directly. We do this only when we don't go
find the ZFS pool to boot from.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38012
2023-01-13 14:22:39 -07:00
Warner Losh
b7ecfa195f kboot: Add hostdisk override
When hostdisk_override is set, all the /dev devices are hidden, and only
the files in that directory are used. This will allow filesystem testing
on FreeBSD without root, for example. Adjust the parse routine to not
require devices start with /dev (plus fix a leak for an error
condition). Add a match routine to allow the device name to be something
like "/home/user/testing/zfsfoo:" instead of strictly in /dev. Note:
since we need to look at all the devices in the system to probe for ZFS
zpools, you can't generally use a full path to get a 'virtual disk' at
this time.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38011
2023-01-13 14:22:39 -07:00
Warner Losh
4f3be6b8d9 kboot: Fetch hostfs_root and bootdev from the environment
Fetch bootdev from the environment variable (so it should be set on the
command line). Default to 'zfs:' which will in the future look for the
first zpool that we can boot from. Prior versions of kboot would set
this from the second argument on the command line.

Fetch hostfs_root from the environment (defaulting to '/'). Prior
versions of kboot would set this from the first arg on the command line.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38010
2023-01-13 14:22:39 -07:00
Warner Losh
42e37d8caf kboot: Add ZFS support build glue
Now that all the pieces are in place, allow kboot to be built with ZFS
support.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38009
2023-01-13 14:22:39 -07:00
Warner Losh
f20ecce33a kboot: Add support for ZFS volumes
Add the zfs device and filesystem to config and write the hook we need
to probe zfs since there's not a generic mechanism in place to do that
when ZFS is configured.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38008
2023-01-13 14:22:39 -07:00
Warner Losh
cc82c650a7 kboot: Add ZFS support to hostdisk
Add helper function to walk through the disk drives we've found to look
for zpools. main.c will still need to call this because the loader
hasn't implemented a good way to 'taste' drives for zpools and/or GELI
partitions (mostly because there's no generic list of candidate
devices).

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38007
2023-01-13 14:22:38 -07:00
Warner Losh
1a13008e98 kboot: Rework hostdisk.c to allow easier ZFS support.
Keep a list of disks and partitions that we have. Keep track of the
sizes of the media and sector and use that to implement DIOCGMEDIASIZE
and DIOCGSECTORSIZE. Proivde a way to lookup disks by name.

Sponsored by:		Netflix
Reviewed by:		kevans (prior version)
Differential Revision:	https://reviews.freebsd.org/D38013
2023-01-13 14:22:38 -07:00
Warner Losh
5385c7e13b stand/zfs: Fix memory leaking on error cases
Now that we return an allocated zfs_devdesc, we have to free it. These
frees were missing from the error cases. In addition, simplify the code
a bit for the out of memory case.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38006
2023-01-13 14:22:38 -07:00
Warner Losh
5740057b43 stand/uboot: Explain why we test for NULL here
Most parsedev routines assume that idev is non-null and can always be
set. Since we break from this pattern in uboot, explain why in a
comment. devparse was invented to put a lot of common code in one place
and to simplify the archsw.arch_getdev code and any dv_parsedev code
called. However, uboot couldn't use devparse at the time because its
device naming scheme slightly different parsing. So, we still use
uboot_parsedev directly from uboot_getdev where dev could be NULL. Add a
comment to this effect.

The match functionality added for ofw likely could be used to clean up
the multiple kludges that are here for uboot's device naming differences
with the normal boot loader. This work will wait for the future.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38042
2023-01-13 14:22:38 -07:00
Warner Losh
d38d8a4c4e stand/ofw: dev can't be NULL here
dev can't be NULL here. ofw_common_parsedev is always called via
devparse (indirectly through dv_parsedev() calls there which call it
with the args unchanged). In the past, ofw_getdev could call us with
NULL pointer for the parse-only case, but that's now all handled inside
of devparse for simplicity.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38041
2023-01-13 14:22:38 -07:00
Warner Losh
d1ea501714 stand: Separate base and cli parts of nvstore
zfs lives in libsa. However, it depends on nvstore (and other things)
that are in common. Fix part of this layering violation by splitting
nvstore into a libsa piece (which is the base implementation) and
keeping a much smaller common piece (to implement the nvstore
command). This just leaves zfs' knowledge of device names that's
specific to common and its calling platform specific init code to
resolve. Add a nvstore.h file for these two parts to communicate private
things and move the public nvstore api from bootstrap.h to stand.h.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D38043
2023-01-13 14:22:38 -07: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
bf020787d5 stand: Move dev_cleanup into libsa
Since dev_cleanup() walks through all the devsw devices with dv_cleanup
rotuines, move it into libsa rather than having it in
'common'. Logically, it operates only on things that are in libsa, and
would never be different for different loaders: either people would call
it as is, or they'd do the loop themselves with 'special' things inline
between calls to cleanup (not that I think that will ever be needed
though).

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38004
2023-01-11 15:15:14 -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
23ed2a38c2 stand/efi: Better variable name
sanity_check_currdev returns true if it found a kernel or a sane loader
config file. A better name for this would be 'bootable' rather than 'rv'
which connotes in other places an errno value or similar.

Sponsored by:		Netflix
2023-01-09 10:12:40 -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
4dd3e76881 kboot: use 128MB for the heap area, ZFS needs a lot of memory
ZFS uses a lot of memory. The old minimal allocations won't work when
ZFS support is added. Most environments this will be used (or will
liekly be used) have >> 256MB, 128MB should be safe everywhere and allow
examination of a fair number of ZFS pools to boot from.

Sponsored by:		Netflix
2023-01-07 13:27:49 -07:00
Warner Losh
a0e4d18091 kboot: Sort kexec_load alphabetically
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37968
2023-01-07 13:24:45 -07:00
Warner Losh
2f5f17b80c stand: Add macros for file types from stat
Add the familiar macros for file types for stat's st_mode
member. Prepend HOST_ to the start of these. Make sure all the values
match the linux nolibc and uapi headers. These values are the same as
native values since they appear to be required by POSIX. Define anyway
to allow the reader of the code to know that they are in the 'host (eg
Linux)' namespace rather than the 'loader' namespace.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37967
2023-01-07 13:23:05 -07:00
Warner Losh
0386255bee kboot: Disks should be at least 16MB
Linux pre-boot environments will often have a number of psuedo disks
that are small, all smaller than a few MB. 16MB is a good cutoff since
it's big enough to filter these devices, yet small enough to allow a
super-minimal partition through (the smallest I've been able to make
that's useful lately is around 20MB).

Sponsored by:		Netflix
2023-01-07 13:20:44 -07:00
Warner Losh
538b73578b kboot: hostdisk.c update copyright notice
I've rewritten a substantial portion of this file, so add Netflix
copyright.

Sponsored by:		Netflix
2023-01-07 13:16:19 -07:00
Warner Losh
5cf20707ba stand: Allow stand.h to be included in C++ programs
Allow stand.h to be included in C++ programs. This is little more than
using our stylized __BEGIN_DECL / __END_DECL around the entire
file. There's no run-time support for C++, so the C++ that can be used
is quite limited. It is enough for libunwind, though.

Sponsored by:		Netflix
Reviewed by:		jrtc27, kevans
Differential Revision:	https://reviews.freebsd.org/D37946
2023-01-06 18:40:01 -07:00
Warner Losh
97e1430606 stand: Add inttype.h
libunwind files need inttype.h. It's safe so add it to the safe list.

Sponsored by:		Netflix
Reviewed by:		jrtc27, kevans
Differential Revision:	https://reviews.freebsd.org/D37947
2023-01-06 18:40:01 -07:00
Robert Clausecker
95fa2e0aee loader.efi: make sure kernel image is executable
The Windows Dev Kit 2023 (Volterra) has an UEFI implementation that maps
EfiLoaderData pages as non-executable.  Map the kernel as EfiLoaderCode
to ensure that it can be executed.

With this change and another in review, FreeBSD boots to the mountroot
prompt if hw.pac.enable = 0 is set in loader.conf(5).

Reviewed by:	andrew, imp, tsoome
Sponsored by:	Berliner Linux User Group e.V.
Sponsored by:	spline / FU-Berlin
Differential Revision: https://reviews.freebsd.org/D37931
2023-01-05 09:58:33 +00:00
Warner Losh
2e1e68cbae stand: Make ioctl declaration consistent
It typically had two args with an optional third from the userland
declaration in sys/ioccom.h. However, the funciton definition used a
non-optional char * argument. This mismatch is UB behavior (but worked
due to the calling convetions of all our machines).

Instead, add a declaration for ioctl to stand.h, make the third arg
'void *' which is a better match to the ... declaration before. This
prevents the convert int * -> char * errors as well. Make the ioctl
user-space declaration truly user-space specific (omit it in the
stand-alone build).

No functional change intended.

Sponsored by:		Netflix
Reviewed by:		emaste
Differential Revision:	https://reviews.freebsd.org/D37680
2022-12-12 21:46:34 -07:00
Warner Losh
e830a6cbbe kboot: Use (void) instead of () for functiosn with no args
`int foo();` means 'a function that takes any number of arguments.`
not `a function that takes no arguemnts`, that's spelled `int foo(void);`
Adopt the latter.

Sponsored by:		Netflix
2022-12-09 07:57:50 -07:00
Warner Losh
111610316e kboot: Allow loading fdt from different sources
Linux has /sys/firmware/fdt and /proc/device-tree to publish the dtb for
the system. The former has it all in one file, while the latter breaks
it out. Prefer the former since it's the more modern interface, but
retain both since I don't have a PS3 to test to see if its kernel is new
enough for /sys/firmware or not.

In addition, do the proper fixup.

Sponsored by:		Netflix
2022-12-08 22:07:52 -07:00
Warner Losh
1066a70e14 kboot: Need to find the ACPI tables
We need to pass the ACPI tables to the laucnhed kernel (at least for x86
and aarch64). Find it using the Linux standard way.

Sponsored by:		Netflix
2022-12-08 21:57:31 -07:00
Warner Losh
e1ff7945e1 stand/kboot: Parse the command line args
Do the standard command line parsing... With a small twist to deal with
the quirks of booting via linuxboot to the initrd from the command line
in shell.efi and other observed oddities.

Sponsored by:		Netflix
2022-12-07 11:00:54 -07:00
Warner Losh
667419d553 stand/efi: remove unused local varaibles
Remove some unused local variables. No functional change.

Sponsored by:		Netflix
2022-12-07 11:00:54 -07:00
Warner Losh
482380c6f8 stand/kboot: Remove unneeded include.
endian.h isn't needed for this file, so remove it.

Sponsored by:		Netflix
2022-12-07 11:00:54 -07:00
Warner Losh
299c64e316 stand/kboot: Initialize all the devices
main() of the boot loader is expected to call devinit() early. We do
this at the same time we do it in the EFI loader (except we don't have a
buffer cache here, we don't need to initialize time and we don't have
special efi partition handles to enumerate). This is just after we probe
for the console.

Sponsored by:		Netflix
2022-12-07 11:00:54 -07:00
Warner Losh
288626083b kboot: copy EFI's bootinfo.c and adjust
Copy EFI's bootinfo.c and make minor adjustments for kboot's needs. Do
not connect this to the build just yet until other pieces are in place.

Sponsored by:		Netflix
2022-12-07 11:00:54 -07:00
Warner Losh
b11aebff4d kboot: Mark the EFI specific parts of bootinfo.c
bootinfo.c is about to be shared with kboot since they create
substantially similar environments / metadata tagging / etc. Tag this
with #ifdef EFI for the moment until the proper abstracting out can
happen.

Sponsored by:		Netflix
2022-12-07 11:00:54 -07:00
Warner Losh
6b574b3ba9 stand/zlib: Document the upstream issue behind NO_DEPRECATED_NON_PROTOTYPE
The zlib project has issue https://github.com/madler/zlib/issues/633 to
document its continued use of old K&R-style function definitions.

Suggested by:		delphij@
Sponsored by:		Netflix
2022-12-05 16:59:58 -07:00
Warner Losh
335615c4ca stand: update prototypes for md_load and md_load64
These are declared as extern in a number of files (some with the wrong
return type). Centralize this in modinfo.h and remove a few extra stray
declarations as well that are no longer used. No functional change.

Note: I've not tried to cope with the bi_load() functions which are the
same logical thing. These will be handled separately.

Sponsored by:		Netflix
2022-12-05 16:59:58 -07:00
John Baldwin
0163de282e libsa: Disable -Wdangling-pointer for zfs.c.
GCC 12 warns about a dangling pointer to 'objid' in
zfs_bootenv_initial().  However, this appears to be a false positive
as the pointer to 'objid' is only passed to zfs_lookup_dataset() but
not saved anywhere that outlives the lifetime of the
zfs_bootenv_initial() function.

Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D37533
2022-12-04 16:27:22 -08:00
Warner Losh
9f7269677c kboot: Add md_addr to metadata
Save the address of where the metadata is loaded.

Sponsored by:		Netflix
2022-12-04 13:52:22 -07:00
Warner Losh
0ea00e71a2 kboot: Use #define for DT_DIR
Sponsored by:		Netflix
2022-12-04 13:31:06 -07:00
Warner Losh
8483b3add8 kboot: powerpc64 has no newfstat system call
Powerpc doesn't have a newfstat system call. It does have a fstat call,
which we define properly if SYS_newfstat isn't defined.

Sponsored by:		Netflix
2022-12-04 13:31:06 -07:00
Warner Losh
58091659cf kboot: Add aarch64 termios
Aarch64 has the generic termios interface, so use termios_gen.h

Sponsored by:		Netflix
2022-12-04 13:31:06 -07:00
Warner Losh
1fc8e9b833 kboot: Add missing license to termios
I neglected to include the proper license markings on these
files. Remedy that now.

Sponsored by:		Netflix
2022-12-04 13:31:06 -07:00
Warner Losh
929c6216b1 stand: aarch64 has different nlinks than amd64
Some typedefs are system dependent, so move them into stat_arch.h where
they are used.  On amd64, nlinks is a int64_t, while on aarch64 it's an
int (or int32_t).

Sponsored by:		Netflix
2022-12-03 22:53:18 -07:00
Warner Losh
e3b74ec119 kboot: powerpc ldscript catchup
Catch up with the latest ldscript for powerpc. Make it match others in
the tree.

Sponsored by:		Netflix
2022-12-03 21:41:28 -07:00
Warner Losh
aed1e5d332 stand/efi: Break stlye rules a little for easier sharing
Break the style rules a little to allow easier sharing between efi and
kboot. This will allow the ifdefs to be fewer in number.

Sponsored by:		Netflix
2022-12-03 17:23:25 -07:00
Warner Losh
3f2c1eb5b8 stand/efi: Better include order for sharing
Have a better include order so this can more easily be shared between
EFI and kboot. Fewer ifdefs and the same (enough) include order as
before.

Sponsored by:		Netflix
2022-12-03 17:23:22 -07:00
Warner Losh
3df86732af stand/efi: Remove redundant parenthesis
Style: Remove redundant parens.

Sponsored by:		Netflix
2022-12-03 17:23:20 -07:00
Warner Losh
67e39a0d1b stand/efi: Document the copy size trick
We call bi_copymodules twice: once with 0 and once with the size of the
arena. We do this to find the size, it turns out. Document this.

Sponsored by:		Netflix
2022-12-03 17:23:16 -07:00
Warner Losh
cc623784c1 kboot: Enable fewer things by default
We don't need NFS / network support by default, nor do we need gzip
support. Remove them for now.

Sponsored by:		Netflix
2022-12-03 12:48:45 -07:00
Warner Losh
4f6c506c6f kboot: Make dosfs support conditional
Sponsored by:		Netflix
2022-12-03 12:48:45 -07:00
Warner Losh
59cbe840cf kboot: Add readme
Document how to test kboot and how to build a initrd.

Sponsored by:		Netflix
2022-12-03 12:48:45 -07:00
Warner Losh
a2fbc88593 kboot: Move archsw init earlier
Do archsw init first thing.

Sponsored by:		Netflix
2022-12-03 12:48:45 -07:00
Warner Losh
da5d0a1dbc kboot: Use unsigned long long.
For the 64-bit platforms, this is a nop. Currently kboot only supports
64-bit platforms, though. If we support 32-bit in the future, this will
become important.

Noticed by:		rpokala
Sponsored by:		Netflix
2022-12-02 12:41:01 -07:00
Warner Losh
7685e8d97a kboot: Enhance hostdisk
Added missing functionality to allow us to boot off of things like
/dev/nvme0n1p2 successfully. And to list all available devices and
partitions with 'lsdev'.

Sponsored by:		Netflix
2022-12-02 11:31:26 -07:00
Warner Losh
c51e1d7c0a kboot: amd64 use /sys/firmware/memmap to find free memory
Use the system's firmware memory map to find a good place to put the
kernel that won't stomp on anything else. While this uses obstensibly MI
interfaces to get this data, arm64 doesn't have this, nor does
powerpc64, so place it here.

Sponsored by:		Netflix
2022-12-02 11:17:28 -07:00
Warner Losh
6f8e9f2273 kboot: move to using devparse
We can use devparse directly now. No need to invent a kboot_parsedev
that just does what devparse does now that we've refactored.

Sponsored by:		Netflix
2022-12-02 11:17:27 -07:00
Warner Losh
7e1a2e46aa kboot: Create routines to read Linux tiny files
Most of the files in /sys/ and /proc/ are small with one value. Create
two routines to help us read the file and decode that value.

Sponsored by:		Netflix
2022-12-02 11:08:11 -07:00
Warner Losh
f9ce8da864 stand/ofw: Refactor ofw parsedev
Both ofw_disk and ofw_net use the same parsedev routine, except for the
string passed in to match the ofw device node's type. Create a routine
to do that and connect these two users up to that.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37560
2022-11-30 15:30:34 -07:00
Warner Losh
854001759e stand/ofw: Use devparse
Retire the custom parsedev routine and use the standard devparse.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37559
2022-11-30 15:30:33 -07:00
Warner Losh
88a8c68298 ofw/disk: Add parsedev support
Add a parsedev support for OpenFirmware disks. We must look at
characteristics of the OFW node to know if we match this device (so
supply a match routine) or not. Add a parsing routine to allocate
devdesc for OpenFirmware disks as well.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37558
2022-11-30 15:30:33 -07:00
Warner Losh
b8ff248f65 stand/ofw: Subclass devnet to cope with ofw's unique needs
We need to match devices in a slightly special way: We have to look up
the path and see if the device is a 'network' device in order to use it.

Sponsored by:		Netflix
Tested by:		grehan@ (with tweaks to my original patch)
Differential Revision:	https://reviews.freebsd.org/D37557
2022-11-30 15:30:33 -07:00
Warner Losh
ed3cc2f248 stand/ofw: Add ofw_path_to_handle
ofw_path_to_handle converts a path string to a phandle_t. It searches
down the path for the first device whose type matches the passed-in
string.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37556
2022-11-30 15:30:33 -07:00
Warner Losh
40d340acb9 stand: Implement ofw disk print routine
Have lsdev show openfirmware devices.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37555
2022-11-30 15:30:33 -07:00
Warner Losh
a07cef5a73 stand: Add dv_match
On OpenFirmware, and possibly kboot, we use full path names for the
objects that are the 'device'. kboot uses a hack of knowing that all
disk device nodes start with '/dev', but this generalizes it for
OpenFirmware where both 'block' and 'network' devices live in the same
namespace and one must ask the OF node its type to know if this device
type matches.

For drivers that don't specify, the current convention of using
strncmp() is retained. This is done only in devparse(), but everything
uses it directly (or will soon).

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37554
2022-11-30 15:30:33 -07:00
Warner Losh
33bbe5ddcb stand: parsedev API change: devspec now points to start of full device name
To support more flexible device matching, we now pass in the full
devspec to the parsedev routines. For everything execpt uboot, this is
just a drop in (since everything except uboot and openfirmware always
uses disk...: and/or zfs:, but openfirmware isn't really affected).

uboot we kludge around it by subtracting 4 from where the rest of the
device name starts. This is unforunate, and can compute the address one
before the string. But we never dereference that address. uboot needs
more work, and this is an acceptable UB until that other work happens.

OFW doesn't really use the parsedev routines these days (since none of
the supported device uses this... yet). It too needs more work, but it
needs device matching support first.

Sponsored by:		Netflix
Reviewed by:		delphij
Differential Revision:	https://reviews.freebsd.org/D37553
2022-11-30 15:30:33 -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
daaf594e84 stand/ofw: ofw_disk isn't really a disk
The rest of the code in the tree assumes that a DEVT_DISK uses a
disk_devdesc to represent the device. However ofw_disk diesn't, so we
can't use disk_fmtdev, nor disk_parsedev. ofw needs to have a
dv_match-like routine to use devpasrse, though, since we have two
drivers (net and block) that claim the same sort of devices (eg
/path/to/ofw-dev) based on the device-type property. In the interim, we
can't use devmatch and ofw_disk's and the default net driver's parsing
is offloaded ofw_parsedev.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37347
2022-11-30 15:30:33 -07:00
Warner Losh
bb9f61da17 zfs: Remove devicename_stubs
We no longer need the zfs stubs since we're no longer referencing these
functions outside of zfs.c.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37345
2022-11-30 15:30:32 -07:00
Warner Losh
90412431fe stand: make zfs_parsedev static
It's now unreferenced outside of zfs.c.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37344
2022-11-30 15:30:32 -07:00
Warner Losh
d16083815c stand/ofw: Access the parsing routine more directly
We don't need to check if something is a ZFS device. Instead, if the
found device has a parse routine, call it. Otherwise, just copy the
path.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37343
2022-11-30 15:30:32 -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
641a0617e8 stand/i386: 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/D37341
2022-11-30 15:30:32 -07:00
Warner Losh
77378d79f1 stand/efi: 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/D37340
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
ca0654bad6 stand/zfs: Connect dv_parsedev to zfs_parsedev
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37348
2022-11-30 15:30:32 -07:00
Warner Losh
781ca0afcd stand: Introduce devparse to parse device / path strings
devparse is now the preferred interface to use to parse device
strings or device:/path strings. It parses the passed in string,
mallocs the device's particular devdesc string and returns the
'remainder' of the device:/path for further processing.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37338
2022-11-30 15:30:31 -07:00
Warner Losh
a0aad69f95 stand: Introduce new dv_parsedev routine
Allow device classes to define a parsing routine. Most device classes
already have these routines, but there's much duplication in their
use. Define an interface for a common routine to parse an individual
device. By convetion, files have the form "[device:]/path/to/file"
where device is optional (filled in to be the value of currdev)
and it starts with the dv_name field of the device, with the rest
of the name up to the device (typically a unit number, but disks
add partition inforation, and other devices may do artibtrary
otehr things).

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37337
2022-11-30 15:30:31 -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
983a18021d stand/zlib: Zlib still uses K&R function definitions
So add ${NO_WDEPRECATED_NON_PROTOTYPE} to the CFLAGS of those
files. This can be removed when we import a zlib that's free of this
anachronism.

Sponsored by:		Netflix
Reviewed by:		jhb
Differential Revision:	https://reviews.freebsd.org/D37516
2022-11-30 11:08:44 -07:00
Warner Losh
4c4563e32d ofw_net: Use c99 initializers
Update to use c99 initializers, although there's no plans to change
anything that this would make easier...

Sponsored by:		Netflix
Reviewed by:		zlei
Differential Revision:	https://reviews.freebsd.org/D37442
2022-11-29 14:49:06 -07:00
Warner Losh
b60164c9f4 stand/ofw: Use strpbrk instead of two strchrs
No need to call strchr twice, when one call to strpbrk will do the
job.. Test booted with qemu-powerpc + mac99 successfully.
Minor style(9) tweaks as well.

Sponsored by:		Netflix
2022-11-29 13:10:16 -07:00
Warner Losh
9f71565609 ofw: Remove old K&R function declaration
We don't need to forward declar strchr anymore.

Sponsored by:		Netflix
2022-11-27 13:34:33 -07:00
Warner Losh
fea231d21b ofw: Cast function pointer to proper type
clang 15 insists that we call entry() via a function prototype. Rather
than copping out and using (...), cast it to the same prototype that's
used elsewhere (with tweaks to pointers to make them fit into that
prototype). No functional change.

Sponsored by:		Netflix
2022-11-27 13:23:28 -07:00
John Baldwin
69f6399c37 libsa: Add missing GNU-stack annotations to _setjmp.S.
ld.bfd marks the stack as executable for the crt objects due to the
missing annotations which raises a fatal warning starting with version
2.39.
2022-11-22 08:36:40 -08:00
John Baldwin
03bbe1845d stand/libsa: Remove MIPS setjmp() and longjmp(). 2022-11-22 08:36:28 -08:00
Warner Losh
8a744de27e stand: Remove i386-only support fire firewire
Remove support for booting off of firewire, and for having dcons via
firewire in the loader. Kernel support for these things is unchanged.
Discussed on arch@ and the current state is not working (and the build
was wrong to boot).

Sponsored by:		Netflix
Discussed:		https://lists.freebsd.org/archives/freebsd-arch/2022-November/000267.html
Reviewed by:		kevans, melifaro, emaste
Differential Revision:	https://reviews.freebsd.org/D37334
2022-11-18 10:43:59 -07:00
Alexander Leidinger
f993fff689 Sort list of supported features for more easy handling
in the future.

Reviewed by:	imp
2022-11-10 09:47:23 +01:00
Warner Losh
269865a8ee stand: Update comment about devdesc
How devdesc is used is opaque until much code is read. Give a more
useful description of the theory behind it here.

Sponsored by:		Netflix
2022-11-04 19:46:44 -06:00
Warner Losh
c9ee39a3f2 stand: Remove unused enum
enum disk_ioctl is unused.  It's only ever defined. All of the stand
code uses DIOCGSECTORSIZE and DIOCGMEDIASIZE instead, both to query and
to implement ioctl.

Sponsored by:		Netflix
2022-11-04 15:40:12 -06:00
Elliott Mitchell
798ea06f07 stand: Nuke double-semicolons
A distinct number of double-semicolons have ended up in FreeBSD.  Take a
pass at getting rid of many of these harmless typos.

Reviewed by: emaste, imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/609
Differential Revision: https://reviews.freebsd.org/D31717
2022-11-02 09:34:54 -06:00
Warner Losh
02dba4f75f kboot: Add hostfs
Add hostfs for the Linux environment. We can't use the userboot one
that's kinda similar because the Linux system calls we have in kboot are
not quite POSIX compliant (Linux takes care of providing the POSIX
interface in libc), so we have to cope with a number of quirks in that
area.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D36607
2022-10-27 11:37:54 -06:00
Warner Losh
cc9f1b4c35 stand/kboot: Make FDT fixup per-arch
The fixups needed vary somewhat by architecture, so move the FDT fixup
to be per-arch. Rename the fdt_linux_fixup() routine to be
fdt_arch_fixup() and expect all architecutres to fix things up as
needed.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D36604
2022-10-27 11:36:51 -06:00
Warner Losh
eca818c872 stand/efi: Simpler construct
Use 'sizeof(long) == 8' for a compile time constant that can be used as
an initializer rather than #ifdefs.

Sponsored by:		Netflix
2022-10-24 12:13:03 -06:00
Warner Losh
e0c3f66b4d stand/efi: Call md_copymodules based on __LP64__ to fix 32-bit arm
When I refactored everything, I neglected to pass in the proper is64
value on 32-bit platforms. This corrects that. This prevented armv7 and
armv6 platforms from booting due to misaligned data in the kernel.  The
only platform we support 32-bit booting in armv[67], which I apparently
neglected to test before commiting my refactoring.

Tested by:		skibo
Fixes:			5d1531d9d4
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D37095
2022-10-22 19:47:25 -06:00
Warner Losh
2cb90a7b2e stand/kboot: hostdisk isn't a DEVT_DISK, use a different value.
We assume in all the code that a DEVT_DISK uses common/disk.c and/or
common/part.c and we can access a struct disk_devdesc. hostdisk.c
opens raw devices directly, so has no such structures. Define a
kboot-specific DEVT_HOSTDISK and use that instead.

In addition, disk_fmtdev assumes it is working with a struct
disk_devdesc, so write hostdisk_fmtdev as well.

Sponsored by:		Netflix
2022-10-22 19:47:24 -06:00
Warner Losh
bb3230e40b geli: Move check for DEVT_DISK into geli_probe_and_attach
We only work on DEVT_DISK disks, so move that into the probe to drive
the point home better.

Sponsored by:		Netflix
2022-10-22 19:47:24 -06:00
Warner Losh
787df454c8 stabd/geli: Bail out if you can't get the disks size
If the DIOCGMEDIASIZE ioctl fails, assume the disk doesn't have geli
encryption. While all disks should implement this, fail safe for disks /
partitions that do not.

Sponsored by:		Netflix
2022-10-21 17:39:34 -06:00
Kyle Evans
0701dbda94 loader: fix elf lookup_symbol type filtering
The existing logic doesn't seem to make much sense, as we won't filter
on the type if st_shndx != SHN_UNDEF.  In practice, this breaks booting
12.3 kernels on newer loaders, as they do have a `kernphys` symbol of
the wrong type (NOTYPE, rather than OBJECT) -- we end up deriving the
wrong value for copy_staging.

It's unclear if this version makes any more sense, but it seems to match
what rtld's matched_symbol() does.  Loader doesn't need to care about
STT_FUNC w/ UND shndx, because we won't encounter those; in kmods,
undefined (kernel) functions are NOTYPE.

Reported by:	Christian McDonald <cmcdonald netgate com>
Reviewed by:	imp, kib, tsoome
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D36975
2022-10-13 22:07:52 -05:00
Warner Losh
6700f34d12 kboot: hostdisk add to lsdev output
Not entirely sure what to do here, so just list that we're here.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D36606
2022-10-07 23:46:20 -06:00
Warner Losh
beba54e4b8 kboot: Move load address stuff to MD code
The load address computations are highly architecture specific. There
are generic ways that are augmented by specific constraints of specific
way things work on each architecture. Move the current load segment
computations into a MD routine load_addr.

As part of the move, I'm marking kboot_get_kernel_machine_bits as
unused. This arrived in a prior commit, but never seems to have been
connected, suggesting an incomplete merge at the time, or a path not yet
taken.

Create a stub for amd64 that will be filled in with a later commit.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D36603
2022-10-07 23:43:04 -06:00
Michał Grzelak
7b54d275ef libsa/netif.c: Replace #if with #ifdef
Follow the convention with *_DEBUG macros in stand/libsa/* and replace
"#if" with "#ifdef".

Reviewed by:	kd
Obtained from:	Semihalf
Differential Revision: https://reviews.freebsd.org/D36740
2022-09-29 12:52:02 +02:00
Michał Grzelak
c66c6da4f0 libsa/arp.c: Change printf format string
Change printf format string to avoid compilation failure when
ARP_DEBUG macro is defined.

Reviewed by:	imp
Obtained from:	Semihalf
Differential Revision: https://reviews.freebsd.org/D36735
2022-09-29 12:51:14 +02:00
Michał Grzelak
ee0d06faa0 libsa/rarp.c: Change casted type and printf format
Change the casted type and printf format string to avoid compilation
failure when RARP_DEBUG macro is defined.

Reviewed by:	imp
Obtained from:	Semihalf
Differential Revision: https://reviews.freebsd.org/D36738
2022-09-29 12:51:14 +02:00
Michał Grzelak
1ed7916188 libsa/rarp.c: Change printf format string
Change printf format string to avoid compilation failure when
RARP_DEBUG macro is defined.

Reviewed by:	imp
Obtained from:	Semihalf
Differential Revision: https://reviews.freebsd.org/D36739
2022-09-29 12:51:14 +02:00
Martin Matuska
c7046f76c2 zfs: merge openzfs/zfs@c629f0bf6
Notable upstream pull request merges:
  #13725 Fix BLAKE3 tuneable and module loading on Linux and FreeBSD
  #13756 FreeBSD: Organize sysctls
  #13773 FreeBSD: add kqfilter support for zvol cdev
  #13781 Importing from cachefile can trip assertion
  #13794 Apply arc_shrink_shift to ARC above arc_c_min
  #13798 Improve too large physical ashift handling
  #13799 Revert "Avoid panic with recordsize > 128k, raw sending and
         no large_blocks"
  #13802 Add zfs.sync.snapshot_rename
  #13831 zfs_enter rework
  #13855 zfs recv hangs if max recordsize is less than received
         recordsize

Obtained from:	OpenZFS
OpenZFS commit:	c629f0bf62
2022-09-21 14:17:13 +02:00
Warner Losh
4a676571e3 stand: Pass in the proper size for bootinfo
Missed one sizeof(bi) -> sizeof(*bi) in 9758dd3de1 conversion to
allocating bootinfo.

Noticed by:		tijl@
Fixes:			9758dd3de1
Sponsored by:		Netflix
2022-09-17 15:18:29 -06:00
Warner Losh
dd2b9c2967 stand: fix mismerge
Remove stray line from mismerge of 5d1531d9d4. This is no longer
needed.

Fixes:			5d1531d9d4
Sponsored by:		Netflix
2022-09-16 10:54:04 -06:00
Warner Losh
c0ecae78ab stand/elf: Only support swapping headers on powerpc.
Powerpc is currently the only architecture that we support more than one
endian. It's the only one that benefits from this swapping, so restrict
the code to there. This saves about 1k in the i386 BIOS loader.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D36577
2022-09-16 09:18:57 -06:00
Warner Losh
9758dd3de1 stand: Allocate bootinfo rather than have it be static
This saves 80 bytes (the new bootinfo structure was 84 bytes, and a
pointer is 4 bytes). The bi_load32 code is the same size.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D36575
2022-09-16 09:18:57 -06: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
2e6ed47a46 stand: Move MOD_xxx macros from modinfo.h to .c
Now that MOD_xxx macros are modinfo.c, they don't need to be in
modinfo.h.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D36573
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
a705c72f21 stand: use archsw.arch_copyin instead of i386_copyin
Since archsw.arch_copyin is always i386_copyin, this will be a nop in
terms of functionality. This is a diff reduction against other copies of
the code that differ only by what copyin routine they call.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D36568
2022-09-16 09:18:56 -06:00
Guido van Rooij
0f97a0d425 stand/efi: Clean the proper files
Need to clean the specific loader we build, not the generic loader.efi

Reviewed by: imp
2022-09-15 09:13:52 -06:00
Warner Losh
45ad955714 stand: Add driver interface docs
Add some rather bare-bones driver interface docs.

Sponsored by:		Netflix
Suggestions by:		rpokala
Reviewed by:		pauamma
Differential Revision:	https://reviews.freebsd.org/D35912
2022-09-09 17:25:59 -06:00
Kyle Evans
72291cee07 stand: i386: take into account disk sector size for blk calculation
disk_blocks assumes BIOSDISK_SECSIZE, but the media may not be using
it.  In particular, bioscd on Parallels presents a 2K sector size, so
we end up with a short disk_blocks and subsequent validation fails when
trying to read /boot/lua.

PR:		233098
Reviewed by:	imp, tsoome
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D36490
2022-09-08 10:05:08 -05:00
Michael Gmelin
0eb736c0f6 stand: Unbreak FAT32 in loader
This corrects an issue introduced in b4cb3fe0e3, where a freshly
allocated `DOS_FS` structure would not be initialized properly before
use in `dos_open`.

In case of FAT32 file systems, this would leave `fs->dirents`
uninitialized and - depending on its content and due to checks in
`parsebs` - prevent mounting the file system successfully.

This particularily impacted the EFI loader, as it was sometimes not
able to read files from a FAT32-formatted EFI partition, including
LoaderEnv (`/efi/freebsd/loader.env`).

Accepted by:	imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D36482
2022-09-08 02:16:34 +02:00
Konstantin Belousov
85c8c0b77d loader.efi(8): document slop control, amd64 nocopy, and amd64 fault commands
Reviewed by:	imp
Discussed with:	gbe (man pages)
English wording help by:	rpokala
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
Differential revision:	https://reviews.freebsd.org/D36435
2022-09-06 18:55:45 +03:00
Michael Gmelin
2b3543dbb1 stand: Parse all arguments passed by UEFI
Approved by:	imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D36457
2022-09-06 13:39:08 +02:00
Gordon Bergling
3c6db09bf4 Revert "stand: Grammar fix for a source code comment"
This reverts commit 7d91d6b83e.

The orginal comment is more natural.

Reported by:jrtc27
2022-09-05 15:40:55 +02:00
Warner Losh
cc7b630cec stand/kboot: Add note about why we use MACHINE_ARCH here
Normally in the boot loader, we key off of MACHINE since that specifies
the kernel and the loader is very tuned to each type of MACHINE in
general. In this case, however, we're producing a Linux binary, with
Linux system calls encoded in it. These align better along the
MACHINE_ARCH axis of FreeBSD. For PowerPC the system calls are radically
different for each of our MACHINE_ARCHes, with only powerpc64 and
powerpc64le sharing the same numbers and memory layout. The same was
true about mips when it was in the tree. 32-bit arm uses the same
layout, however, for both armv6 and armv7 ports: that can be easily
shared in the unlikely event we support that in the future.

Sponsored by:		Netflix
2022-09-04 09:37:42 -06:00
Gordon Bergling
7d91d6b83e stand: Grammar fix for a source code comment
- s/that that/that this/

MFC after:	3 days
2022-09-04 17:26:48 +02:00
Gordon Bergling
e30a08016b stand: Remove a double word in a source code comment
- s/the the/the/

MFC after:	3 days
2022-09-04 13:39:35 +02:00
Jessica Clarke
9b17aa2740 lualoader: Add loader_menu_multi_user_prompt config variable
This allows the "Multi user" in "[B]oot Multi user" to be substituted
with another string, for example with "Installer" in installer media.
Note that this is lua-only at the moment, since loader.4th's menu.rc
defines the alternate name as Boot [M]ulti User, unlike lualoader which
leaves it as [B]oot Multi user. Ideally loader.4th would adopt the newer
and simpler lualoader behaviour and then it could gain support for this
option, but loader.4th is on the way out and isn't used by any official
installer media so this is not a significant concern.

Reviewed by:	kevans, rpokala
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D36418
2022-09-02 20:30:40 +01:00
Kornel Dulęba
66c73af7ea stand: Parse BIOS revision from SMBIOS
Add a smbios.bios.revision kenv, which contains the system BIOS revision
as defined in SMBIOS specification, section 3.3.1.
Since the revision is stored in two separate byte fields,
the smbios_setenv helper can't be used.
Read and construct the kenv manually instead.

Approved by:	mw(mentor)
Sponsored by:	Stormshield
Obtained from:	Semihalf
Differential Revision:	https://reviews.freebsd.org/D36413
2022-09-02 13:10:32 +02:00
Warner Losh
69818bcf38 kboot: List sources one per line to make merges easier
Make SRC an alphabetical list of files, one per line.

Sponsored by:		Netflix
2022-09-01 11:08:32 -06:00
Warner Losh
57f90cf813 kboot: add minmalist init functionality
It is desirable to run kboot as the first program in some LinuxBoot
environments. This is the traditional "pid 1" or "init" program. When
running as pid 1. rovide a minimal environment based on what sysvinit,
u-root, initramfs-tools and other like projects do. We mount /dev, /sys,
/proc, make symlinks from /dev/fd to /dev/proc, and create /tmp, /run,
and /var. We also setup stdin/out/err to the console, set the tty
characteristics of same and block the appropriate signals.

This is indended as an environment that never does a fork/exec. If
that's required, the process groups, session leaders and all things
POSIX terminal handlers will need to be added.

Unlike the general purpose linux projects in this area, no attempt is
made to support very old kernels.

When not pid 1, we skip all of the above.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D36368
2022-09-01 11:08:24 -06:00
Warner Losh
29fc4075e6 stand: Add lua binding loader.has_command
Give scripts the ability to determine if the currently running loader
has provided a command.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D36365
2022-09-01 11:08:22 -06:00
Warner Losh
a5948d40ad stand: Add interp_has_builtin_cmd to see if we have a command
interp_has_builtin_cmd() will try to lookup the passed in command and
returns true if it was found, false otherwise.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D36364
2022-09-01 11:08:19 -06:00
Warner Losh
113dfadd5c stand: separate the command lookup from the command execution
Factor out interp_lookup_cmd to search for a command from
interp_builtin_cmd. This simplifies the latter and can be used to expand
lua to ask if a command exists.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D36363
2022-09-01 11:08:16 -06:00
Warner Losh
75a91c70f8 stand: Document EFI consoles
Document how EFI consoles work, at least on x86. There's a number of
weird quirks and limitations that are generally known, but not
documented until now. Include information on how EFI decides what the
defualt console is, how to set it and how to cope with common
situations. Note limitations and mismatch between ACPI (which uses UID
to identify a device) and our console code (which uses a raw address)
and explain why we can't translate between them in the loader.

Sponsored by:		Netflix
Reviewed by:		manu, kevans, rpokala, pauamma
Differential Revision:	https://reviews.freebsd.org/D36286
2022-09-01 10:34:30 -06:00
Warner Losh
b1819983e7 stand: Stop setting hints for bios loader too
Catch up to 2753bbe71b and remove the old hints.

Sponsored by:		Netflix
2022-09-01 10:33:09 -06:00
Warner Losh
7ed3228323 stand: Document that boot0 uses BIOS
And thus has a limited range of supported baud rates. Also add that
setting BOOT_BOOT0_COMCONSOLE_SPEED=0 will leave it unchanged which
sometimes can give you 115200 if the BIOS initialized things outside of
the normal BIOS baud rates (which many x86 enbedded-targetted boards
do).

Sponsored by:		Netflix
Reviewed by:		emaste, manu (earlier versions)
Suggestions by:		jhb
Differential Revision:	https://reviews.freebsd.org/D36300
2022-08-26 22:17:56 -06:00
Warner Losh
df065f699f stand: More sensible defaults when ConOut is missing
When ConOut is missing, we used to default to serial. Except we did it
in the worst way possible by just setting the howto bits and not
updating the console setting, which lead to weird behavior where we'd
get some things on the video port, others on serial.

Instead, set console to "efi,comconsole" for this case. Also set
RB_MULTIPLE always (so we get dual consoles from the kernel) and or in
RB_SERIAL when we can't find GOPs that suggest the precense of a video
console. This will put output in the most places and have a sensible
default for 'primary' console.

Sponsored by:		Netflix
Reviewed by:		emaste, manu
Differential Revision:	https://reviews.freebsd.org/D36299
2022-08-26 22:17:56 -06:00
Warner Losh
9d70108a74 stand: Use bool for stage_offset_set
stage_offset_set is a boolean, convert it to a bool.

Sponsored by:		Netflix
2022-08-21 09:48:02 -06:00
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