Commit Graph

1806 Commits

Author SHA1 Message Date
Warner Losh
c16e08e5f3 stand/efi: Retire i386 support
Remove the i386 ifdefs and files. It never worked.

Sponsored by:		Netflix
Reviewed by:		manu, tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D40012
2023-05-11 14:06:03 -06:00
Warner Losh
8c3d6917c1 stand: eficom: Only set baudrate when it changes
Only set the baudrate when it is different than what the device has
reported. In addition, pass in the args to effect no change to the other
parameters to the serial port. Some EFI firmware gets cranky when you
set them to the same value, so avoid doing so (we likely can remove the
HyperV workaround with this fix, but I kept it in place). Add comments
to the code for why we do this too.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D40010
2023-05-11 14:06:03 -06:00
Warner Losh
cb2da74905 stand: eficom: Don't preemtively assume flow control
Remove rtsdtr_off. It's basically unused. Expand its meaning, but put
changing flow control to under an ifdef. We shouldn't set it unless
we're sure we need to do so. UEFI normally initializes the device
correctly, and we should avoid needless changes that aren't user
requested.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D40009
2023-05-11 14:06:03 -06:00
Warner Losh
66826fd54a stand: eficom : remove unused ignore_cd
Sponsored by:		Netflix
Reviewed by:	tsoome
Differential Revision:	https://reviews.freebsd.org/D40008
2023-05-11 14:06:03 -06:00
Warner Losh
bab80c12a8 stand: Move eficom to libefi
Rename efiserialc to eficom.c and move it to libefi. Remove
loader.efi.h, since it's not needed. It's architecture independent
(though how we use it might vary). Drivers also belong in libfoo
in the boot loader: all the BIOS drivers are in i386/libi386 and
the console driver is in efi/libefi.

Sponsored by:		Netflix
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D40007
2023-05-11 14:06:03 -06:00
Warner Losh
82cf061eba stand: Make non-matching console names OKer
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D39984
2023-05-11 14:06:03 -06:00
Warner Losh
f93416d677 stand: add comconsole backwards compatibility shim for aarch64
Add a compat shim for the "comconsole" name so that people with a
"console=comconsole" in their loader.conf on aarch64 will continue to
work (though with a warning).

