]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
17 months agostand/ofw: Refactor ofw parsedev
Warner Losh [Wed, 30 Nov 2022 22:10:23 +0000 (15:10 -0700)]
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

(cherry picked from commit f9ce8da86434867e1e7172fb56a5504f91c98ce4)

17 months agostand/ofw: Use devparse
Warner Losh [Wed, 30 Nov 2022 22:10:18 +0000 (15:10 -0700)]
stand/ofw: Use devparse

Retire the custom parsedev routine and use the standard devparse.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D37559

(cherry picked from commit 854001759e59172a2760d3a77f37a287f92053b3)

17 months agoofw/disk: Add parsedev support
Warner Losh [Wed, 30 Nov 2022 22:10:11 +0000 (15:10 -0700)]
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

(cherry picked from commit 88a8c68298dbc86370d9a7eff06314da398829cb)

17 months agostand/ofw: Subclass devnet to cope with ofw's unique needs
Warner Losh [Wed, 30 Nov 2022 22:10:05 +0000 (15:10 -0700)]
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

(cherry picked from commit b8ff248f6595067ef9a31d5d4cec5fb9b9052fc3)

17 months agostand/ofw: Add ofw_path_to_handle
Warner Losh [Wed, 30 Nov 2022 22:10:00 +0000 (15:10 -0700)]
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

(cherry picked from commit ed3cc2f24829e6c5827f142cfcd9729331a1106c)

17 months agostand: Implement ofw disk print routine
Warner Losh [Wed, 30 Nov 2022 22:09:56 +0000 (15:09 -0700)]
stand: Implement ofw disk print routine

Have lsdev show openfirmware devices.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D37555

(cherry picked from commit 40d340acb9316db5771fe777e279776b903336d4)

17 months agostand: Add dv_match
Warner Losh [Wed, 30 Nov 2022 22:09:51 +0000 (15:09 -0700)]
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

(cherry picked from commit a07cef5a738642ae0a39fa513945d9f867a5e2f1)

17 months agostand: parsedev API change: devspec now points to start of full device name
Warner Losh [Wed, 30 Nov 2022 22:09:36 +0000 (15:09 -0700)]
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

(cherry picked from commit 33bbe5ddcbbce03b6395a4948927643107b55c06)

17 months agostand: create devinit
Warner Losh [Wed, 30 Nov 2022 22:09:29 +0000 (15:09 -0700)]
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

(cherry picked from commit 66012c8fc4f92b80a61405dc7e206617e9f08920)

17 months agostand/ofw: ofw_disk isn't really a disk
Warner Losh [Wed, 30 Nov 2022 22:09:23 +0000 (15:09 -0700)]
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

(cherry picked from commit daaf594e8469b1fb4fb7861c2f7129f4d61c6d4d)

17 months agozfs: Remove devicename_stubs
Warner Losh [Wed, 30 Nov 2022 22:09:18 +0000 (15:09 -0700)]
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

(cherry picked from commit bb9f61da17f66352a344e14c4d32fda83126827b)

17 months agostand: make zfs_parsedev static
Warner Losh [Wed, 30 Nov 2022 22:09:14 +0000 (15:09 -0700)]
stand: make zfs_parsedev static

It's now unreferenced outside of zfs.c.

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D37344

(cherry picked from commit 90412431fe1bf5f4a10b68c7938b0fc9f11dc4a2)

17 months agostand/ofw: Access the parsing routine more directly
Warner Losh [Wed, 30 Nov 2022 22:09:09 +0000 (15:09 -0700)]
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

(cherry picked from commit d16083815caf32dd117487c709b33669cef4af6f)

17 months agostand/userboot: Move to using common devparse()
Warner Losh [Wed, 30 Nov 2022 22:09:05 +0000 (15:09 -0700)]
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

(cherry picked from commit 910de60a7e43c593b5126b2f1ee468c089c8116e)

17 months agostand/i386: Move to using common devparse()
Warner Losh [Wed, 30 Nov 2022 22:09:00 +0000 (15:09 -0700)]
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

(cherry picked from commit 641a0617e8d060c3c5fb997cee9e2b7fb40d9306)

