Commit graph

1297 commits

Author SHA1 Message Date
Kyle Evans
96df822abb 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).

Sponsored By:	National Bureau of Economic Research
Sponsored by:	Klara, Inc.

(cherry picked from commit 3daa8e165c)
2021-09-04 02:44:33 -05:00
Konstantin Belousov
0d693b8bbc efi loader: disallow user to configure staging area size less than default
(cherry picked from commit b54eec8366)
2021-09-03 04:08:35 +03:00
Konstantin Belousov
8a51116a86 Restore the definition of EFI_STAGING_SIZE
(cherry picked from commit b850806921)
2021-09-03 04:08:35 +03:00
Gordon Bergling
8fc67f27d0 libsa: Fix a typo in source code comments
- s/mininum/minimum/

(cherry picked from commit 005fe24f2a)
2021-09-01 06:34:20 +02:00
Toomas Soome
0e98ea6423 loader: loader_lua can run command_more twice
When we quit pager, the return value 1 is returned and command_more()
interprets it as error.

when lua loader gets error from command, it will try to
interpret it once more, so we get the same file shown once more.

There is no reason why we should return error from command_more().

(cherry picked from commit 7b0d05d56d)
2021-08-28 10:38:35 +03:00
Toomas Soome
d54fdcd59e loader: FB console does leave garbage on screen while scrolling
Scrolling screen will leave "trail" of chars from first column.
Apparently caused by cursor location mismanagement.
Make sure we do not [attempt to] set cursor out of the screen.

(cherry picked from commit e5a50b0329)
2021-08-28 08:37:03 +03:00
Toomas Soome
ed760a3a6f libsa: cstyle cleanup of dosfs.c
No functional changes intended.

(cherry picked from commit 3ec0714d6d)
2021-08-26 11:02:22 +03:00
Toomas Soome
cb08b3020f loader: open file list should be dynamic
Summary:
Open file list is currently created as statically allocated array
(64 items). Once this array is filled up, loader will not be able
to operate with files. In most cases, this mechanism is good enough,
but the problem appears, when we have many disks with zfs pool(s).
In current loader implementation, all discovered zfs pool
configurations are kept in memory and disk devices open - consuming
the open file array. Rewrite the open file mechanism to use
dynamically allocated list.

Reviewed by:	imp
Differential Revision: https://reviews.freebsd.org/D31364

(cherry picked from commit 97cbd5e722)
2021-08-26 10:59:28 +03:00
Roger Pau Monné
25a4a79ccc loader: fix multiboot loading on UEFI
(cherry picked from commit 5e4279a8f3)
2021-08-24 02:21:15 +03:00
Konstantin Belousov
1b33aa1f5f amd64 UEFI loader: stop copying staging area to 2M physical
(cherry picked from commit f75caed644)
2021-08-24 02:21:15 +03:00
Toomas Soome
416194c9af loader: cstyle cleanup of userboot/devicename.c
No functional changes intended.

(cherry picked from commit 5d5a621664)
2021-08-19 16:05:26 +03:00
Gordon Bergling
337c971838 Fix a few typos in source code comments
- s/becase/because/

(cherry picked from commit fa7a635f7e)
2021-08-19 09:29:50 +02:00
Mitchell Horne
952226eedb Prefer MK_SSP=no to SSP_CFLAGS=
It is more idiomatic. CFLAGS is only augmented with $SSP_CFLAGS when
$MK_SSP != "no".

Reviewed by:	imp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D31401

(cherry picked from commit 61ed578ee6)
2021-08-11 13:56:28 -03:00
Toomas Soome
e663905714 loader: tftp client should use server address from rootip
servip is set from bootp bp_siaddr (if present) and rootip is
set immediately from servip in tha sane bootp code.

However, the common/dev_net.c does only set rootip (based on
url processing etc). Therefore, we should also use rootip in tftp
reader.

Fixes hung tftp based boot when bp_siaddr is not provided.

MFC after: 1 week

