Commit graph

1979 commits

Author SHA1 Message Date
Warner Losh d1a3cc0abe kboot: Define bi_loadsmap for loading memory maps
Each architecture will soon be required to provide this to load memory
maps as metadata for the platforms that require it (or a stub function
for those that don't).

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D38252
2023-02-03 08:41:39 -07:00
Warner Losh 2e53353280 kboot: Call enumerate_memory_arch()
Now that all architectures provide this, enumerate the platform's memory
before we go to interact(). This needs to be done only once, but relies
on our ability to open host: files on some platforms, so it needs to be
done after devinit().

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D38251
2023-02-03 08:41:39 -07:00
Warner Losh a967cd4db2 kboot: Update amd64 to use enumerate_memory_arch()
Move memory enumeration to the enumerate_memory_arch(), tweak the code a
bit to make that fit into that framework.

Also fix a bug in the name of the end location. The old code never found
memory (though amd64 doesn't yet work, this lead to using fallback
addresses that were good enough for QEMU...).

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38250
2023-02-03 08:41:39 -07:00
Warner Losh 1c98cd1569 kboot: aarch64 memory enumeration enumerate_memory_arch()
We have an odd situation with aarch64 memory enumeration. The fdt that
we can get has a PA of the UEFI memory map, as modified by the current
running Linux kernel so it can retain those pages it needs for EFI and
other services. We have to pass in this EFI tablem but don't have access
to it in the boot loader. We do in the trampoline code, so a forthcoming
commit will copy it there for the kernel to use. All for want of /dev/mem
in the target environment sometimes.

However, we also have to find a place to load the kernel, so we have to
fallback to /proc/iomem when we can't read the UEFI memory map directly
from /dev/mem. It will give us good enough results to do this task. This
table isn't quite suitable to be converted to the EFI table, so we use
both methods. We'll fall back to this method also if there's no EFI
table advertised in the fdt. There's no /sys file on aarch64 that has
this information, hence using the old-style /proc/iomem. We're unlikely
to work if there's no EFI, though.

Note: The underlying Linux mechanism is different than the amd64 method
which seems like it should be MI, but unimplemented on aarch64.

Sponsored by:		Netflix
Discussed with:		kevans
Differential Revision:	https://reviews.freebsd.org/D38249
2023-02-03 08:41:39 -07:00
Warner Losh 1d5f967fa7 kboot: Add powerpc stub for enumerate_memory_arch()
Add stub for new MI interface for enumerating memory. Right now powerpc
looks in the FDT table at a later point in boot since we don't need to
pass a specific memory table to the kernel. Leave it like that for now,
but note plans for the future.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38248
2023-02-03 08:41:39 -07:00
Warner Losh 81fbd74a4b kboot: space_avail -- how much space exists from 'start' to end of segment
Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D38313
2023-02-03 08:41:39 -07:00
Warner Losh 33e5b27254 kboot: Add parsing of /proc/iomem into seg.c
We'll be using this code for most / all of the platforms since iomem is
the only interface that can tell us of the reserved to the linux kernel
areas that we cannot place the new kernel into, but that we are free to
use once we hit trampoline. aarch64 will use this shortly, and similar
code in amd64 will be refactored when I make that platform work.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D38309
2023-02-03 08:41:39 -07:00
Warner Losh 08779e839a kboot: Create segment handling code at main level
Create segment handling code up to the top level. Move it all into
seg.c, and make necessary adjustments for it being in a new file,
including inventing print_avail() and first_avail() to print the array
and find the first large enough memory hole.  aarch64 will use this,
and I'll refactor the other platforms to use it as I make them work.

Sponsored by:		Netflix
Discussed with:		kevans
Differential Revision:	https://reviews.freebsd.org/D38308
2023-02-03 08:41:39 -07:00
Warner Losh 9e50222131 kboot: MI part of the memory enumeration code
enumerate_memory_arch is called once early in kboot's startup to allow
us to discover the memory layout, reserved areas, etc of the system
memory. Add the MI interface part of this.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D38247
2023-02-03 08:41:38 -07:00
Warner Losh fb26a14fc4 kboot: Add aarch64 fdt fixup
Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38256
2023-02-03 08:41:38 -07:00
Warner Losh d76330efd9 kboot: Probe all disks and partitions for a kernel
Guess where to boot from when bootdev= isn't on the command line or
other config. Search all the disks and partitions for one that looks
like it could be a boot partition (same as we do when probing
zpools). Return the first one we find.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D38319
2023-02-03 08:41:38 -07:00
Toomas Soome a1f8a0c793 efiserialio: use port settings (sio->Mode) for initial setup
Use serial port setup done by system firmware.
ARM64 Hyper-V does hung if we attempt to override the defaults,
therefore we should default to use settings from firmware.

Tested by: schakrabarti@microsoft.com
PR:		266248
MFC after:	1 week
2023-02-03 11:53:32 +02:00
Warner Losh ab926ba4c3 kboot: Remove kboot_loadaddr
Turns out that the loadaddr interface is not sufficiently expressive to
do the loading we need to do. Instead, we'll emulate some of its
features with inline math in copyin/copyout.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38260
2023-02-02 14:09:55 -07:00
Warner Losh 63c7a483e5 kboot: Assert errno is negative
When converting from a Linux error to a FreeBSD errno, assert that the
value passed in is negative, as is Linux's custom.

Suggested by:		brooks
Sponsored by:		Netflix
Reviewed by:		tsoome, brooks
Differential Revision:	https://reviews.freebsd.org/D38357
2023-02-02 14:09:55 -07:00
Warner Losh 7da605ec03 kboot: Parse memory usage
To properly size segments, we have to know how much memory we have in
the system, as well as how much this process can allocate.  Due to our
inability to overcommit, we need to know how much memory is
available. commit_limit is the grand total allowed. committed_as is the
current memory used. mem_avail is what Linux tells us is available. Find
these from /proc/meminfo. We'll use them later to allocate the biggest
possible segment sizes, but for now print the raw numbers.

Sponsored by:		Netflix
Reviewed by:		kevans (earlier version)
Differential Revision:	https://reviews.freebsd.org/D38267
2023-02-02 13:11:57 -07:00
Warner Losh 2e1edd04eb kboot: For hostfs, return better errors from read, where possible.
Translate the Linux error return from read to a FreeBSD errno. We use a
simplified translation: 1-34 are the same between the systems, so any of
those will be returned directly. All other errno map to EINVAL. This
will suffice for some code that reads /dev/mem in producing the right
diagnostic.

A fully generalized version is much harder. Linux has a number of errno
that don't translate well and has architecture dependent
encodings. Avoid this mess with a simple macro for now. Add comment
explaining why we use the simple method we do.

Sponsored by:		Netflix
Reviewed by:		kevans, andrew
Differential Revision:	https://reviews.freebsd.org/D38265
2023-02-02 13:06:31 -07:00
Warner Losh 81d71f94ca kboot: Fix hostdisk fmtdev
The device name was totally wrong. It should be "/dev/mumble:" not just
"mumble".

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D38318
2023-02-02 13:04:06 -07:00
Warner Losh 9fb276ea80 kboot: Trim initial allocation to 64MB
We only need 64MB to read off ZFS pools. Since Linux doesn't do
ovecommit by default, the extra 64MB is 64MB less we can allocate for
things like RAM disks.

Sponsored by:		Netflix
Reviewed by:		kevans, andrew
Differential Revision:	https://reviews.freebsd.org/D38268
2023-02-02 13:04:05 -07:00
Warner Losh ce18e19394 stand: only compute symidx on x86
We only use symidx on x86, so only compute it on x86 to fix a set but
not used warning on aarch64.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D38246
2023-02-02 13:04:05 -07:00
Emmanuel Vadot 04afa8cc37 loader: md: Use default func for fmtdev and parsedev
The default function are enough for md so use them instead of the
disks ones that doesn't work for it anymore.

Reviewed by:	imp
Sponsored by:	Beckhoff Automation GmbH & Co. KG
MFC after:	now
Differential Revision:	https://reviews.freebsd.org/D38218
2023-01-27 19:06:25 +01:00
Ed Maste ec96506307 lua: reduce diffs between luaconf.h copies
Upstream luaconf.h is contrib/lua/src/luaconf.h.dist, while userland lua
and loader lua have copies in lib/liblua/luaconf.h and
stand/liblua/luaconf.h.

Adjust whitespace, VCS tags, etc. to match upstream's version, for ease
of comparison.

Reviewed By:	imp
Sponsored By:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D38206
2023-01-26 12:38:19 -05:00
Warner Losh 4410e85796 stand/uboot: Remove -fPIC here
When needed, -fPIC is added in defs.mk. While not in main, mips on
stable/13 can't tolerate it. Remove it here.

MFC After:		now (it's a build issue)
Sponsored by:		Netflix
2023-01-25 08:04:59 -07:00
Warner Losh 4883f347f6 stand: dev can't be NULL in default_prasedev
We pass in the address of a variable to store this value always in the
only place that calls this function, so there is no need to test for NULL.

Sponsored by:		Netflix
Notied by:		tsoome in D38041
2023-01-13 15:54:44 -07:00
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
Warner Losh 3623222940 stand: i386_fmtdev can be reduced to devformat
devformat produces the same output as i386_fmtdev, so just use it to
reduce on the dependencies.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

The two existing options are now flags:

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

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

One additional flag is added:

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

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

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

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

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

Based on discussion at:
            https://github.com/llvm/llvm-project/issues/56306

MFC after:	1 day
Sponsored by:	Instituto de Pesquisas Eldorado (eldorado.org.br)
2022-07-29 05:13:19 -03:00
Warner Losh 9579540144 kboot: Make console raw when we start
Put the console into raw mode on startup. This allows the menus to work
as expected. Boot is now interruptable.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Sponsored by:		Netflix
Reviewed by:		delphij
Differential Revision:	https://reviews.freebsd.org/D35895
2022-07-24 16:53:36 -06:00
Warner Losh 1306a5dc07 stand/libsa: zfs use standard ZFS_EARLY stuff
Now that the minor issues preventing zfs.c from using CFLAGS_EARLY have
been fixed, use that mechanism like everything else that needs the
OpenZFS spl headers. This simplifies things somewhat. Update comments to
document why zfs.c is still special, though in different ways.

Note: We also use the fact that NEED_SOLARIS_BOOLEAN is only defined in
an environment where the solaris compat boolean stuff will be defined
prior to this point (eg, when we're building zfs.c in libsa), but not in
other environments (like when we're building mkimage and stand-alone
boot loaders that don't use libsa). These latter uses should be changed
to use the same ZFS compile env, but aren't as part of this commit.
This has to be done in the same change as the ZFS_EARLY change to not
break zfs.c building for one commit affecting bisectabiltiy.

Sponsored by:		Netflix
Reviewed by:		tsoome, delphij
Differential Revision:	https://reviews.freebsd.org/D35894
2022-07-24 16:53:36 -06:00
Warner Losh 09ace5cefb stand/zfs: Limit flags further for ZFS
Constrain CFLAGS for ZFS: don't add anything globally. Add the includes
to only the files that need them. Add -DHAS_ZSTD_ZFS to zfs.c (which
includes zfsimpl.c which includes zfssubr.c both of which need this
defined). Also add it to efi/boot1/Makefile since zfs_module.c also
includes zfsimple.c.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D35887
2022-07-24 16:53:35 -06:00
Warner Losh b3f43ee031 stand: Use c99 structure initialization for userboot's host_fsops
Sponsored by:		Netflix
2022-07-24 16:53:35 -06:00
Warner Losh b7625c2c2c stand: Use c99 structure initialization for gzipfs_fsops
Sponsored by:		Netflix
2022-07-24 16:53:35 -06:00
Warner Losh 9450d9c4e5 stand: Use c99 structure initialization for splitfs_fsops
Sponsored by:		Netflix
2022-07-24 16:53:35 -06:00
Warner Losh e7d045aa2b stand: Use c99 structure initialization for pkgfs_fsops
Sponsored by:		Netflix
2022-07-24 16:53:35 -06:00
Warner Losh 90a7e556a4 stand: Use c99 structure initialization for nfs_fsops
Sponsored by:		Netflix
2022-07-24 16:53:35 -06:00
Warner Losh 0ad8a113b7 stand: Use c99 structure initialization for bzipfs_fsops
Sponsored by:		Netflix
2022-07-24 16:53:35 -06:00
Warner Losh 12a41918a2 stand: Use c99 structure initialization for ext2fs_fsops
Sponsored by:		Netflix
2022-07-24 16:53:35 -06:00
Warner Losh c4f4a6c983 stand: Use c99 structure initialization for network device
Use c99 structure init for devsw.

Sponsored by:		Netflix
2022-07-24 16:53:34 -06:00
Warner Losh bf855d1bf2 stand: Use c99 structure initialization for fwohci device
Use c99 structure init for devsw.

Sponsored by:		Netflix
2022-07-24 16:53:34 -06:00
Warner Losh 4c460aaf83 stand: Use c99 structure initialization for userboot block device
Use c99 structure init for devsw.

Sponsored by:		Netflix
2022-07-24 16:53:34 -06:00
Warner Losh 1e3d1c86bc stand: Use c99 structure initialization for uboot block device
Use c99 structure init for devsw.

Sponsored by:		Netflix
2022-07-24 16:53:34 -06:00
Warner Losh e72a01f132 stand: Use c99 structure initialization for ofw's block device
Use c99 structure init for devsw.

Sponsored by:		Netflix
2022-07-24 16:53:34 -06:00
Warner Losh fc5d0d51aa stand: Use c99 structure initialization for kboot's hostdisk device
Use c99 structure init for devsw.

Sponsored by:		Netflix
2022-07-24 16:53:34 -06:00
Warner Losh 143452f760 stand: Use c99 structure initialization for md device
Use c99 structure init for devsw.

Sponsored by:		Netflix
2022-07-24 16:53:34 -06:00
John Baldwin bb7ddd077c stand geli: Restore include path to LDRSRC.
Various GELI sources need bootstrap.h and disk.h. In theory they
shouldn't need anything outside of libsa, but disk.h and bootstrap.h are
currently required.

This fixes the build with MK_LOADER_ZFS=no.

Obtained from: CheriBSD
Fixes: eaf7aabddc stand: geli CFLAGS tightening
Sponsored by: DARPA
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D35861
2022-07-22 10:08:46 -06:00
John Baldwin d1fb0e1dc8 stand libsa: Restore include path to LDRSRC for disk.h for filesystems.
In theory they shouldn't need anything outside of libsa, but disk.h and
bootstrap.h are currently required. Future work wil address this issue.

This fixes the build with MK_LOADER_ZFS=no. ZFS's Makefile.inc adds
these flags globally to CFLAGS when it should not. This masked the
problem because the tools/boot/universe.sh didn't build MK_LOADER_ZFS=no
as part of its regressions. Future work will also fix this.

Obtained from: CheriBSD
Fixes: 84bf2bbbec stand: constrain zlib/gzip CFLAGS better
Sponsored by: DARPA
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D35860
2022-07-22 10:08:40 -06:00
Dimitry Andric e60f6384f9 Adjust parse() definition in boot2 to avoid clang 15 warning
With clang 15, the following -Werror warning is produced:

    stand/i386/boot2/boot2.c:358:6: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]

This is because parse() is declared with a (void) argument list, and
defined with an empty argument list. Make the definition match the
declaration.

MFC after:	3 days
2022-07-15 21:18:28 +02:00
Warner Losh 01c58e7e4f kboot: Pull in constants from Linux's mmap.h api
Define the usual #defines for mmap(2) (with HOST_ prepended) and use
them instead of hard coding constants.

Sponsored by:		Netflix
2022-07-15 12:00:51 -06:00
Warner Losh 2870493f1f kboot: Properly cap number of segments loaded for kexec
Linux has an arbitrary limit of 16 segments. Make sure we don't load too
many.

Sponsored by:		Netflix
2022-07-15 12:00:51 -06:00
Warner Losh ffb0d016df kboot: Refinements to host_kexec_load
Move kexec_segments to host_syscall.h and pre-pend host_ to it.  Correct
args to host_exec_load.

Sponsored by:		Netflix
2022-07-15 12:00:51 -06:00
Warner Losh 8fa9263f67 kboot: Use #defines for magic reboot constants
Sponsored by:		Netflix
2022-07-15 12:00:51 -06:00
Warner Losh 8138a766b0 kboot: Implement mount(2)
Create a wrapper for the mount system call. To ensure a sane early boot
environment and to gather data we need for kexec, we may need to mount
some special filesystems.

Sponsored by:		Netflix
2022-07-15 12:00:50 -06:00
Warner Losh a99d47bcaa kboot: Implement mkdir(2)
mkdir() may be needed early in boot to create missing
directories. Provide a syscall wrapper for it.

Sponsored by:		Netflix
2022-07-15 12:00:50 -06:00
Warner Losh bc84de741d kboot: Implement dup(2)
Early in boot, we need to create the normal stdin/out/err env for the
boot loader to run in. To do that, we need to open the console and
duplicate the file descriptors which requires dup(2). Implement a
wrapper as host_dup.

Sponsored by:		Netflix
2022-07-15 12:00:50 -06:00
Warner Losh a4ed0eb1aa kboot: Implement symlink(2)
Linux's /dev/fd is implemented inside of /proc/self/fd, so we may need
to create a symlink to it early in boot. "/dev/fd" and "/dev/std*" might
not be strictly required for the boot loader, but should be present for
maximum flexibility.

Sponsored by:		Netflix
2022-07-15 12:00:50 -06:00
Warner Losh 764780294f kboot: Implement getpid(2)
Add host_getpid() so we can know if we're running as init(8) or not.  If
we are, we may chose to do early system setup / sanity operations.

Sponsored by:		Netflix
2022-07-15 12:00:50 -06:00
Warner Losh 76949f503f kboot: Implement munmap(2)
Define host_munmap so we can use it in the x86 code to find things for
the BIOS/CMS boot path and unmap after we find it.

Sponsored by:		Netflix
2022-07-15 12:00:50 -06:00
Warner Losh a647d4a4d1 kboot: Implement stat(2) and fstat(2) system calls
Implement stat(2) and fstat(2) in terms of newfstatat and newfstat
system calls respectively (assume we have a compat #define when
there's no newfstat and just a regular fstat and do so for ppc).

Snag struct kstat (the Linux kernel stat(2), et al interface) from musl
and attribute properly.

Sponsored by:		Netflix
2022-07-15 12:00:50 -06:00
Warner Losh ae366d5106 kboot: Add HOST_O_ constants for open, etc
Add the common O_ constants for the open, fcntl, etc system calls. They
are different than FreeBSD's. While they can differ based on
architecture, they are constant for architectures we care about, and
those architectures use the 'generic' version so future architectures
will also work.

Sponsored by:		Netflix
2022-07-15 12:00:50 -06:00
Warner Losh bf35f00522 kboot: Enhance kboot_getdev to cope with NULLs
Fallback to currdev when NULL is passed in when 'rootdev' is NULL. Other
getdevs do this. Additional features are needed here still, though.

Sponsored by:		Netflix
2022-07-15 12:00:50 -06:00
Warner Losh edc23ddf9c kboot: Reimplement older system calls in terms of newer ones
aarch64 doesn't have open, just openat, etc. Cope.

Sponsored by:		Netflix
2022-07-15 12:00:49 -06:00
Warner Losh f5ed1b0f84 kboot: Rework _start
Split _start into _start and _start_c (inspired by musl and the powerpc
impl is copied from there). This allows us to actually get the command
line arguments on all the platforms. We have a very simplified startup
that supports only static linking.

Sponsored by:		Netflix
2022-07-15 12:00:49 -06:00
Warner Losh c1bbe71104 stand: Remove extra efi.h include
There's nothing EFI specific about this file, so remove including efi.h.

Sponsored by:		Netflix
2022-07-15 12:00:49 -06:00
Toomas Soome f4ca0fdbe6 loader.efi: faults could try to print out call trace
with grab_faults, we can try to print out the trace of function calls.
Without symbol table, we can not translate addresses to function names,
but even addresses can help to track the bugs.

For loader functions, print out absolute address, so it could be
searched from objdump -d output.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D35433
2022-07-14 15:59:26 +03:00
Warner Losh 4773d3425e stand: Add comments on ZFS build
Add comments describing the weird nesting things we have to do to live
inside the ZFS world. Also fix a stale comment by moving nvlist.c to an
early user.

Sponsored by:		Netflix
2022-07-08 23:01:59 -06:00
Warner Losh 75ad24775b stand: Add blake3 support to boot loader
Add the necessary glue to get blake3 building for the boot loaded as
well as connected to the ZFS system so it is useful.

On some platforms, we create references to blake3_sse2_impl and
blake3_sse41_impl ops structs to utilize SIMD. These aren't present on
x86 (since we dind't ask for them), but are on aarch64 with no
implementation. Since we don't want SIMD in the boot loader, have these
all return 'unsupported' always. This should be fixed upstream to allow
more flexibility in this selection, but for now we use this hack to not
modify the sys/contrib/openzfs with difficult to maintain hacks while
an upstreamable solution is found.

tsoome@ did the implementation bits in sys/cddl/boot, and I did the
Makefile work and the aweful blake3_impl_hack.c.

Co-author:		tsoome@freebsd.org
Sponsored by:		Netflix
Reviewed by:		kevans (earlier version)
Differential Revision:	https://reviews.freebsd.org/D35750
2022-07-08 22:57:59 -06:00
Warner Losh df76778ad5 stand: delete zstd_shim.c
We no longer need to use this to get zfs_zstd.c compiling, so delete it.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D35750
2022-07-08 22:49:56 -06:00
Warner Losh 119c786f7b stand: Compile zfs_zstd.c directly now
Now that we have the ability to work around all the issues that
zstd_stub.c worked around, compile zfs_std.c directly.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D35750
2022-07-08 22:49:56 -06:00
Warner Losh b0a337d501 stand: Fix inclusion of sys/blake3.h
sys/blake3.h is not safe to include in a standalone environment. It
assumes, unwisely, that there's only kernel or userland. The userland
choice is bad due to imperfections in how we handle stdlib.h in this
environment (we wind up including the host's stdlib.h, it expects a
standard FreeBSD setup which the gymnastics we've done to create a
OpenSolaris/Illumos-like environment interfere with). Thankfully, in
this case we can just pretend to be the kernel for a little bit by
defining _KERNEL and the undefing it after we exit.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D35750
2022-07-08 22:49:55 -06:00
Warner Losh faf25f48d6 stand: Work around upstream issues in the standalone environment
There's a number of issues with including zfs_context.h from a
standalone environment. First, sys/uio_imp.h isn't at all safe for this
environment, so define its guard #defines so that its contents are
skipped. Next, there's a problem including string.h to get the mem*
routines, so just define them here. ZFS_MODULE_PARAM_ARGS isn't defined
properly. I had wanted to define it when I was upstreaming changes to
include/os/freebsd/spl/sys/zfs_context.h, but they ran into resistance
so I'm defining that here now (it is also defined in zstd_shim.c, but
that will disappear once the issues it works around are
cleared). Finally, sys/sysmacros.h has to be included now before
sys/atomic.h, but upstream includes it after so include it here so that
the guards make the out-of-order includes in upstream irrelevant.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D35750
2022-07-08 22:49:55 -06:00
Warner Losh 87d3aa5397 stand: For ZFS build, add new directory
OpenZFS is based on having a number of layers of include files that
define things and include the next layer. Insert a later at the start
for files in libsa/zfs/spl so we can override issues with upstream
OpenZFS while we work to get the issues corrected upstream.

Sponsored by:		Netflix
Reviewed by:		kevans
Differential Revision:	https://reviews.freebsd.org/D35750
2022-07-08 22:49:55 -06:00
Warner Losh 37dabb06e2 stand: Add comment about CFLAGS pollution
Add a note that veriexec / bearssl builds will pollute the CFLAGS in a
way that's somewhat hard to fix, so I'm just noting it for now.

Sponsored by:		Netflix
2022-07-08 11:47:37 -06:00
Warner Losh 84bf2bbbec stand: constrain zlib/gzip CFLAGS better
Define ZLIB_CFLAGS and use it only for the sources that are in ZLIB or
that include it.

Sponsored by:		Netflix
2022-07-08 11:47:37 -06:00
Warner Losh 59a4cfe03c stand: Confine BZIP defines to bzip files
Sponsored by:		Netflix
2022-07-08 11:47:37 -06:00
Warner Losh eaf7aabddc stand: geli CFLAGS tightening
Only add -DWEAK_REFS to sha256.c and sha512.c instead of
everything. Remove redundant include that's not needed.
Minor formatting tweak.

Sponsored by:		Netflix
2022-07-08 11:47:36 -06:00
Warner Losh 451ac17a50 stans: Narrow the scope of includes and other flags
CFLAGS+= here affects *ALL* libsa files being built. However, this is
only needed for zfs.c, so define it only for this. Also, use the defines
from defs.mk. Move all the zfs.c include hacks together. Also, move the
-Wformat -Wall warnings that were added to CFLAGS+= to the individual
files instead for the same reason.

Sponsored by:		Netflix
2022-07-08 11:47:36 -06:00
Warner Losh 0e5ac0ad03 stand: Use a for loop for all the common ZSTD files
Also add comments about why we're not using the BMI instructions when
vailable.

Sponsored by:		Netflix
2022-07-08 11:47:36 -06:00
Warner Losh 285f6ab665 stand: Separate out ZSTD sources from ZFS sources
Sponsored by:		Netflix
2022-07-08 11:47:36 -06:00
Warner Losh f424b167a3 stand: Don't reuse ZFSSRC
ZFSSRC is the top level directory where the ZFS sources come from. Don't
reuse it for a list of ZFS sources. Instead, use ZFS_SRC

Sponsored by:		Netflix
2022-07-08 11:47:36 -06:00
Warner Losh 2753bbe71b amd64/efi: Remove setting hints for rsdp
Given that hints set this way don't work when a static kenv is compiled
into the kernel. acpi.rsdp has been set for this for the past 6 years,
and all kernels in that time have used it in preference to the hints. As
such, we no longer hints.*, so remove them.

Sponsored by:		Netflix
Reviewed by:		jhb
Differential Revision:	https://reviews.freebsd.org/D35634
2022-07-02 08:02:12 -06:00
Warner Losh 37a3df3d61 loader: Set preferred kenv for acpi.rsdp on arm64
Several years ago, x86 moved from using hints to communicate this
information to using the simpler acpi.rsdp variables. If one compiles
static hints into the kernel, then these hints are ignored. We can
remove this when we branch FreeBSD 15. Thought about BURN_BRIDGES
here, but it's too messy.

Sponsored by:		Netflix
Reviewed by:		andrew, jhb
Differential Revision:	https://reviews.freebsd.org/D35632
2022-07-02 08:02:12 -06:00
Alfredo Dal'Ava Junior 5d48fb3b16 loader: fix powerpc* ofw loader
With the introduction of llvm14, the powerpc* loader used on ofw/pseries
for 32 and 64 bit architectures puts the .data.rel.ro section after
.data section. This caused a crash kernel didn't boot. Bisect pointed to
change https://reviews.llvm.org/D111717 but problem could be fixed by
adding a section description to make it appear in the expected order.

This patch is based on discussion at:
        https://github.com/llvm/llvm-project/issues/56306

MFC after:	1 day
Sponsored by:	Instituto de Pesquisas Eldorado (eldorado.org.br)
2022-07-01 12:56:46 -03:00
Albert Jakiela 1323f0aa9c stand/uboot: setup archsw before probing devices
In some cases ubldr would try to mount a disk device before
the archsw struct was filled with functions pointers.
This would result in a NULL pointer derefrence of the arch_getdev field.
Fix that filling the archsw functions earlier.
Note that this matches the EFI behavoiur.

Reviewed by: imp, mw
Sponsored by: Stormshield
Obtained from: Semihalf
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D35670
2022-07-01 13:36:41 +02:00
Ed Maste a765ac11c5 Remove "All Rights Reserved" from Foundation copyrights
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2022-06-30 10:49:09 -04:00
Warner Losh d8f3ef8f54 kboot: rename kexec_load to host_kexec_load
And make it match the system call more closely by passing in the proper
args.

Sponsored by:		Netflix
2022-06-27 14:54:45 -06:00
Warner Losh 201c1d0d25 kboot: sort system calls
Sort the system calls. No functional change intended.

Sponsored by:		Netflix
2022-06-27 14:54:45 -06:00
Warner Losh 43ad112b93 kboot: use SYS_kexec_load insteaed of __NR_kexec_load
Make this regular with the rest of the system calls.

Sponsored by:		Netflix
2022-06-27 14:54:45 -06:00
Warner Losh ce3e4a3a96 kboot: Sort system calls alphabetically
No functional change: sort the system calls alphbetically to make it
easier to add new ones.

Sponsored by:		Netflix
2022-06-27 14:54:45 -06:00
Toomas Soome e417249016 loader: GELI encrypted disk should still use device name disk
geli_probe_and_attach() does pick geli_devsw structure for
encrypted disks, the implementation depends on device
name "disk" when device type is DEVT_DISK, but geli_devsw is
setting name field "gelidisk".

PR:		264282
Submitted by:	yamagi@yamagi.org
Reported by:	yamagi@yamagi.org
MFC after:	2 weeks
2022-06-20 10:10:14 +03:00
Toomas Soome e368fb6eb6 userboot is missing vdisk_dev
Add vdisk device support in userboot configuration.

MFC after:	1 week
2022-06-19 21:29:49 +03:00
Toomas Soome 942e52f776 test_diskread(): detect end of the disk
Detect the end of the disk condition. This may happpen when
disk image is truncated and the reads are addressing blocks past
image end.

MFC after:		1 week
Differential Revision:	https://reviews.freebsd.org/D35432
2022-06-19 18:26:22 +03:00
Toomas Soome a2e02d9d8e loader.efi: fix panic() after BS off
panic() is using multiple services - attempting to read
keyboard, accessing time functions and finally, exiting the loader.

Protect all the accessed listed above. Note, when BS are off,
we really can not just exit the loader, we only can reboot.

MFC after:	1 week
2022-06-19 17:46:35 +03:00
Mark Johnston 9a964ad561 loader: Relax the check in is_kernphys_relocatable()
The check fails in kernels compiled with KASAN because AddressSanitizer
inserts redzones around global variables, so the size of the "kernphys"
symbol is 32 rather than 8.  Thus we fall back to copying even though
it's not necessary.

Simply remove the size check.  I didn't want to extend the symbol size
check since there's no guarantee that AddressSanitizer will always emit
32 bytes for "kernphys".

Reviewed by:	kib
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35448
2022-06-15 11:39:10 -04:00
Gordon Bergling c44b5e090d stand: Fix a common typo in source code comments
- s/independant/independent/

MFC after:	3 days
2022-06-05 09:49:51 +02:00
Martin Matuska e3aa18ad71 zfs: merge openzfs/zfs@b9d98453f
Notable upstream pull request merges:
  #12321 Fix inflated quiesce time caused by lwb_tx during zil_commit()
  #13244 zstd early abort
  #13360 Verify BPs as part of spa_load_verify_cb()
  #13452 More speculative prefetcher improvements
  #13466 Expose zpool guids through kstats
  #13476 Refactor Log Size Limit
  #13484 FreeBSD: libspl: Add locking around statfs globals
  #13498 Cancel in-progress rebuilds when we finish removal
  #13499 zed: Take no action on scrub/resilver checksum errors
  #13513 Remove wrong assertion in log spacemap

Obtained from:	OpenZFS
OpenZFS commit:	b9d98453f9
2022-06-03 18:17:53 +02:00
Andrew Turner 0d6600b579 Set mm before passing it to the UEFI firmware
When reading the UEFI memory map we pass in a pointer to the memory to
hold the map. Unfortunately it wasn't initialised before the first use
so clang decided it was undefined behaviour so the entire loop was
removed. This leads to everything in bi_load after this to also be
removed as dead code.

The next function after bi_load in the binary is efi_copy_init. The
above caused us to enter efi_copy_init with a return address of the
start of the function. Because of this it would enter an infinite
loop of calling the function, allocating memory, then returning to
the start of the function.

PR:		264021
2022-05-21 11:45:41 +01:00
Toomas Soome 9cd45772a4 libsa: mark head_errlog feature supported.
head_errlog is new format for errlog, but we do not really
use errlog, so we can just mark it supported, to enable reading
from pool.

MFC after:	1 week
2022-05-21 09:13:06 +03:00
Mark Johnston e097436cb2 libsa: Make the nvlist implementation more self-contained
Move declarations into a new nvlist.h rather than putting everything in
libzfs.h.  This makes this nvlist code easier to reuse elsewhere.  In
particular, the nvlist implementation in sys/contrib/libnv does not
provide XDR encoding, but this is needed when reading from or writing to
ZFS pools.

Also:
- Remove references to boolean_t.  It has to be a 32-bit int here, so
  just reference the underlying type.
- Add includes needed when compiling the nvlist code outside of stand/.

No functional change intended.

Reviewed by:	tsoome
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35255
2022-05-20 10:35:19 -04:00
Mark Johnston bcc3148c70 libsa: Fix a bug in nvlist creation
When adding an entry to an nvlist, the data buffer might need to be
resized.  When this happens, the XDR encoder's notion of the buffer size
also needs to be updated, otherwise the operation may erroneously fail.

Reviewed by:	tsoome, imp
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D35254
2022-05-20 10:34:43 -04:00
Ed Maste f70de61e56 loader.efi: add cross-reference to loader(8)
The loader.efi man page describes UEFI-specific loader details, but not
general loader information.

MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
2022-05-18 10:33:20 -04:00
Warner Losh 7df08a14e3 stand: Initial kboot support on amd64
Get amd64 compiling. However, the current kboot supports an old way of
enumerating memory and the new way needs to be incorporated as well. The
powerpc folks could use either, it seems and newer powerpc platforms
need some changes for kboot to work anyway.

This commit includes the linker script, trampoline code to start the new
kernel, Linux system calls and the necessary configuration glue needed
to build the binaries.

This includes a quick hack to get multiboot support, but we need to
really share these defines. The multiiboot2.h is the minimum needed to
build. We have multiboot information in three places now, so a
refactoring is in order.

This should be considered, at best, preliminary and experimental for
anybody wishing to try it out.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D35100
2022-05-01 11:13:39 -06:00
Warner Losh 70b5c4ff48 stand: Install libsa.3
Turns out there is a libsa.3. It's a bit out of date, but we reference
it in a number of places so we should install it. We need to do the DO32
dance because this Makefile is included twice and we don't want it
installing twice.

Sponsored by:		Netflix
2022-04-30 12:52:19 -06:00
Warner Losh 11f49259c8 stand: Change libstand.3 to libsa.3
Changes instances of the non-existant libstand.3 to the more correct,
but also non-existant libsa.3.

Sponsored by:		Netflix
2022-04-30 08:07:52 -06:00
Warner Losh bd001d86d6 stand: s/libstand/libsa/g to catch up with rename
We renamed libstand to libsa years ago with the move from sys/boot to
stand. Catch up in the comments.

Sponsored by:		Netflix
2022-04-30 07:34:19 -06:00
Kyle Evans 914dc91d12 stand: zfs: handle holes at the tail end correctly
This mirrors dmu_read_impl(), zeroing out the tail end of the buffer and
clipping the read to what's contained by the block that exists.

This fixes an issue that arose during the 13.1 release process; in
13.1-RC1 and later, setting up GELI+ZFS will result in a failure to
boot.  The culprit is this, which causes us to fail to load geom_eli.ko
as there's a residual portion after the single datablk that should be
zeroed out.

PR:		263407
Reviewed by:	tsoome
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D35019
2022-04-21 14:57:24 -05:00
Gordon Bergling 746cc38ec3 libsa: Fix a typo in a panic message
- s/occured/occurred/

MFC after:	3 days
2022-04-20 12:56:52 +02:00
Kyle Evans 660c1892d5 loader: userboot: provide a getsecs() implementation
We don't need it for userboot, but it avoids issues with BIND_NOW, so
just provide it.  time(3) isn't defined but ends up being provided by
libc linked into the host process, which is generally fine.

PR:	262920
Reviewed by:	imp, jhb
MFC after:	3 days
Diferential Revision:	https://reviews.freebsd.org/D34758
2022-04-12 19:33:54 -05:00
Kyle Evans 454630c725 stand: libefi: swap /Pci() printing around
Printing device followed by interface matches, e.g., edk2.  Note that
this is only a fallback, many firmware implementations will provide the
protocol that we'll use to format device paths.

Reviewed by:	imp, tsoome
Sponsored by:	Ampere Computing
Submitted by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D34539
2022-04-12 19:30:30 -05:00
Jens Schweikhardt 8e458a431e Clean up some grammos I left behind. 2022-04-11 20:24:11 +02:00
Jens Schweikhardt 67f5810e07 Correct typos and more precise wording. 2022-04-11 20:16:18 +02:00
Gordon Bergling 49f6a83ed8 stand: Remove a double word in a source code comment
- s/be be/be/

MFC after:	3 days
2022-04-09 09:27:34 +02:00
Jens Schweikhardt f7b0434d29 Correct a grammo. 2022-04-04 11:00:09 +02:00
Gordon Bergling ad49d7c54c loader.4th(8): Fix a typo in the manual page
- s/commmand/command/

MFC after:	3 days
2022-04-02 15:11:59 +02:00
Gordon Bergling 2d62a8653d powerpc64: Fix a typo in a source code comment
- s/converion/conversion/

MFC after:	3 days
2022-04-02 10:56:45 +02:00