Commit Graph

1343 Commits

Author SHA1 Message Date
Kyle Evans
ed107537b4 lualoader: use more concise verbiage for autoboot
The behavior remains the same, but lualoader now uses the more concise
verbiage that forthloader used.  This is particularly important because
the previous line would exceed the right boundary of the menu and run
straight into space that would typically be allowed for the logo.

This makes it slightly easier to port logos from forthloader to
lualoader.
2021-09-09 02:01:50 -05:00
Kyle Evans
e19d9a9b6e lualoader: allow brands to specify a shift
Some brands will want to specify a shift to make sure they're properly
centered; let it happen.
2021-09-09 02:01:50 -05:00
Kyle Evans
763bcebe0b lualoader: remove shadowed local from graphics:drawitem()
for loop vars are local already and distinct from this earlier
declaration; remove it.
2021-09-09 02:01:50 -05: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
Dimitry Andric
c90cab0d66 i386 loaders: avoid lld 13 garbage collecting linker sets
Because lld 13 and higher default to garbage collecting start/stop
symbols when using --gc-sections, the linker sets used in the i386 boot
loaders will disappear. This leads to the loaders not recognizing any
commands, and failure to boot.

Until we have a good set of linker scripts for the loaders, work around
it by disabling the start-stop-gc feature.

MFC after:	1 week
2021-09-08 14:04:13 +02:00
Toomas Soome
4c7a3a70e0 loader.efi: fix console output after BS off
When Boot Services (BS) are switched off, we can not use BS
functions any more. Since drawn console does implement our own
Blt(), we can use it to draw the console.

However, SimpleTextOutput protocol based console output must be
blocked.

Tested by inserting printf() after ExitBootServices() call.

MFC after:	1 week
2021-09-03 00:48:56 +03:00
Gordon Bergling
005fe24f2a libsa: Fix a typo in source code comments
- s/mininum/minimum/

MFC after:	3 days
2021-08-29 10:09:58 +02:00
Konstantin Belousov
b54eec8366 efi loader: disallow user to configure staging area size less than default
We need to round it up to 2M, for instance.  Having staging area too small
might cause the first resize to use negative size for memmove()/memcpy(),
which kills loader.

Tested by:	Harry Schmalzbauer <freebsd@omnilan.de>
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2021-08-27 19:49:01 +03:00
Konstantin Belousov
b850806921 Restore the definition of EFI_STAGING_SIZE
The definition can be overridden by users, and before f75caed644 it
was in MBs.  Make the symbol' unit MB, to be compatible with users
customizations.

Reported and tested by:	Harry Schmalzbauer <freebsd@omnilan.de>
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2021-08-27 19:48:53 +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
Konstantin Belousov
6032b6ba95 amd64 UEFI loader: enable automatic disable of staging area copying
Discussed with:	emaste
Sponsored by:	The FreeBSD Foundation
MFC after:	1 month
2021-08-25 22:26:52 +03:00
Toomas Soome
7b0d05d56d 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().

MFC after:	1 week
2021-08-21 21:28:54 +03:00
Toomas Soome
e5a50b0329 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.

MFC after:	1 week
2021-08-21 19:17:25 +03:00
Maxim Sobolev
0d13f5343f Only trigger read-ahead if two adjacent blocks have been requested.
The change makes block caching algorithm to work better for remote
media on low-BW/high-delay links.

This cuts boot time over IP KVMs noticeably, since the initialization
stage reads bunch of small 4th (and now lua) files that are not in
the same cache stripe (usually), thus wasting lot of bandwidth and
increasing latency even further.

The original regression came in 2017 with revision 87ed2b7f5. We've
seen increase of time it takes for the loader to get to the kernel
loading from under a minute to 10-15 minutes in many cases.

Reviewed by:	tsoome
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D31623
2021-08-20 14:08:01 -07:00
Toomas Soome
3ec0714d6d libsa: cstyle cleanup of dosfs.c
No functional changes intended.

MFC after:	1 week
2021-08-19 17:36:25 +03:00
Gordon Bergling
fa7a635f7e Fix a few typos in source code comments
- s/becase/because/

