Commit Graph

138 Commits

Author SHA1 Message Date
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
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
Simon J. Gerraty
d9a4274795 Update/fix Makefile.depend for userland 2023-04-18 17:14:23 -07: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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Gordon Bergling
9cd75b5588 stand: Fix a common typo in source code comments
- s/existance/existence/

MFC after:	3 days
2022-03-28 19:34:30 +02:00
Ed Maste
cf8880d52b teken: color #3 is yellow not brown - use TC_YELLOW as the name
The console escape code standard (ECMA-48) specifies color #3 (escape
code 33) as yellow.  A brown console color is an artifact of the VGA
palette, which replaces dim (but not bright) yellow with brown.

Reviewed by:	adrian, imp
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D34531
2022-03-12 09:17:29 -05:00
Ed Maste
e9249ef958 loader: accept "yellow" as a named color
For historical reasons console color number 3 may be either yellow (most
consoles) or brown (VGA palette).  The console escape code standard
uses "yellow", but teken color name constants appear to be based on the
VGA scheme and use TC_BROWN for color 3.  Even so, the palette table
used 50,50,0 as the RGB percentage tuple, resulting in a dim yellow for
framebuffer consoles at the time teken was introduced.

Amusingly, in 19e2ce2d83 the comment on the palette entry was changed
from "brown" to "dark yellow" but the colour itself was changed from
a pure yellow to being somewhat brown.

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2022-03-11 15:22:13 -05:00
Ed Maste
425e57e7a2 loader: support numeric and named bright colors (8-15)
Accept "bright" or "light" prefix for named colors.

For numeric colors, update error message to specify that values 0 to 15
are allowed, and verify that values are in that range.

Reviewed by:	imp, tsoome (both earlier version)
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D34512
2022-03-11 14:20:34 -05:00
Warner Losh
aaaa5a2e68 loader: narrow the scope of gfx frame buffer wrt tg supported kernels
Store whether or not we found a vbefb module (eg, a tg supported kernel)
in the preloaded_file structure. This automatically resets on reload and
eliminates load_elf knowing about any gfx_* interface. Restrict this to
i386, which is the only place it's used. Update libi386 to check in the
preloaded_file struct. Eliminate this from the teken_gfx
structure. Rewrite the parsing code to be more inline. Check this from
the same place we check for a relocatable amd64 kernel.

Sponsored by:		Netflix
Reviewed by:		manu, tsoome
Differential Revision:	https://reviews.freebsd.org/D33427
2021-12-14 15:27:47 -07:00
Toomas Soome
6102f43cf0 loader: framebuffer should only be written into
Reading from Write Combining memory can be very-very slow. Try to use
shadow buffer to avoid such reads.

MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D33305
2021-12-11 13:25:35 +02:00
Toomas Soome
b4cb3fe0e3 loader: implement mount/unmount rootfs
We want to keep our root file system open to preserve bcache segment
between file accesses, thus reducing physical disk IO.

Reviewed by:	imp, allanjude, kevans (previous version)
Differential Revision:	https://reviews.freebsd.org/D30848
MFC after:	1 month
2021-09-08 04:01:20 +03:00
Kyle Evans
3daa8e165c pxeboot: improve and simplify rx handling
This pushes the bulk of the rx servicing into a single loop that's only
slightly convoluted, and it addresses a problem with rx handling in the
process.  If we hit a tx interrupt while we're processing, we'd
previously drop the frame on the floor completely and ultimately
timeout, increasing boot time on particularly busy hosts as we keep
having to backoff and resend.

After this patch, we don't seem to hit timeouts at all on zoo anymore
though loading a 27M kernel is still relatively slow (~1m20s).

Reviewed by:	tsoome
Triage by:	Ash Gokhale <ashfixit gmail com>
Sponsored By:	National Bureau of Economic Research
Sponsored by:	Klara, Inc.
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D31512
2021-08-25 21:59:08 -05:00
Colin Percival
313724bab9 loader: Use tslog to instrument some functions
In my initial testing, these are the functions which showed up as
being worth instrumenting.  More may be added later.

common/console.c: cons_probe
common/gfx_fb.c: read_list, insert_font, autoload_font
common/interp.c: interact
common/interp_lua.c: interp_init, interp_run
efi/libefi/efipart.c: efipart_readwrite
i386/libi386/biosdisk.c: bd_init, bd_open, bd_edd_io, bd_chs_io, bd_io
libsa/open.c: open
libsa/read.c: read
libsa/twiddle.c: twiddle

Note that profiling interp_run may be of questionable utility as it
may depend on user behaviour (e.g. pressing keys).

Reviewed by:	kevans (earlier version)
2021-06-20 20:09:48 -07:00
Eric van Gyzen
eda28feb2e EFI secure boot VECTX related changes
When VECTX is enabled as a kernel option and non-EFI loaders are
built, many reads will fail due to the mis-match of whether
LOADER_VERIEXEC_VECTX or not in readin.h.  Source that includes
bootstrap.h must ensure the kernel option agrees with the compile
time CFLAGS in the various make related files.