(cherry-picked from commit 1b1bb6f178)
2021-08-08 16:21:07 +03:00
Toomas Soome
e6847536a8 loader: cstyle cleanup of libsa/lseek.c
Clean up lseek.c, no functional changes intended. This is pre-patch
for open file list rewrite.

MFC after:	1 week

(cherry-picked from commit bbb539b83c)
2021-08-08 16:17:13 +03:00
Andrew Turner
52ec367e70 Use the arm virtual counter in the arm64 loader
It exist on all ARMv8+ CPUs, and other boot loaders rely on it being
present.

Sponsored by:	Innovate UK
Differential Revision: https://reviews.freebsd.org/D30410

(cherry picked from commit 0a0d6ce34d)
2021-08-05 20:50:15 +00:00
Li-Wen Hsu
d2c0584257
loader.conf(5): mention "efi" option for "console" parameter
PR:		213467
Reviewed by:	imp
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D31368

(cherry picked from commit de0c7fbe28)
2021-08-04 07:50:14 +08:00
Warner Losh
a051259072 typo: becauce -> because
Noticed by:	Piotr P. Stefaniak
Sponsored by:	Netflix

(cherry picked from commit 2b720db8d4)
2021-07-30 17:02:07 -06:00
Warner Losh
631cf89fd4 boot: fix OBJS to not include BTX's crt0.o
According to comments in the Makefile, to make pxeboot work we need to
have crt0.o first. This is needed because the simplified loader in
pxeboot assumes that the startup code is at offset 0 in this binary. In
normal booting, the start address can be obtained from headers of the
binary, but since pxeboot encodes this as a pure binary, it has no way
of knowing where that is and assumes 0. Added comments to that effect
in the Makefile.

We've done this by adding it to OBJS before all the other .o's are
added. However, there's a problem. This also adds it to the CLEANFILES
variable, which causes it to be removed from multiple places. The
dependencies may also cause it to be re-built at a time that's after
boot2 is built. This causes installs to fail because at install time
boot2 is considered to be out of date and the programs to rebuild it are
no longer in the path.

Cope with this problem by just adding it to LDFLAGS instead.

Glanced at by:		kevans ("I thought that went in ages ago")
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D28876

(cherry picked from commit e713d3a013)
2021-07-30 17:00:17 -06:00
Warner Losh
320e5d7d39 Revert "loader: support.4th resets the read buffer incorrectly"
This reverts commit 9c1c02093b. It seems
to have broken all old nextboot.conf files causing hangs on boot.

PR:	239315

(cherry picked from commit 4783fb730f)
2021-07-26 20:37:40 -06:00
Warner Losh
5ad4296780 loader: make sure CPUTYPE is ignored when building
CPUTYPE?=native causes -march=native to be added to the command
line. When the host machine is haswell, this causes some versions of
clang to generate code that can't execute in the efi boot loader
environment. Set _CPUCFLAGS= to undo what's done bsd.cpu.mk. bsd.cpu.mk
is included too early to control with NO_CPU_CFLAGS here. The only other
option is to put that in all the Makefiles, and this is less tedious and
error prone.

PR:			194641
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D31187
MFC After:		1 week

(cherry picked from commit 7a0c0ff7ee)
2021-07-21 10:13:10 -06:00
Emrion
b0b483b64b Fix pmbr issues > 2TB
These issues have low impact because they require precise circumstances
to trigger one of them. The disk must be > 2 TiB in size and either:
- The primary GPT header is dammaged.
- The freebsd-boot partiton is located farther than the first 2 TiB of
  the disc and one of its sectors takes place at a lba value that makes
  the higher 32 bits of this very value change.
Errors and corrections folow:
- decl and incl don't affect CF, so replace with subl/addl $1
- repe uses %cx, so move size to it with movw
- moving a 64-bit value with %cx of 2 (should be 4) so addresses
  > 2TB will work.

PR:			233180
Reviewed by:		imp@ (applied patch using description in bug)
Differential Revision:	https://reviews.freebsd.org/D31100