17 months agostand/efi: Move to using common devparse()
Warner Losh [Wed, 30 Nov 2022 22:08:55 +0000 (15:08 -0700)]
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

(cherry picked from commit 77378d79f165b59296a0133eb910af55c8b2b600)

17 months agostand: For all disk drivers, connect dv_parsedev to disk_parsedev
Warner Losh [Wed, 30 Nov 2022 22:08:51 +0000 (15:08 -0700)]
stand: For all disk drivers, connect dv_parsedev to disk_parsedev

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D37339

(cherry picked from commit 8337ab69ba8e065e5cfde8f09859ec1d0d47e892)

17 months agostand/zfs: Connect dv_parsedev to zfs_parsedev
Warner Losh [Wed, 30 Nov 2022 22:08:47 +0000 (15:08 -0700)]
stand/zfs: Connect dv_parsedev to zfs_parsedev

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D37348

(cherry picked from commit ca0654bad68d521066497e708cfb56f5f3f5d1fa)

17 months agostand: Introduce devparse to parse device / path strings
Warner Losh [Wed, 30 Nov 2022 22:08:42 +0000 (15:08 -0700)]
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

(cherry picked from commit 781ca0afcd6c64ac3fbaf2a19b1880734cdfe947)

17 months agostand: Introduce new dv_parsedev routine
Warner Losh [Wed, 30 Nov 2022 22:08:36 +0000 (15:08 -0700)]
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

(cherry picked from commit a0aad69f9556221283b8f6ddcd332329b50463e4)

17 months agostand: Change zfs_parsedev() API
Warner Losh [Wed, 30 Nov 2022 22:08:22 +0000 (15:08 -0700)]
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

(cherry picked from commit ba11bc368e612e7c5bbc195830a280f8af73ce18)

17 months agostand: Change disk_parsedev() API
Warner Losh [Wed, 30 Nov 2022 22:08:15 +0000 (15:08 -0700)]
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

(cherry picked from commit 17276525fa1a28028f7ca423f365d5081cbe9a97)

17 months agostand/zlib: Zlib still uses K&R function definitions
Warner Losh [Wed, 30 Nov 2022 18:08:24 +0000 (11:08 -0700)]
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

(cherry picked from commit 983a18021decd68fbcf5d14ccd60c3d66dac1c6a)

17 months agoofw_net: Use c99 initializers
Warner Losh [Tue, 29 Nov 2022 21:47:02 +0000 (14:47 -0700)]
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

(cherry picked from commit 4c4563e32dfce0652953fcbd160a9dfdda050cc4)

17 months agostand/ofw: Use strpbrk instead of two strchrs
Warner Losh [Tue, 29 Nov 2022 20:02:40 +0000 (13:02 -0700)]
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

(cherry picked from commit b60164c9f4d823b3e9fbcb733f92d181c704f415)

17 months agoofw: Remove old K&R function declaration
Warner Losh [Sun, 27 Nov 2022 20:34:33 +0000 (13:34 -0700)]
ofw: Remove old K&R function declaration

We don't need to forward declar strchr anymore.

Sponsored by: Netflix

(cherry picked from commit 9f7156560905f5da0b42dce3e5fb64f77e9f70aa)

17 months agoofw: Cast function pointer to proper type
Warner Losh [Sun, 27 Nov 2022 20:23:28 +0000 (13:23 -0700)]
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

(cherry picked from commit fea231d21b299535302b41ac2e841f8abf1787fc)

17 months agolibsa: Add missing GNU-stack annotations to _setjmp.S.
John Baldwin [Tue, 22 Nov 2022 16:36:40 +0000 (08:36 -0800)]
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.

(cherry picked from commit 69f6399c3733d717bc3dcefda7fcc031f06cef0d)

17 months agostand: Update comment about devdesc
Warner Losh [Sat, 5 Nov 2022 01:45:27 +0000 (19:45 -0600)]
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

(cherry picked from commit 269865a8eed240f572472750451484feccaeeeea)

17 months agostand: Remove unused enum
Warner Losh [Fri, 4 Nov 2022 21:28:26 +0000 (15:28 -0600)]
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

(cherry picked from commit c9ee39a3f255b62cbf106f4e5a704bcefdef017b)