This is only aarch64: it will never be there for amd64 (where comconsole
always means talk to the hardware directly). To do that is too hard.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D39983
2023-05-11 14:06:03 -06:00
Warner Losh
2f131435bc stand: efi create eficom console device.
Fix the 'renaming kludge' that we absolutely cannot do going forward
(it's cost us days of engineering time).

console=comconsole talks to the hardware directly. This is available
only on amd64. It is not available anywhere else (and so requires
changes for people doing comconsole on aarch64)

console=eficom talks to the console via EFI protocols.  It's available
on amd64, aarch64 and riscv64. It's the first port that we find, though
it can be overriden by efi_com_port (which should be set to the UID of
the serial port, not the I/O port, despite the name). devinfo -v
will give the UID to uartX mapping.

This is an incompatible change for HYPER-V on amd64. It only works with
eficom console, so you'll need to change your configuration in
loader.conf. No compatibility hack will ever be provided for this (since
it requires renamig, which the loader cannot reliably do).

It's also an incompatible change for aarch64. comconsole will need to
change to eficom. There might be a comconsole "shim" for this.

All the interlock to keep only eficom and comconsole from both attaching
have been removed.

RelNotes:		Yes
Sponsored by:		Netflix
Discussed with:		kevans
Differential Revision:	https://reviews.freebsd.org/D39982
2023-05-11 14:06:03 -06:00
Kyle Evans
3cb2f5f369 lualoader: add support for .lua configuration files
If a file is specified in loader_conf_files that ends in '.lua', lualoader
will now load and execute that file. These may be used in place of a
traditional loader.conf to use more complicated logic, where some values
may be set based on others or based on the environment that the C bits has
left us with.

Lua scripts are run in a limited environment. In particular, it does not get
access to any modules or, in-fact, anything except environment variable.

A config.buildenv hook has been added so that a local module can add
whatever it may need to to the environment.

When a global var is set in the lua script, it does not immediately alter
the loader environment. Instead, the script's environment is initially
empty and processed only if the whole script executes successfully.
Effectively, a lua configuration file either takes effect or it does not,
an error will not leave it in a half-baked state.

Reviewed by:	bcr (manpages), imp
Differential Revision:	https://reviews.freebsd.org/D28450
2023-05-10 23:10:53 -05:00
Ed Maste
e32fecd0c2 loader: install help files only once
Every file should be installed exactly once by `make installworld`.
This is especially important for pkgbase.

Loader help files were being installed by each loader variant (e.g.,
the simp, lua, and 4th EFI loaders).  Add a (slightly hacky) mechanism
to skip installing help files for all but one variant.

PR:		271178
Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D40021
2023-05-09 20:18:19 -04:00
Warner Losh
5fd34912b4 stand: Fix oversight in updating OpenZFS: Add com.klarasystems:vdev_zaps_v2
com.klarasystems:vdev_zaps_v2 is a new feature that the last OpenZFS
import brought in. It needs to be on the list of supported features, but
that update didn't happen so I woke up to a mailbox with multiple
complaints.

CirrusCI test to boot twice with a zpool update inbetween coming later
today.

Sponsored by:		Netflix
2023-05-04 08:25:46 -06:00
Warner Losh
a5b4ec5281 stand: More protection against malformed smbios tables
Add some more sanity checks to make sure we don't march off the end of
the table. Typically, smbios structures are well formed, or Windows
wouldn't boot. Sometimes they aren't, and this at least fails safe.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D39794
2023-05-01 15:12:41 -06:00
Warner Losh
c5e433b99e stand: Avoid unaligned access in smbios code
This code was written on x86 where unaligned accesses were
easy. LinuxBoot running on aarch64 uses mmap of /dev/mem to read the
smbios table. Linux's mapping of this memory doesn't allow the normal
unaligned fixup, so we get a bus error instead. We can't use the more
natural le16dec and friends because they optimize into a single,
unaligned memory load. We don't see this issue on aarch64 UEFI because
memory is mapped such that unaligned accesses are fixed up.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D39793
2023-05-01 15:12:34 -06:00
Warner Losh
a083d08676 kboot: Add smbios support
Add support for getting smbios from /sys/firmware/efi/systab, if
any. Add ptov mapping that uses mmap on /dev/mem to do the mapping with
64k pages (usually we only need 1 or two mappings).

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D39792
2023-05-01 15:12:29 -06:00
Warner Losh
facd0edbb2 kboot: Fix an off by one error
Fix an off-by-one error that would mean we'd get stuck on the newline if
ACPI= wasn't first.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D39817
2023-05-01 15:12:24 -06:00
Warner Losh
83eabc64ef kboot: Add HOST_MAP_FAILED define
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D39790
2023-05-01 15:11:32 -06:00
Warner Losh
b53ec4e44f stand: Add isspace to FreeBSD ctypes.h
And eliminate blake3_impl_hack.c since it's no longer needed.

Sponsored by:		Netflix
Reviewed by:		delphij
Differential Revision:	https://reviews.freebsd.org/D39899
2023-05-01 15:02:54 -06:00
Warner Losh
6c8358cd7f stand: back out the most of the horrible aarch64 kludge
Add one ifdef to upstrem code and get rid of compiling the horrible
checked-in aarch64 assembler for the boot loader that the loader will
never use. I'll attempt to upstream this and adjust as needed.

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D39897
2023-05-01 15:02:54 -06:00
Warner Losh
cb8179079a stand: Fix warning about variable unused
dflag is unused when LOADER_VERIEXEC isn't defined, so move it under the
ifdef.

Sponsored by:		Netflix
2023-05-01 15:02:54 -06:00
Warner Losh
5328f9034f stand/kboot: Simplify
There's plenty of stack in kboot, so use it here rather than the
malloc/free dance.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D39416
2023-05-01 15:02:53 -06:00
Warner Losh
d5babd0d23 stand/efi: Simplify code here
We have plenty of stack in the EFI case, so use it instead of the
complicated malloc / free dance.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D39415
2023-05-01 15:02:53 -06:00
Warner Losh
5ce98ee5f4 stand/userboot: Simplify code
We have way more than 8k of stack for the current value of the zfs
bootonce attribute. Allocate buf on the stack rather than the
complicated malloc / free dance.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans, jhb
Differential Revision:	https://reviews.freebsd.org/D39414
2023-05-01 15:02:53 -06:00
Warner Losh
43f7eeff0d stand/boot1.efi: Implement bootonce for ZFS
Implement ZFS bootonce protocol. We pass zfs-bootonce=t to the next boot
stage as a command line argument. Unlike zfsboot -> loader handoff in
the BIOS case, we don't use the OS_BOOTONCE_USED. This would require
modifications to loader.efi which would only server to make it more
complicated. Instead, use the command line parsing interface for the
boot1.efi -> loader.efi to pass in the zfs-bootonce kenv that will be
needed by rc.d/zfsbe to activate the BE if boot progresses that far.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D39412
2023-05-01 15:02:53 -06:00
Warner Losh
b765cfa380 stand/zfs: Refactor zfs_get_bootonce
Lookup the spa and pass it into zfs_get_bootonce_spa to process the boot
once protocol.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D39411
2023-05-01 15:02:53 -06:00
Warner Losh
4dcae288fe stand/zfs: Refactor zfs_set_bootenv
Refactor zfs_set_bootenv to split out the lookup of spa from the
rest. zfs_set_bootenv_spa flushes the benv to the vdevs and updates the
cached benv.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D39410
2023-05-01 15:02:53 -06:00
Warner Losh
6479bd1b7d stand/zfs: Refactor zfs_get_bootenv
Create a new interface to zfs_get_bootenv called zfs_get_bootenv_spa
which takes a spa instead of a void * (effectively a devdesc *). Use
that in zfs_get_bootenv.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D39409
2023-05-01 15:02:53 -06:00
Warner Losh
439a9766ad stand/zfs: Move spa_find_by_dev from zfsimpl.c to zfs.c
zfsimpl.c doesn't know about devdesc at all, but zfs.c does. Move it to
zfs.c, which is the only user. Keep it static for now, but it could be
exposed later if something else were to need it.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D39408
2023-05-01 15:02:52 -06:00
Warner Losh
91ac713b64 stand/boot1.efi: Allow modules to add env variables
Sometimes filesystem modules need to pass details of the state of the
filesystem to later stages of a boot. Provide a generic method to do
so. We'll add them after any env variables set in our config files.

Sponsored by:		Netflix
Reviewed by:		tsoome, kevans
Differential Revision:	https://reviews.freebsd.org/D39407
2023-05-01 15:02:52 -06:00
Toomas Soome
795497bf3d pxeboot: bugs in pxe.h
SEGDESC_t needs to be PACKED
there is no status in t_PXENV_UNDI_MCAST_ADDRESS

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D39799
2023-04-26 16:33:28 +03:00
Kyle Evans
61fd6a1ea2 Note that static hints no longer break loader hints
This commentary was carried over from the x86 version of the same code,
but has actually been inaccurate for a while now. As of FreeBSD 12.x,
all environments are used unless they disable each other. See
39d44f7f15 ("kern_environment: use any provided environments [...]")
for details.

Reviewed by:	imp
Differentiala Revision:	https://reviews.freebsd.org/D35695
2023-04-26 00:38:32 -05:00
Warner Losh
16e9ec4406 stand: mark unused argment as unused
We don't use the 'ver' argument for uuids sometimes, so mark it unused.

Sponsored by:		Netflix
2023-04-22 00:30:43 -06:00
Gordon Bergling
66095010d1 stand: Remove a double word in a source code comment
- s/value value/value/

MFC after:	3 days
2023-04-20 11:11:18 +02:00
Stephen J. Kiernan
a50d73d578 loader: Change version calculation to be more consistent.
Use 1000 * major + minor when calculating the version number that
gets set in the Ficl environment or lua loader property. This allows
for more room if the minor number needs to go above 9.

Add loader.version property to lua loader.

Reviewed by:	imp
Obtained from:	Juniper Networks, Inc.
Differential Revision: https://reviews.freebsd.org/D39631
2023-04-19 13:58:53 -04:00
Simon J. Gerraty
d9a4274795 Update/fix Makefile.depend for userland 2023-04-18 17:14:23 -07:00
Warner Losh
238271f4a6 stand: Add a snarky note about the upstream ZFS situation
The latest import of openzfs broke the hacks that we used to omit the
special registers being used on arm64. Add snarky note documenting this
situation since it's a mess now since the hack was only partially
undone, leaving behind a mess.

Sponsored by:		Netflix
2023-04-18 15:31:17 -06:00
Mark Johnston
21d56b7966 loader.efi: Fix some arm64 PE metadata
- Mark the file as an executable in the COFF header.
- Provide separate .text and .data sections.
- Provide sane file and section alignment values.  These values are the
  defaults defined in the PE specification.
- Set appropriate characteristics for each of .text and .data.

This is required for the MS devkit to load our UEFI image.

Obtained from:	OpenBSD via allanjude
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D37765
2023-04-18 14:36:24 -04:00
John Baldwin
c7f3674fb0 boot0: Drop the BOOT_BOOT0_ORG option.
This shouldn't be an option (and I added it in the first place back in
4ae4202e70 and
83f4b92050).  However, unlike the other
knobs I added back then, this really shouldn't be a knob since it is
hardcoded in the source.
2023-04-18 11:19:12 -07:00
John Baldwin
bd5dc94b99 boot0: Expand the description of BOOT_BOOT0_ORG.
This really shouldn't even be an option given it is hardcoded as a
constant named ORIGIN in the assembly.  mbr.S also uses 0x600 and
hardcodes it in both the assembly and the Makefile.
2023-04-18 11:02:50 -07:00
Gordon Bergling
c3fbd9c621 Revert "stand: Remove double words in source code comments"
The sentence, "The base address that we the boot0 code to to run it."
is correct.