(cherry picked from commit 0ca9f1d4a3)
2021-07-21 10:13:10 -06:00
Warner Losh
1e1d372556 loader: Don't reserve space for symbols twice.
The current code bumps lastaddr twice for the symbol table
location. However, the first bump is bogus and results in wasted
space. Remove it.

PR:			110995
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D31017

(cherry picked from commit 297e9f364b)
2021-07-16 12:28:45 -06:00
Daniel Gerzo
f32c4c3b00 loader: update autoboot description and move to loader.conf.5
Document "NO" special value for the autoboot_delay and move the
description to loader.conf.5.

imp reworked some of the wording from danger's patch.

Reviewed by:		imp
PR:			85128
Differential Revision:	https://reviews.freebsd.org/D11887

(cherry picked from commit 71f6aea415)
2021-07-16 12:28:44 -06:00
John Hood
37053c21e9 loader: support.4th resets the read buffer incorrectly
Large nextboot.conf files (over 80 bytes) are not read correctly by the
Forth loader, causing file parsing to abort, and nextboot configuration
fails to apply.

Simple repro:

nextboot -e foo=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
shutdown -r now

That will cause the bug to cause a parse failure but shouldn't otherwise
affect the boot.  Depending on your loader configuration, you may also
have to set beastie_disable and/or reduce the number of modules loaded
to see the error on a small console screen.  12.0 or CURRENT users will
also have to explicitly use the Forth loader instead of the Lua loader.
The error will look something like:

Warning: syntax error on file /boot/loader.conf.local
foo="xxxxxxxxxxxxxxnextboot_enable="YES"
                                    ^
/boot/support.4th has crude file I/O buffering, which uses a buffer
'read_buffer', defined to be 80 bytes by the 'read_buffer_size'
constant.  The loader first tastes nextboot.conf, reading and parsing
the first line in it for nextboot_enable="YES".  If this is true, then
it reopens the file and parses it like other loader .conf files.

Unfortunately, the file I/O buffering code does not fully reset the
buffer state in the reset_line_reading word.  If the last file was read
to the end, that doesn't matter; the file buffer is treated as empty
anyway.  But in the nextboot.conf case, the loader will not read to the
end of file if it is over 80 bytes, and the file buffer may be reused
when reading the next file.  When the file is reread, the corrupt text
may cause file parsing to abort on bad syntax (if the corrupt line has
<>2 quotes in it), the wrong variable to be set, no variable to be set
at all, or (if the splice happens to land at a line ending) something
approximating normal operation.

The bug is very old, dating back to at least 2000 if not before, and is
still present in 12.0 and CURRENT r345863 (though it is now hidden by
the Lua loader by default).

Suggested one-line attached.  This does change the behavior of the
reset_line_reading word, which is exported in the line-reading
dictionary (though the export is not documented in loader man pages).
But repo history shows it was probably exported for the PNP support
code, which was never included in the loader build, and was removed 5
months ago.

One thing that puzzles me: how has this bug gone unnoticed/unfixed for
nearly 2 decades?  I find it hard to believe that nobody's tried to do
something interesting with nextboot, like load a kernel and filesystem,
which is what I'm doing.

PR: 239315
Reviewed by: imp

(cherry picked from commit 9c1c02093b)
2021-07-16 12:28:44 -06:00
Mark Johnston
765c6eb395 stand: Fix __elfN(loadimage) return value
Caller functions expect __elfN(loadimage) to return a value of zero on
failure and the file size on success.

PR:		256390
Reviewed by:	markj

(cherry picked from commit 1ea87e2a70)
2021-06-20 15:00:54 -04:00
Andrew Turner
abb9d448b3 Update the EFI timer to be called once a second
There is no need to call it evert 10ms when we need 1s granularity.
Update to update the time every second.

Reviewed by:	imp, manu, tsoome
Sponsored by:	Innovate UK
Differential Revision: https://reviews.freebsd.org/D30227