17 months agostand: Nuke double-semicolons
Elliott Mitchell [Mon, 16 Aug 2021 22:51:38 +0000 (15:51 -0700)]
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

(cherry picked from commit 798ea06f07778f69297bcb9c88738d115bf0369e)

17 months agokboot: Add hostfs
Warner Losh [Thu, 27 Oct 2022 17:37:54 +0000 (11:37 -0600)]
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

(cherry picked from commit 02dba4f75f86f3d5ae5a6a438b5bcfdc667929bb)

17 months agostand/kboot: Make FDT fixup per-arch
Warner Losh [Thu, 27 Oct 2022 17:36:51 +0000 (11:36 -0600)]
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

(cherry picked from commit cc9f1b4c35974972c36553d4ca07ac91dc4262a2)

17 months agostand/efi: Simpler construct
Warner Losh [Mon, 24 Oct 2022 18:11:50 +0000 (12:11 -0600)]
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

(cherry picked from commit eca818c872f7ad094f8dac143123e7e8d65f3bcc)

17 months agostand/kboot: hostdisk isn't a DEVT_DISK, use a different value.
Warner Losh [Sat, 22 Oct 2022 15:09:23 +0000 (09:09 -0600)]
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

(cherry picked from commit 2cb90a7b2efc41e791c589e17127f63ccf24167c)

17 months agogeli: Move check for DEVT_DISK into geli_probe_and_attach
Warner Losh [Sat, 22 Oct 2022 00:16:56 +0000 (18:16 -0600)]
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

(cherry picked from commit bb3230e40bea68c1a0fc9ba1bee204bc05d7ea78)

17 months agostabd/geli: Bail out if you can't get the disks size
Warner Losh [Fri, 21 Oct 2022 23:39:34 +0000 (17:39 -0600)]
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

(cherry picked from commit 787df454c8175e58131f582c05c169070fb6ca7c)

17 months agokboot: hostdisk add to lsdev output
Warner Losh [Sat, 8 Oct 2022 05:46:20 +0000 (23:46 -0600)]
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

(cherry picked from commit 6700f34d126eb4892e24f4c7758e9f570de2fb4e)

17 months agokboot: Move load address stuff to MD code
Warner Losh [Sat, 8 Oct 2022 05:40:56 +0000 (23:40 -0600)]
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

(cherry picked from commit beba54e4b8349c5482f92d1abf366cfdc12b2416)

17 months agolibsa/netif.c: Replace #if with #ifdef
Michał Grzelak [Wed, 28 Sep 2022 10:31:25 +0000 (12:31 +0200)]
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

(cherry picked from commit 7b54d275ef6f74fe6030c85445bd3770d537d408)

17 months agolibsa/arp.c: Change printf format string
Michał Grzelak [Thu, 29 Sep 2022 05:22:47 +0000 (07:22 +0200)]
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

(cherry picked from commit c66c6da4f08187deab6a30d4aeb4d6e82088a046)

17 months agolibsa/rarp.c: Change casted type and printf format
Michał Grzelak [Wed, 28 Sep 2022 10:36:53 +0000 (12:36 +0200)]
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

(cherry picked from commit ee0d06faa0a5b0e551cac4cfcad68062cb3257c7)

17 months agolibsa/rarp.c: Change printf format string
Michał Grzelak [Wed, 28 Sep 2022 10:34:55 +0000 (12:34 +0200)]
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

(cherry picked from commit 1ed7916188b5a9684414387ff88829b304a858ae)

17 months agostand/elf: Only support swapping headers on powerpc.
Warner Losh [Fri, 16 Sep 2022 15:10:14 +0000 (09:10 -0600)]
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

(cherry picked from commit c0ecae78abbe5c925cd05d5e218aa6f038cd03c7)

17 months agostand: Allocate bootinfo rather than have it be static
Warner Losh [Fri, 16 Sep 2022 15:09:41 +0000 (09:09 -0600)]
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

(cherry picked from commit 9758dd3de1cddc8271be8dd6fee69286c5c86535)

stand: Pass in the proper size for bootinfo

Missed one sizeof(bi) -> sizeof(*bi) in 9758dd3de1cdd conversion to
allocating bootinfo.

Noticed by: tijl@
Fixes: 9758dd3de1cdd
Sponsored by: Netflix