Reported by:	jrtc27

This reverts commit b12ccd0bb1.
2023-04-18 08:08:35 +02:00
Gordon Bergling
b12ccd0bb1 stand: Remove double words in source code comments
- s/to to/to/
- s/value value/value/

MFC after:	5 days
2023-04-18 07:14:44 +02:00
Stephen J. Kiernan
b5c3ade765 libsa: Update comments about SMBIOS specification
Summary:
Include details from the SMBIOS 3 specification and some additional
details for SMBIOS 2.1.

Obtained from:	Juniper Networks, Inc.

Reviewers: jmg, manu

Subscribers: imp, dab

Differential Revision: https://reviews.freebsd.org/D39635
2023-04-17 23:21:04 -04:00
Dimitry Andric
1a3ccb8f15 libsa: make single bit bitfields unsigned to avoid clang 16 warning
Clang 16 introduced a warning about single bit bitfields in structs,
which is triggered by a declaration in libsa's tftp.c:

    stand/libsa/tftp.c:382:20: error: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Werror,-Wsingle-bit-bitfield-constant-conversion]
                                    h->islastblock = 1;     /* very short file */
                                                   ^ ~
    stand/libsa/tftp.c:432:18: error: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Werror,-Wsingle-bit-bitfield-constant-conversion]
                    h->islastblock = 1;     /* EOF */
                                   ^ ~