(cherry picked from commit 93f7be080f)
2021-06-12 02:21:55 +01:00
David Bright
3045f4aa1a libsa: Fix infinite loop in bzipfs & gzipfs
A bug in the loader's bzipfs & gzipfs filesystems caused compressed
kernel and modules not to work on EFI systems with a veriexec-enabled
loader. Since the size of files in these filesystems are not known
_a priori_ `stat` would initialize the size to -1 and the loader would
then hang in an infinite loop while trying to seek (read) to the end
of file since the loop termination condition compares the current
offset to that negative target position.

Sponsored by:	Dell EMC Isilon

(cherry picked from commit 3df4c387d2)
2021-06-09 11:11:01 -05:00
Toomas Soome
3dc9f92a0d loader: gfx_fb_drawrect should use GfxFbBltVideoFill
The gfx_fb_drawrect() is drawing rectangle by pixels, this can be very
slow on some systems. Use Blt() video fill primitive instead.

Testing done: Tested on mac mini 2012 where the issue was revealed

(cherry picked from commit 5365af662c)

Reviewed by:	yuripv
2021-05-23 03:46:51 +03:00
Hans Petter Selasky
30c20249b9 Fix build of stand/usb .
Sponsored by:	Mellanox Technologies // NVIDIA Networking

(cherry picked from commit 7497dd5889)
2021-05-10 16:11:19 +02:00
Toomas Soome
eabfffcb4c loader: do not output empty menu title
As we output spaces around the menu title, we should also check,
if the title is actually empty string.

PR:		255299
Submitted by:	Jose Luis Duran
Reported by:	Jose Luis Duran

(cherry picked from 4ba91fa073)
2021-04-28 12:35:54 +03:00
Alex Richardson
f323095645 Don't add -Winline for WARNS=6
This warning is very rarely useful (inline is a hint and not mandatory).
This flag results in many warnings being printed when compiling C++
code that uses the standard library with GCC.

This flag was originally added in back in r94332 but the flag is a no-op
in Clang ("This diagnostic flag exists for GCC compatibility, and has no
effect in Clang"). Removing it should make the GCC build output slightly
more readable.

Reviewed By:	jrtc27, imp
Differential Revision: https://reviews.freebsd.org/D29235

(cherry picked from commit c8c62548bf)
2021-04-22 10:44:51 +01:00
Alex Richardson
52b6501bd7 libsa: Remove conflicting .global/.weak directive
LLVM12 complains if you change the symbol binding:
`error: _longjmp changed binding to STB_GLOBAL`
In this case LLVM actually ignored the weak directive and used the
later .global, but GNU as would mark the symbol as weak.
None of the other architectures mark the libsa _setjmp as weak so
just drop this directive.

(cherry picked from commit 59b2caef05)
2021-04-10 14:01:05 +01:00
Toomas Soome
3056bbfc2c loader: we should support pools without features
nvlist_check_features_for_read() does return error when there
are no features for read.

Reported by:	yuripv

(cherry picked from commit d36341f7b8)
2021-04-09 23:09:28 +03:00
Toomas Soome
d019c774e9 loader: insert spaces around menu title
Small visual nit, make menu title more clean

(cherry picked from 62ffcaab8f)
2021-04-04 02:03:33 +03:00
Mark Johnston
7cde0b06f9 stand: Load INIT_ARRAY and FINI_ARRAY sections
This is required for preloading modules into a KASAN-configured kernel.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 7b1b5aad95)
2021-03-22 21:32:08 -04:00
Martin Matuska
57b9b81894 zfs: merge OpenZFS master-9312e0fd1
Notable upstream changes:
  778869fa1 Fix reporting of mount progress
  e7adccf7f Disable use of hardware crypto offload drivers on FreeBSD
  03e02e5b5 Fix checksum errors not being counted on repeated repair
  64e0fe14f Restore FreeBSD resource usage accounting
  11f2e9a49 Fix panic if scrubbing after removing a slog device