(cherry picked from commit 4a676571e382d0188b98134732f421df57a47a87)

17 months agostand: Stop support booting 4.x and earlier kernels
Warner Losh [Fri, 16 Sep 2022 15:09:07 +0000 (09:09 -0600)]
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

(cherry picked from commit d43bcf62a2182d3f00c11e5145c8912f4468871a)

17 months agostand: Remove dead store to bi_kernelname
Warner Losh [Fri, 16 Sep 2022 15:09:02 +0000 (09:09 -0600)]
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

(cherry picked from commit e895ab3fbdc10fbf944289165c25357cb3f279fe)

17 months agostand: collapse all copies of *copyenv into md_copyenv
Warner Losh [Fri, 16 Sep 2022 15:08:57 +0000 (09:08 -0600)]
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

(cherry picked from commit fc352701ff3aeb0af22c0da17c4194cf1f8ad5d0)

17 months agostand: Move MOD_xxx macros from modinfo.h to .c
Warner Losh [Fri, 16 Sep 2022 15:08:52 +0000 (09:08 -0600)]
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

(cherry picked from commit 2e6ed47a4609ff03a9308a173c64900485172c22)

17 months agostand: Move md_copymodules into modinfo.c and reduce copies
Warner Losh [Fri, 16 Sep 2022 15:08:47 +0000 (09:08 -0600)]
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

(cherry picked from commit 5d1531d9d4e7d1b1b706ab23ac3f864416e87522)

stand: fix mismerge

Remove stray line from mismerge of 5d1531d9d4e7. This is no longer
needed.

Fixes: 5d1531d9d4e7
Sponsored by: Netflix

(cherry picked from commit dd2b9c2967767b19bcbc33de0e487405c612f59f)

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: 5d1531d9d4e7d
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D37095

(cherry picked from commit e0c3f66b4d5f0282e9c7c4803c4cd26b5a388a38)

17 months agostand: Create common/modinfo.h
Warner Losh [Fri, 16 Sep 2022 15:08:42 +0000 (09:08 -0600)]
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

(cherry picked from commit bca9c87b6104219af35ae5ea4a6af098a1631bca)

17 months agostand: Create MOD_ALIGN macro and use it everywhere
Warner Losh [Fri, 16 Sep 2022 15:08:37 +0000 (09:08 -0600)]
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

(cherry picked from commit 8b19d28d68a396b0263e3c13a559a31f70eb3b1d)

17 months agostand: use archsw.arch_copyin instead of direct call
Warner Losh [Fri, 16 Sep 2022 15:08:32 +0000 (09:08 -0600)]
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

(cherry picked from commit 4c670b53a0007739a0fc84ea4bc24a5895953aae)

17 months agostand: use archsw.arch_copyin instead of i386_copyin
Warner Losh [Fri, 16 Sep 2022 15:08:23 +0000 (09:08 -0600)]
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

(cherry picked from commit a705c72f214293a7aae5f83235a82f126f73e109)

17 months agostand/efi: Clean the proper files
Guido van Rooij [Thu, 15 Sep 2022 15:10:20 +0000 (09:10 -0600)]
stand/efi: Clean the proper files

Need to clean the specific loader we build, not the generic loader.efi

Reviewed by: imp

(cherry picked from commit 0f97a0d425cf0c7fa3966e64b4f88e67a2ee2982)

17 months agostand: Add driver interface docs
Warner Losh [Fri, 9 Sep 2022 23:22:09 +0000 (17:22 -0600)]
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

(cherry picked from commit 45ad955714f8442a4485510de819755370a76af3)

17 months agoloader.efi(8): document slop control, amd64 nocopy, and amd64 fault commands
Konstantin Belousov [Sun, 4 Sep 2022 07:36:35 +0000 (10:36 +0300)]
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

(cherry picked from commit 85c8c0b77d164f00e7e6e1e94544c82041d43223)

17 months agoRevert "stand: Grammar fix for a source code comment"
Gordon Bergling [Mon, 5 Sep 2022 13:40:55 +0000 (15:40 +0200)]
Revert "stand: Grammar fix for a source code comment"

This reverts commit 7d91d6b83e74edf278dde375e6049aca833cbebd.