Submitted by:	bret_ketchum@dell.com (original revision)
Reviewed by:	sjg, bdrewery, dab, bret_ketchum@dell.com
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D29993
2021-04-30 12:53:45 -05:00
Toomas Soome
becaac3972 loader: use display pixel density for font autoselection
Calculate font size from 16 density independent pixels (dp) by using:
size = 16 * ppi/160 * display_factor

We are specifying font size 16dp, and assuming 1dp = 160ppi.
Also apply scaling factor 2 (display_factor).

MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D28849
2021-02-27 11:26:02 +02:00
Toomas Soome
61c50cbc09 loader: autoload_font will hung loader when there is no local console
If we start with console set to comconsole, the local
console (vidconsole, efi) is never initialized and attempt to
use the data can render the loader hung.

Reported by:	Kamigishi Rei
MFC after: 3 days
2021-02-21 12:45:36 +02:00
Toomas Soome
96bef2053a loader: remove BORDER_PIXELS
BORDER_PIXELS is left over from picking up the source from illumos
port. Since FreeBSD VT does not use border in terminal size
calculation, there is no reason why should loader use it.

MFC after: 1 week
2021-02-09 13:45:07 +02:00
Roger Pau Monné
45ecda8ebf stand/amd64: remove unused addr parameter from bi_load64
All callers of bi_load64 pass 0 as the addr parameter, so just remove
it and always calculate the last load address from the module chain.

No functional change.

Sponsored by:		Citrix Systems R&D
Reviewed by:		tsoome, imp
Differential revision:	https://reviews.freebsd.org/D28412
2021-02-01 15:41:26 +01:00
Roger Pau Monné
b6d85a5f51 stand/multiboot: adjust the protocol between loader and kernel
There's a currently ad-hoc protocol to hand off the FreeBSD kernel
payload between the loader and the kernel itself when Xen is in the
middle of the picture. Such protocol wasn't very resilient to changes
to the loader itself, because it relied on moving metadata around to
package it using a certain layout. This has proven to be fragile, so
replace it with a more robust version.

The new protocol requires using a xen_header structure that will be
used to pass data between the FreeBSD loader and the FreeBSD kernel
when booting in dom0 mode. At the moment the only data conveyed is the
offset of the start of the module metadata relative to the start of the
module itself.

This is a slightly disruptive change since it also requires a change
to the kernel which is contained in this patch. In order to update
with this change the kernel must be updated before updating the
loader, as described in the handbook. Note this is only required when
booting a FreeBSD/Xen dom0. This change doesn't affect the normal
FreeBSD boot protocol.

This fixes booting FreeBSD/Xen in dom0 mode after
3630506b9d.

Sponsored by:		Citrix Systems R&D
MFC after:		3 days
Reviewed by:		tsoome
Differential Revision:	https://reviews.freebsd.org/D28411
2021-01-29 15:23:26 +01:00
Toomas Soome
6c7a932d0b loader: start kernel in text mode when there is no vbefb vt driver
If kernel is built without VT vbefb driver, make sure
we start kernel in text mode.
2021-01-27 01:07:34 +02:00
Toomas Soome
52e3a7300d loader: handle malloc failures in vbe_init, use consistent naming
Handle malloc failures in vbe_init().

If it should so happen and we do get malloc failure in vbe_init(),
use original mode list.

Replace nitems with nentries to have naming consistency and avoid
confusion with nitems() macro.

Reported by: yuripv, rpokala
2021-01-19 21:58:46 +02:00
Toomas Soome
ad1ebbe5ce loader: create local copy of mode list provided by vbeinfoblock
Apparently some systems do corrupt mode list memory area, so we need
to use local copy instead.
2021-01-16 12:23:22 +02:00
Toomas Soome
0974bfa3a8 loader: do not update palette in text mode (real fix)
Apparently palette update while in text mode, will cause
some adapters to end up with blank display. Previous update had
condition reversed.
2021-01-15 15:43:14 +02:00
Toomas Soome
89632acb50 loader: term_image_display() should test screen_buffer
Make sure screen_buffer is not NULL.
2021-01-10 21:59:52 +02:00
Toomas Soome
1790f5e654 loader: do not update palette in text mode
Apparently palette update while in text mode, will cause
some adapters to end up with blank display.
2021-01-07 17:07:53 +02:00
Toomas Soome
babda0952f loader: instead of hw.vga.textmode, use screen.textmode
hw.vga.textmode is directing VT VGA backend to use text mode.

The default screen mode for BIOS loader is text, and default
screen mode for VT VGA backend is graphics (unless we are running on
hypervisor or hw.vga.textmode is set to 1). Using hw.vga.textmode
for loader does remove possibility to have graphical mode VT VGA with
text mode loader.

screen.textmode can have possible values "0" to disable text mode,
and "1" to set text mode.
2021-01-06 14:38:55 +02:00