Signed one-bit bitfields can only have values -1 and 0, but the intent
here is to use the field as a boolean, so make it unsigned.

MFC after:	3 days
2023-04-17 18:26:11 +02:00
Cyrus Rahman
0ab68e9272 loader: lua: disable autoboot timer after password entry
In the lua loader, if one sets a password in loader.conf, the
autoboot_delay timer will start before the menu is displayed.  One can
interrupt the autoboot and bring up the menu by entering a keyboard
character before the timer expires.

If this is done a prompt for the password is displayed.  Entering the
password will bring up the menu, but the timer will again start and
another keyboard character must be entered or autoboot will abort the
menu and boot the system.

PR:		265472
Reviewed by:	kevans
MFC after:	3 days
2023-04-15 21:39:56 -05:00
Cyrus Rahman
d7584aa09f loader: lua: unload the kernel when changing BEs
Usually the kernel is loaded later, but there are circumstances where it
could have been loaded earlier than changing BEs.  Unload anything that
is already there so that we know we're using artifacts from the proper
environment.

PR:		265471
Reviewed by:	kevans
MFC after:	3 days
2023-04-15 21:39:52 -05:00
Kyle Evans
ec671f4980 loader: comconsole: don't unconditionally wipe out hw.uart.console
It may be the case that we need to set hw.uart.console manually in some
scenarios that comconsole can't necessarily support.  Avoid clobbering
hw.uart.console unless we've actually selected comconsole so that one
could at least get kernel console output..