The orginal comment is more natural.

Reported by:jrtc27

(cherry picked from commit 3c6db09bf45fd48e5e3c207f138ae1914dbeed0c)

17 months agostand/kboot: Add note about why we use MACHINE_ARCH here
Warner Losh [Sun, 4 Sep 2022 15:31:51 +0000 (09:31 -0600)]
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

(cherry picked from commit cc7b630cec8320ad979af6b29cb67027f6a95456)

17 months agostand: Grammar fix for a source code comment
Gordon Bergling [Sun, 4 Sep 2022 15:26:48 +0000 (17:26 +0200)]
stand: Grammar fix for a source code comment

- s/that that/that this/

MFC after: 3 days

(cherry picked from commit 7d91d6b83e74edf278dde375e6049aca833cbebd)

17 months agolualoader: Add loader_menu_multi_user_prompt config variable
Jessica Clarke [Fri, 2 Sep 2022 19:30:40 +0000 (20:30 +0100)]
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

(cherry picked from commit 9b17aa27406f3716383e71c6687d53599a8f8d8a)

17 months agostand: Parse BIOS revision from SMBIOS
Kornel Dulęba [Fri, 2 Sep 2022 11:08:32 +0000 (13:08 +0200)]
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

(cherry picked from commit 66c73af7ea59382ce5ca7cfb2eedb0491790276c)

17 months agokboot: List sources one per line to make merges easier
Warner Losh [Thu, 1 Sep 2022 17:07:34 +0000 (11:07 -0600)]
kboot: List sources one per line to make merges easier

Make SRC an alphabetical list of files, one per line.

Sponsored by: Netflix

(cherry picked from commit 69818bcf38e0bb1716a8d29f61ed392d447cea83)

17 months agokboot: add minmalist init functionality
Warner Losh [Thu, 1 Sep 2022 17:06:43 +0000 (11:06 -0600)]
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

(cherry picked from commit 57f90cf81338ca9d1e403fdfeac16f21def72763)

17 months agostand: Add lua binding loader.has_command
Warner Losh [Thu, 1 Sep 2022 17:06:19 +0000 (11:06 -0600)]
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

(cherry picked from commit 29fc4075e69fd27de0cded313ac6000165d99f8b)

17 months agostand: Add interp_has_builtin_cmd to see if we have a command
Warner Losh [Thu, 1 Sep 2022 17:06:01 +0000 (11:06 -0600)]
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

(cherry picked from commit a5948d40ad060140bf5b995f5409458a18ced0ce)

17 months agostand: separate the command lookup from the command execution
Warner Losh [Thu, 1 Sep 2022 17:05:42 +0000 (11:05 -0600)]
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

(cherry picked from commit 113dfadd5c8c2b8a566bf4d0e969e1dff62c9e2f)

17 months agostand: Document EFI consoles
Warner Losh [Thu, 1 Sep 2022 16:34:30 +0000 (10:34 -0600)]
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

(cherry picked from commit 75a91c70f8d12825ded5a6d14841bf3065ba6595)

17 months agostand: Stop setting hints for bios loader too
Warner Losh [Thu, 1 Sep 2022 16:33:09 +0000 (10:33 -0600)]
stand: Stop setting hints for bios loader too

Catch up to 2753bbe71b5a and remove the old hints.

Sponsored by: Netflix

(cherry picked from commit b1819983e70f5b8890404b7e07d17888d0cccfb6)

17 months agostand: Document that boot0 uses BIOS
Warner Losh [Fri, 26 Aug 2022 21:47:21 +0000 (15:47 -0600)]
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

(cherry picked from commit 7ed3228323ef4f9e3130603ea68c3be9c2ed50ce)

17 months agostand: More sensible defaults when ConOut is missing
Warner Losh [Fri, 26 Aug 2022 21:46:33 +0000 (15:46 -0600)]
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

(cherry picked from commit df065f699f1ff819bb9607c44a6754275ab335ed)

17 months agostand: Use bool for stage_offset_set
Warner Losh [Sun, 21 Aug 2022 15:45:44 +0000 (09:45 -0600)]
stand: Use bool for stage_offset_set

stage_offset_set is a boolean, convert it to a bool.

Sponsored by: Netflix