(cherry picked from commit ba27dd8be8)
2021-03-10 02:53:32 +01:00
Toomas Soome
38fe00d43d loader: cursor off should restore display content
When drawing cursor, we should store original display
content because there may be image data we would like to restore
when the cursor is removed.

PR:		254054
Reported by:	Jose Luis Duran

(cherry picked from commit d708f23ebb)
2021-03-09 09:32:17 +02:00
Toomas Soome
99e1b2d798 loader_4th: brand image is aligned right
With screen border removed, I forgot to update forth brand image
coordinates to avoid image alignment.

(cherry picked from commit 6a3095aa6d)
2021-03-06 11:06:51 +02:00
Toomas Soome
209247b961 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).

(cherry picked from commit becaac3972)
2021-03-04 17:38:37 +02:00
Toomas Soome
05e4a34e43 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.

(cherry picked from commit 61c50cbc09)

Reported by:	Kamigishi Rei
2021-03-01 12:54:36 +02:00
Toomas Soome
debcf835b1 loader: unload command should reset tg_kernel_supported in gfx_state
While loading kernel, we check if vt/vbe backend support is included in
kernel and set the tg_kernel_supported flag in gfx_state. unload
command needs to reset this flag to allow next load to perform
this check with new kernel.

Reported by: jhb

(cherry picked from commit 9b388ac303)
2021-02-21 22:32:14 +02:00
Dimitry Andric
1714029b8a Fix loader detection of vbefb support on !amd64
On i386, after 6c7a932d0b, the vbefb vt
driver was no longer detected by the loader, if any kernel module was
loaded after the kernel itself.

This was caused by the parse_vt_drv_set() function being called multiple
times, resetting the detection flag. (It was called multiple times,
becuase i386 .ko files are shared objects like the kernel proper, while
this is not the case on amd64.)

Fix this by skipping the set_vt_drv_set lookup if vbefb was already
detected.

Reviewed by:	tsoome
(cherry picked from commit 6e26189be4)
2021-02-21 22:31:56 +02:00
Toomas Soome
b7f1582221 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.

(cherry picked from commit 6c7a932d0b)
2021-02-21 22:31:38 +02:00
Toomas Soome
57d6e82d1f loader_lua: consider userboot console as serial
We use ascii box chars with serial console because we do not know
if terminal can draw unixode box chars. Same problem is about userboot
console.

(cherry picked from commit 5d8c062fe3)
2021-02-21 13:07:12 +02:00
Guangyuan Yang
c05f4077ec pxeboot(8): remove antiquated information
While I was there:
- Fix some typos
- Fix an excessive argument "indent" reported by mandoc -Tlint
- Replace a dead link with the one suggested by
  https://www.uefi.org/uefi

Submitted by:	linimon (in part)
Reviewed by:	bcr
Differential Revision:	https://reviews.freebsd.org/D27774

(cherry picked from commit c90fb7acf0)
2021-02-22 01:13:24 +00:00
Toomas Soome
d9dd77252c loader: do not autoselect smaller font than 8x16 with high res display
The VT screen buffer size is calculated based on our default
built in (8x16) font.

With high-resolution display, we want to use at least 8x16 font,
or we will have large unused areas on screen.

MFC after: 1 week

(cherry picke from commit a26f735858)
2021-02-15 23:05:28 +02:00
Toomas Soome
b72a2e3ffa 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

(cherry picke from commit 96bef2053a)
2021-02-15 23:04:01 +02:00
Toomas Soome
0c839497c1 loader.efi: There are systems without ConOut, also use ConOutDev
Conout does contian the default output device name.
ConOutDev does contain all possible output device names, so we can
use it as fallback, when there is no ConOut.

PR: 253253

(cherry picked from commit 2bd4ff2d89)
2021-02-04 23:33:15 +02:00
Roger Pau Monné
51ab5e0d82 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.

(cherry picked from commit b6d85a5f51)
2021-02-03 14:07:43 +01:00