Discussed with:	imp
Sponsored by:	Zenith Electronics LLC
Sponsored by:	Klara, Inc.
2023-04-13 23:42:03 -05:00
Mateusz Piotrowski
d8e36cd2b1 gptboot.efi.8: Fix a typo 2023-04-13 13:02:59 +02:00
Martin Matuska
2a58b312b6 zfs: merge openzfs/zfs@431083f75
Notable upstream pull request merges:
  #12194 Fix short-lived txg caused by autotrim
  #13368 ZFS_IOC_COUNT_FILLED does unnecessary txg_wait_synced()
  #13392 Implementation of block cloning for ZFS
  #13741 SHA2 reworking and API for iterating over multiple implementations
  #14282 Sync thread should avoid holding the spa config write lock
         when possible
  #14283 txg_sync should handle write errors in ZIL
  #14359 More adaptive ARC eviction
  #14469 Fix NULL pointer dereference in zio_ready()
  #14479 zfs redact fails when dnodesize=auto
  #14496 improve error message of zfs redact
  #14500 Skip memory allocation when compressing holes
  #14501 FreeBSD: don't verify recycled vnode for zfs control directory
  #14502 partially revert PR 14304 (eee9362a7)
  #14509 Fix per-jail zfs.mount_snapshot setting
  #14514 Fix data race between zil_commit() and zil_suspend()
  #14516 System-wide speculative prefetch limit
  #14517 Use rw_tryupgrade() in dmu_bonus_hold_by_dnode()
  #14519 Do not hold spa_config in ZIL while blocked on IO
  #14523 Move dmu_buf_rele() after dsl_dataset_sync_done()
  #14524 Ignore too large stack in case of dsl_deadlist_merge
  #14526 Use .section .rodata instead of .rodata on FreeBSD
  #14528 ICP: AES-GCM: Refactor gcm_clear_ctx()
  #14529 ICP: AES-GCM: Unify gcm_init_ctx() and gmac_init_ctx()
  #14532 Handle unexpected errors in zil_lwb_commit() without ASSERT()
  #14544 icp: Prevent compilers from optimizing away memset()
         in gcm_clear_ctx()
  #14546 Revert zfeature_active() to static
  #14556 Remove bad kmem_free() oversight from previous zfsdev_state_list
         patch
  #14563 Optimize the is_l2cacheable functions
  #14565 FreeBSD: zfs_znode_alloc: lock the vnode earlier
  #14566 FreeBSD: fix false assert in cache_vop_rmdir when replaying ZIL
  #14567 spl: Add cmn_err_once() to log a message only on the first call
  #14568 Fix incremental receive silently failing for recursive sends
  #14569 Restore ASMABI and other Unify work
  #14576 Fix detection of IBM Power8 machines (ISA 2.07)
  #14577 Better handling for future crypto parameters
  #14600 zcommon: Refactor FPU state handling in fletcher4
  #14603 Fix prefetching of indirect blocks while destroying
  #14633 Fixes in persistent error log
  #14639 FreeBSD: Remove extra arc_reduce_target_size() call
  #14641 Additional limits on hole reporting
  #14649 Drop lying to the compiler in the fletcher4 code
  #14652 panic loop when removing slog device
  #14653 Update vdev state for spare vdev
  #14655 Fix cloning into already dirty dbufs
  #14678 Revert "Do not hold spa_config in ZIL while blocked on IO"

Obtained from:	OpenZFS
OpenZFS commit:	431083f75b
2023-04-03 16:49:30 +02:00
Gleb Smirnoff
4358928e23 amd64 loader: plug hard hang with serial console enabled
The hang basically bricks a physical box and it can be recovered
only if you are able to boot from alternate media.  This isn't a
perfect fix, but throw it in before loader experts decide on
proper one.

Submitted by:	whu
Fixes:		927358dd98
2023-03-31 11:19:25 -07:00
Wei Hu
927358dd98 amd64 loader: Use efiserialio for Hyper-V booted systems
UEFI provides ConIn/ConOut handles for consoles that it supports,
which include the text-video and serial ports. When the serial port
is available, use the UEFI driver instead of direct io-port accesses
to avoid conflicts between the firmware and direct hardware access, as
happens on Hyper-V (Azure) setups.

This change enables efiserialio to be built for efi-amd64 and has
higher order priority vs comconsole, and only uses efiserialio
if the hypervisor is Hyper-V. When efiserialio successfully
probes, it will set efi_comconsole_avail=true which will prevent
comconsole from probing in this setup.

Tested on Hyper-V, ESXi and Azure VMs.

PR:		264267
Reviewed by:	kevans, whu
Tested by:	whu
Obtained from:	Rubicon Communications, LLC (Netgate)
MFC after:	2 weeks
Sponsored by:	Rubicon Communications, LLC (Netgate)
2023-03-18 07:07:35 +00:00
Allan Jude
a849842f51 loader: Add support for booting from a ZFS snapshot
When booting from a snapshot we need to follow a different code path
to turn the objset ID into the name, and for forward lookups we need
to walk the parent's snapnames_zap.

With this, it is possible to set the pools BOOTFS property to a
snapshot and boot with a read-only filesystem of that snapshot.

Reviewed by:	tsoome, rew, imp
Sponsored By:	Beckhoff Automation GmbH & Co. KG
Sponsored By:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D38600
2023-03-14 14:18:29 +00:00