(cherry picked from commit 9d70108a74efe327ed9d1f68bc1e9e271810d94c)

17 months agoloader: zfs reader should only store devdesc in f_devdata
Toomas Soome [Sun, 14 Aug 2022 21:49:50 +0000 (00:49 +0300)]
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

(cherry picked from commit d98de7440507aea1648c8f4bc302bf88c0eb9458)

17 months agostand: Raise limit to 550,000 bytes for loader
Warner Losh [Fri, 12 Aug 2022 04:59:51 +0000 (22:59 -0600)]
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

(cherry picked from commit f8a199f28f9de46fe7360c3a4a0e19e71be72721)

stand: Fix a couple of comment typos in f8a199f28f9d

The commit message documented it as /etc/src.conf but the comment in the
source mentioned the non-existent /etc/loader.conf.

Fixes: f8a199f28f9d ("stand: Raise limit to 550,000 bytes for loader")
(cherry picked from commit 3179bb2737493bc4191c3239226bda50f0b64b8f)

17 months agostand: Go back to a.out format for /boot/loader
Warner Losh [Thu, 11 Aug 2022 23:29:10 +0000 (17:29 -0600)]
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

(cherry picked from commit 4c8ea3efe73c12d595472a7fc37177432a77858e)

17 months agostand: Make BIOS loader size limits settable
Warner Losh [Thu, 11 Aug 2022 16:24:58 +0000 (10:24 -0600)]
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

(cherry picked from commit 7d72ff905770a64a22125c890438189db71104ae)

17 months agostand: i386_fmtdev can be reduced to devformat
Warner Losh [Thu, 11 Aug 2022 15:09:03 +0000 (09:09 -0600)]
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

(cherry picked from commit 362322294045943703e03dee263bbc237002525c)

17 months agostand: uboot_fmtdev can be reduced to devformat
Warner Losh [Thu, 11 Aug 2022 15:08:52 +0000 (09:08 -0600)]
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

(cherry picked from commit add8154e451f441778fb9c2fb7d10d281dea9611)

17 months agostand: userboot_fmtdev can be reduced to devformat
Warner Losh [Thu, 11 Aug 2022 15:08:26 +0000 (09:08 -0600)]
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

(cherry picked from commit 1e9b23448a3010e8403eae08ad890fe1eb75da8b)

17 months agostand: efi_fmtdev can be reduced to devformat
Warner Losh [Thu, 11 Aug 2022 15:08:08 +0000 (09:08 -0600)]
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

(cherry picked from commit 1e7a2eb93a527a2f4b22be66788caf50e4ba1f89)

17 months agostand: Replace zfs_fmtdev with generic devformat()
Warner Losh [Thu, 11 Aug 2022 15:07:44 +0000 (09:07 -0600)]
stand: Replace zfs_fmtdev with generic devformat()

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D35973

(cherry picked from commit edb26097cb6416adb89b54c830d36c0ead3ca64c)

17 months agostand: For zfs, set dv_fmtdev to zfs_fmtdev
Warner Losh [Thu, 11 Aug 2022 15:07:26 +0000 (09:07 -0600)]
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

[ Dropped changes to stand/libsa/zfs/Makefile.inc file, depends
  on newer OpenZFS ]

(cherry picked from commit 654b7837a6a08ec5b51635badd14794754fab7c5)

17 months agostand: Use devformat instead of disk_devfmt
Warner Losh [Thu, 11 Aug 2022 15:07:13 +0000 (09:07 -0600)]
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

[ minor tweaks due to earlier UFS MFC ]

(cherry picked from commit 0b3a4a588fb6b30d923686828dab4685b94ec1ea)

17 months agostand: Use devformat rather than disk_devfmt
Warner Losh [Thu, 11 Aug 2022 15:06:53 +0000 (09:06 -0600)]
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

[ minor changes because UFS changes interferred and were already merged ]

(cherry picked from commit ec9f3e776f39286ccec9915f38cca9729e6f9241)

17 months agostand: Add disk_fmtdev for dv_fmtdev for all the disk devices
Warner Losh [Thu, 11 Aug 2022 15:06:28 +0000 (09:06 -0600)]
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

(cherry picked from commit ad759c73522efb606135e2891ac03864926b80a3)