MFC after:	5 days
2021-08-14 09:06:09 +02:00
Toomas Soome
5d5a621664 loader: cstyle cleanup of userboot/devicename.c
No functional changes intended.

MFC after:	1 week
2021-08-11 10:13:46 +03:00
Roger Pau Monné
5e4279a8f3 loader: fix multiboot loading on UEFI
The Xen kernel has no symbol tables, so calling lookup_symbol against
it triggers the following Divide by Zero fault:

Loading Xen kernel...
/boot/xen data=0x2809c8+0x149638 |
!!!! X64 Exception Type - 00(#DE - Divide Error)  CPU Apic ID - 00000000 !!!!

Fix lookup_symbol to prevent the #DE fault from happening if the
symbol table is not loaded and also fix loadfile_raw to mark multiboot
kernels as relocatable, since the only multiboot kernel supported is
Xen and was already unconditionally booted as relocatable.

Fixes: f75caed644 ('amd64 UEFI loader: stop copying staging area to 2M physical')
Reviewed by: imp, kib
Differential Revision: https://reviews.freebsd.org/D31507
2021-08-12 09:18:33 +02:00
Toomas Soome
97cbd5e722 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
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D31364
2021-08-10 21:54:32 +03:00
Warner Losh
879675e9a0 stand: Add MK_PIE=no to defs.mk
There's no need to build both pie and non-pie .o's for stand. There's
some other build thing with MK_BEAR_SSL=yes and/or MK_LOADER_VERIEXEC=yes
that causes the pie build to fail that the 'ar' stage now. Since we don't
need the PIE stuff and the non-PIE stuff, disable PIE for the boot loader.

Reviewed by:	emaste
Sponsored by:	Netflix
2021-08-11 11:03:19 -06:00
Konstantin Belousov
f75caed644 amd64 UEFI loader: stop copying staging area to 2M physical
On amd64, add a possibility to activate kernel with staging area in place.
Add 'copy_staging' command to control this.  For now, by default the
old mode of copying kernel to 2M phys is retained.  It is going to be
changed in several weeks.

On amd64, add some slop to the staging area to satisfy both requirements
of the kernel startup allocator, and to have space for minor staging data
increase after the final size is calculated.  Add a new command
'staging_slop' to control its size.

Improve staging area resizing, in particular, reallocate it anew if
we cannot grow it neither down nor up.

Reviewed by:	kevans, markj
Discussed with:	emaste (the delivery plan)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D31121
2021-08-08 22:52:29 +03:00
Mitchell Horne
61ed578ee6 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
2021-08-04 15:23:22 -03:00
Alex Richardson
5e9226f063 Fix build of stand/ when building world with ASAN
The userboot/test  program links against the default userspace libraries
(e.g. shared libgcc_s.so) that will be instrumented if WITH_ASAN is set.
All other programs link against libsa instead of libc and therefore can't
use the sanitizer runtime library. To fix the stand/ build with
sanitizers, we disable MK_ASAN/MK_UBSAN if -nostdlib is found in the
LDFLAGS (i.e. we are using libsa instead of libc).

Reviewed By:	imp, tsoome
Differential Revision: https://reviews.freebsd.org/D31047
2021-08-02 14:33:24 +01:00
Toomas Soome
1b1bb6f178 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
2021-08-02 15:43:54 +03:00
Toomas Soome
bbb539b83c 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
2021-08-01 10:11:17 +03:00
Li-Wen Hsu
de0c7fbe28
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
2021-08-01 06:41:49 +08:00
Warner Losh
6b51baf6a8 cli.lua.8: make the command match the code
It's disable-device, not device-disable

Spotted by:		jrtc27
Sponsored by:		Netflix
2021-07-28 20:54:14 -06:00
Warner Losh
07c4b78d0a lua loader: Add disable-device to disable a device.
disable-device fooX will set hint.foo.X.disabled=1 as a way to easily
disable a device attaching during boot.

Reviewed by:		tsoome
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D31297
2021-07-28 16:53:00 -06:00
John Hood
dbdf2b52f5 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.

Tested by:		Gary Jennejohn
PR:			239315
MFC After:		3 weeks
Reviewed by:		imp (and correctly applied this time)
Differential Revision:	https://reviews.freebsd.org/D31328
2021-07-28 13:50:38 -06:00
Warner Losh
4783fb730f 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.

Sponsored by:		Netflix
2021-07-26 16:40:41 -06:00
Warner Losh
2b720db8d4 type: becauce -> because
Noticed by:	Piotr P. Stefaniak
Sponsored by:	Netflix
2021-07-21 20:03:35 -06:00
Warner Losh
7a0c0ff7ee 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
2021-07-14 21:06:19 -06:00
Warner Losh
9873c807da loader: Create loader_simp(8) to document simple version of loader
loader_simp is a much simplified version of loader that will process a
linear sequence of commands from loader.rc. It has neither Forth nor Lua
built in and is much smaller. Document it. This is largely copied from
loader.8 since it implements those built-in commands. Future revisions
will fix this duplication.

Sponsored by:		Netflix
2021-07-14 16:59:51 -06:00
Warner Losh
13c98cd06b loader(8): fix path to be correct loader.4th.
boot.4th was a thing for only a few months around FreeBSD 3.1. The
correct name has been loader.4th for a long time.

MFC After:   		2 days
Sponsored by:		Netflix
2021-07-14 16:34:43 -06:00
Warner Losh
29c8295312 loader: small Makefile style change
Move to using M.${option} and M.yes to collecting man pages to install.

Sponsored by:		Netflix
2021-07-14 08:33:01 -06:00
Emrion
0ca9f1d4a3 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
2021-07-13 15:40:44 -06:00
Warner Losh
297e9f364b 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
2021-07-12 15:30:27 -06:00
Daniel Gerzo
71f6aea415 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
2021-07-12 15:13:03 -06:00
John Hood
9c1c02093b 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
2021-07-11 08:47:29 -06:00
Emmanuel Vadot
b464c459ea loader: Fix dtb loading
When calling file_findfile with only a type it returns
the first file matching the type. But in fdt_apply_overlays we
then iterate on the next files and try loading them as dtb overlays.
Fix this by checking the type one more time.

Sponsored by:	Diablotin Systems
Reported by:	Mark Millard <marklmi@yahoo.com>
2021-07-05 15:53:08 +02:00
Colin Percival
e6caac717b libsa: Add tslog support for arm64
The original code only supported x86 and used rdtsc(); we now also
support arm64 and use the CNTVCT_EL0 special register.
2021-06-23 22:21:23 -07: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
Colin Percival
537a44bf28 stand/common command_boot: Pass tslog to kernel
Pass the recorded tslog buffer to the kernel as a "preloaded module".

Reviewed by:	kevans
2021-06-20 20:09:46 -07:00
Colin Percival
f49381ccb6 efi/loader: Call tslog_init
This allows the EFI loader to start recording timestamps.
2021-06-20 20:09:45 -07:00
Colin Percival
c4b65e954f i386/loader: Call tslog_init
This allows the i386 loader to start recording timestamps.

Reviewed by:	kevans
2021-06-20 20:09:44 -07:00
Colin Percival
c8dfc327db stand/common: Add support for timestamp logging (tslog)
This adds tslog_init, which allocates a 2MB buffer for recording
timestamped events; and tslog_publish, which takes the buffer and
passes it to the kernel as a "preloaded module".  These functions
will be used in a later commit.

Reviewed by:	kevans
2021-06-20 20:09:43 -07:00
Colin Percival
e193d3ba33 libsa: Add support for timestamp logging (tslog)
At present this only supports x86, due to the use of the rdtsc
instruction; and is inert unless a buffer is allocated and passed to
the tslog code (which will be done by a future commit).

Reviewed by:	kevans
2021-06-20 20:09:42 -07:00
Colin Percival
60a978bec9 stand/common: Add file_addbuf()
This provides an interface for a memory buffer to be passed from the loader
to the kernel as a "preloaded module".

Reviewed by:	kevans
2021-06-20 20:09:41 -07:00
Mark Johnston
1ea87e2a70 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
MFC after:	2 weeks
2021-06-06 16:44:46 -04:00
Andrew Turner
0a0d6ce34d 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
2021-06-02 10:58:20 +00:00