17 months agostand: Add devformat to return formatted string for a device
Warner Losh [Thu, 11 Aug 2022 15:06:09 +0000 (09:06 -0600)]
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

(cherry picked from commit dc472f67021320309ced970d3d26d30a04da0ef2)

17 months agostand: Add dv_devfmt to return a string represenation of the device
Warner Losh [Thu, 11 Aug 2022 15:05:34 +0000 (09:05 -0600)]
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

(cherry picked from commit 4d4b1a298c84f2357c304583dfe78d0e4b8fa2f1)

17 months agostand: Change zfs_fmtdev to take a struct devdesc *
Warner Losh [Thu, 11 Aug 2022 15:05:15 +0000 (09:05 -0600)]
stand: Change zfs_fmtdev to take a struct devdesc *

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D35974

(cherry picked from commit d2d4e1271b33b233f57fd18a61a1b5c1b0aeb355)

17 months agostand: Change disk_fmtdev to take a struct devdesc *
Warner Losh [Thu, 11 Aug 2022 15:04:50 +0000 (09:04 -0600)]
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

(cherry picked from commit c32dde3166922f55927764464d13f1bc9640f5f6)

17 months agostand: Move i386_devdesc to a union
Warner Losh [Thu, 11 Aug 2022 15:04:08 +0000 (09:04 -0600)]
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

(cherry picked from commit f197c0bf3e075286ccea32cd12023f3317474c5a)

17 months agostand: Remove unnecessary include
Warner Losh [Thu, 11 Aug 2022 14:59:48 +0000 (08:59 -0600)]
stand: Remove unnecessary include

stdbool.h is implied by stand.h, so remove it.

Sponsored by: Netflix

(cherry picked from commit bec11d96318bc8647f28b580829eeb7ba9d05768)

17 months agostand: impose 510,000 byte limit for /boot/loader and /boot/pxeldr
Warner Losh [Thu, 11 Aug 2022 03:19:01 +0000 (21:19 -0600)]
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

(cherry picked from commit 39fdad34e220c52a433e78f20c8c39412429014e)

17 months agostand: i386/amd64: Always use elf format for /boot/loader and pxeldr
Warner Losh [Thu, 11 Aug 2022 03:18:32 +0000 (21:18 -0600)]
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

(cherry picked from commit e2295b9117233d8248fe919c6b28ef1d44a8950d)

17 months agostand: Reduce number of files that need -I${LDRSRC}
Warner Losh [Wed, 3 Aug 2022 17:16:17 +0000 (11:16 -0600)]
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

(cherry picked from commit f863970a82f430a2b10b9799585008fe89eab00a)

17 months agostand: Remove unneeded include from geli
Warner Losh [Wed, 3 Aug 2022 17:13:34 +0000 (11:13 -0600)]
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

(cherry picked from commit 4333168b1dc0f9285e90ccba26e21348e51fe889)

17 months agostand: use snprintf here
Warner Losh [Wed, 3 Aug 2022 16:50:14 +0000 (10:50 -0600)]
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

(cherry picked from commit a23c26b2fe38f7ad63e71e1f32795b4800213585)

17 months agostand: Add a helper 'universe' target
Warner Losh [Sat, 30 Jul 2022 11:01:47 +0000 (05:01 -0600)]
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

(cherry picked from commit 206203f5301b1bda1ceabcb7ecb7c0eee3e6b07a)

17 months agostand: Move quit command to common commands
Warner Losh [Sat, 30 Jul 2022 10:43:21 +0000 (04:43 -0600)]
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

[[ tweaked because mips is still in stable/13 leading to conflict ]]

(cherry picked from commit 2101541ff1222788901d9503001add9f288a4c40)

17 months agokboot: Make console raw when we start
Warner Losh [Tue, 26 Jul 2022 23:39:45 +0000 (17:39 -0600)]
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

(cherry picked from commit 9579540144880e0a612ec2fdfc66de46c08d28d6)

17 months agokboot: implement stripped down termios
Warner Losh [Tue, 26 Jul 2022 23:31:23 +0000 (17:31 -0600)]
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

(cherry picked from commit 963037786f76a414e91e45d4fbef5e35fc1abc84)