Commit graph

196 commits

Author SHA1 Message Date
Warner Losh
c8e7050f8a efi: switch boot_services_gone to boot_services_active
Turn the presence or absence of boot services into a positive bool (and
change its type to bool). Move declaration to efi.h in the global
variables section.

Sponsored by:		Netflix

Reviewed by:	tsoome, kib
Differential Revision:	https://reviews.freebsd.org/D31814

(cherry picked from commit 305ef653bc)
2022-06-26 07:58:55 +03:00
Gordon Bergling
7a8585c073 stand: Fix a common typo in source code comments
- s/independant/independent/

(cherry picked from commit c44b5e090d)
2022-06-10 14:23:25 +02:00
Gordon Bergling
97531acbf8 stand: Remove a double word in a source code comment
- s/be be/be/

(cherry picked from commit 49f6a83ed8)
2022-04-14 08:07:55 +02:00
Emmanuel Vadot
19d26be3f3 loader: tslog: Add more log for module loading
This helps mesuring what's happening when we load the kernel/modules/mfsroot.

This also adds TSENTER2 which uses the third argument of TSRAW, same
as in the kernel.

MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33699

(cherry picked from commit 01cad73192)
2022-01-27 11:06:43 +01:00
Emmanuel Vadot
14f0497aa4 loader: Add more bus name to pnpautoload
Add ofwbus, iicbus and spibus to pnpautoload so modules under those
buses will be loaded.
On my rockpro64 now :
OK pnpautoload -v
Autoloading modules for simplebus
Using DTB provided by EFI at 0x8100000.
Autoloading modules for ofwbus
/boot/kernel/rk_spi.ko text=0x14b2 text=0xd4c data=0x4d0+0x8 syms=[0x8+0xa98+0x8+0x807]
/boot/kernel/dwwdt.ko text=0x12e2 text=0x78c data=0x4c8+0x10 syms=[0x8+0x990+0x8+0x6e1]
Autoloading modules for iicbus
Autoloading modules for spibus
/boot/kernel/mx25l.ko text=0x1613 text=0x114c data=0x6e8+0x8 syms=[0x8+0xa08+0x8+0x665]
loading required module 'fdt_slicer'
/boot/kernel/fdt_slicer.ko text=0x95e text=0x340 data=0x290 syms=[0x8+0x6c0+0x8+0x4a0]

(cherry picked from commit 4c0c353d0e)
2022-01-14 14:38:07 +01:00
Emmanuel Vadot
e52cb5ee22 loader: Fix pnpload and add some usage
pnpload needs a busname and a compat data.

(cherry picked from commit d4874307fd)
2022-01-14 14:37:55 +01:00
Emmanuel Vadot
a327bd3058 loader: Fix pnpmatch and add some usage
pnpmatch needs a busname and a compat data.

(cherry picked from commit 544af629a4)
2022-01-14 14:37:39 +01:00
Emmanuel Vadot
9418a62610 stand: Don't build readtest command on mips
MIPS doesn't have getsecs which is used in this command.
Simply don't include it for this arch.

This is a direct commit to stable/13.

Sponsored by:	Beckhoff Automation GmbH & Co. KG
2022-01-13 14:38:24 +01:00
Emmanuel Vadot
c95afea4a8 loader: bcache: Fix debug printf
Use %j to it works on 64 and 32 bits system.

Reviewed by:	imp, tsoome
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33430

(cherry picked from commit 8ed8b4203a)
2022-01-13 08:58:46 +01:00
Emmanuel Vadot
37e1449d29 loader: Add preload operation to fs_ops
When we load an ELF file (kernel or module) we do seek(2) a lot to
parse/load the different sections of the ELF file.
Protocol like TFTP suffers a lot from this as there is no resume or
a way to start the tranfer from a specified offset in the file.
fs_preload is added to help those protocol.
Call preload just after opening the ELF file that we need to load so
the underlying method can cache the hole file and then read/lseek operations
are faster.

Reviewed by:	imp
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33409

(cherry picked from commit c25d9aff46)
2022-01-13 08:58:31 +01:00
Toomas Soome
bc9154a208 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

(cherry picked from commit b4cb3fe0e3)
2022-01-13 08:58:21 +01:00
Emmanuel Vadot
0078d54c09 loader: Add a readtest command
readtest will simply load the file in memory, useful for timing
loading on some filesystems.

Reviewed by:	tsoome
MFC after:	2 weeks
Sponsored by:	Beckhoff Automation GmbH & Co. KG
Differential Revision:	https://reviews.freebsd.org/D33411

(cherry picked from commit 70661eaafa)
2022-01-13 08:55:42 +01:00
Toomas Soome
835f59f324 loader.efi: to preserve heap space, use AllocatePages() for shadow_fb
shadow FB size could be rather large and depends on resolution,
instead of using heap, allocate dedicated space outside of heap.

Reviewed by: manu
Differential Revision: https://reviews.freebsd.org/D33600

(cherry-picked from 221376db0c)
2022-01-10 12:28:30 +02:00
Toomas Soome
04a0bd52d6 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.

Differential Revision: https://reviews.freebsd.org/D33305

(cherry-picked from 6102f43cf0)
2022-01-10 12:26:57 +02:00
Colin Percival
3684bb89d5 MFC: Improve readahead in loader
style: Fix leading whitespace in bcache.c
loader: Refactor readahead adjustment in bcache
loader bcache: Track unconsumed readahead
loader bcache: Allow readahead up to 256 kB I/Os

Sponsored by:	https://www.patreon.com/cperciva

(cherry picked from commit 5a01dea7e8)
(cherry picked from commit b841148bbb)
(cherry picked from commit 04b9b7c507)
(cherry picked from commit 248682a589)
2021-12-29 14:53:19 -08:00
Maxim Sobolev
57e897ec3d 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

(cherry picked from commit 0d13f5343f)
2021-12-29 14:53:19 -08:00
Colin Percival
45156a9468 loader: Set twiddle globaldiv to 16 by default
Booting FreeBSD on an EC2 c5.xlarge instance, the loader "twiddles"
810 times over the course of 510 ms, a rate of 1.59 kHz. Even accepting
that many systems are slower than this particular VM and will take
longer to boot (especially if using spinning-rust disks), this seems
like an unhelpfully large amount of twiddling when compared to the
~60 Hz frame rate of many displays; printing the twiddles also consumes
roughly 10% of the boot time on the aforementioned VM.

Setting the default globaldiv to 16 dramatically reduces the time spent
printing twiddles to the console while still twiddling at roughly 100
Hz; this should be ample even for systems which take longer to boot and
consequently twiddle slower.

Note that this can adjusted via the twiddle_divisor variable in
loader.conf, but that file is not processed until nearly halfway
through the loader's runtime.

Sponsored by:	https://www.patreon.com/cperciva
Differential Revision:	https://reviews.freebsd.org/D32163

(cherry picked from commit 7457840230)
2021-12-29 14:53:19 -08:00
Colin Percival
89a9852f32 MFC loader+userland TSLOG support
stand/common: Add file_addbuf()
libsa: Add support for timestamp logging (tslog)
stand/common: Add support for timestamp logging (tslog)
i386/loader: Call tslog_init
efi/loader: Call tslog_init (+ bugfix)
stand/common command_boot: Pass tslog to kernel
kern_tslog: Include tslog data from loader
loader: Use tslog to instrument some functions
Add userland boot profiling to TSLOG (+ bugfix)

Sponsored by:	https://www.patreon.com/cperciva

(cherry picked from commit 60a978bec9)
(cherry picked from commit e193d3ba33)
(cherry picked from commit c8dfc327db)
(cherry picked from commit c4b65e954f)
(cherry picked from commit f49381ccb6)
(cherry picked from commit 537a44bf28)
(cherry picked from commit fe51b5a76d)
(cherry picked from commit 313724bab9)
(cherry picked from commit 46dd801acb)
(cherry picked from commit 52e125c2bd)
(cherry picked from commit 19e4f2f289)
2021-12-29 14:53:18 -08:00
Gordon Bergling
1c53a9d354 gfx_fb: Fix a typo in a source code comment
- s/decriptor/descriptor/

(cherry picked from commit b5e0a70193)
2021-12-25 11:40:36 +01:00
Leandro Lupori
8a62b07bce powerpc64le: stand fixes
Fix boot1 and loader on PowerPC64 little-endian (LE).

Due to endian issues, boot1 couldn't find the UFS boot partition
and loader wasn't able to load the kernel. Most of the issues
happened because boot1 and loader were BE binaries trying to access
LE UFS partitions and because loader expects the kernel ELF image
to use the same endian as itself.

To fix these issues, boot1 and loader are now built as LE binaries
on PPC64LE. To support this, the functions that call OpenFirmware
were enhanced to correctly perform endian conversion on its input
and output arguments and to change the CPU into BE mode before
making the calls, as OpenFirmware always runs in BE. Besides that,
some other small fixes were needed.

Submitted by:		bdragon (initial version)
Reviewed by:		alfredo, jhibbits
Sponsored by:		Instituto de Pesquisas Eldorado (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D32160

(cherry picked from commit f83288645c)
2021-11-05 11:29:40 -03:00
Toomas Soome
b91af716ed loader: dev_net.c should use __func__ with printf
We have printf calls with function name hardwired to string,
sometimes wrong name. Use __func__ instead.

(cherry picked from commit 1a25c51e38)
2021-10-01 09:55:18 +03:00
Toomas Soome
1f91b3b631 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.

(cherry picked from commit 4c7a3a70e0)
2021-09-09 11:28:07 +03: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
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
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
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
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
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
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
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
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
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
Andrew Turner
f6f0b849fb Reuse the amd64 loader relocation code on arm64
There is no need to keep multiple copies of the relocation code. The
amd64 code works on arm64 with a few small changes to relocation types.

Sponsored by:	Innovate UK
Differential Revision:	https://reviews.freebsd.org/D28213
2021-01-20 17:59:38 +00:00
Toomas Soome
4bbfe4bf08 loader: comment on rgb_to_color_index()
Add small comment block about rgb_to_color_index().
2021-01-19 22:15:26 +02:00
Toomas Soome
1caed70c62 loader: update gfx module
Update from illumos review process.
Add more comments, drop memory buffer from blt functions.
2021-01-18 00:15:36 +02:00
Emmanuel Vadot
0f2434ea00 loader: Partial revert of 987eabdc2a
The arm relocation code doesn't not work and make loader not loading
dependancies.

Reported by:	Dr. Rolf Jansen <freebsd-rj@obsigna.com>
2021-01-17 17:41:25 +01:00
Toomas Soome
3ddf7eade0 loader.efi: Use Blt with gop as default
System with FB address 0x4000000000 does not draw, Blt() is doing fine.
I think, we can assume the Blt will usually work.
2021-01-16 17:39:40 +02:00
Toomas Soome
20fb2ea2c7 loader: really use bold font for vga text mode
8x16v turns out to be too thin and hard to read,
use bold font instead.
2021-01-08 01:24:30 +02:00
Toomas Soome
3630506b9d loader: implement framebuffer console
Draw console on efi.
Add vbe framebuffer for BIOS loader (vbe off, vbe on, vbe list,
vbe set xxx).
autoload font (/boot/fonts) based on resolution and font size.
Add command loadfont (set font by file) and
variable screen.font (set font by size). Pass loaded font to kernel.

Export variables:
screen.height
screen.width
screen.depth

Add gfx primitives to draw the screen and put png image on the screen.
Rework menu draw to iterate list of consoles to enamble device specific
output.

Probably something else I forgot...

Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D27420
2021-01-02 21:41:36 +02:00
Jessica Clarke
c46f7610d4 loader: Print autoboot countdown immediately, not at 9
For the first second otime and ntime are equal so no message gets
printed. Instead we should print the countdown right from the start,
although we do it at the end of the first iteration so that if a key has
already been pressed then the message is suppressed.

Reviewed by:	imp
Approved by:	imp
Differential Revision:	https://reviews.freebsd.org/D26935
2020-12-14 00:46:24 +00:00
Kyle Evans
0a0d522b36 stand: liblua: add a pager module
This is nearly a 1:1 mapping of the pager API from libsa.  The only real
difference is that pager.output() will accept any number of arguments and
coerce all of them to strings for output using luaL_tolstring (i.e. the
__tostring metamethod will be used).

The only consumer planned at this time is the upcoming "show-module-options"
implementation.

MFC after:	1 week
2020-12-12 21:25:38 +00:00
Toomas Soome
3e9f0f1d29 loader: cstyle cleanup of console.c
cstyle cleanup only, no functional changes intended.
2020-11-14 10:56:40 +00:00
Toomas Soome
83a252c6a1 loader: cstyle cleanup of bootstrap.h did miss a bit
correct small issues - misplaced comment and typos.
2020-11-08 09:49:51 +00:00
Toomas Soome
90b307a897 loader: cstyle cleanup of bootstrap.h
No functional changes intended.
2020-11-08 09:35:41 +00:00
D Scott Phillips
987eabdc2a stand/reloc_elf: Handle relative relocations for arm{,64} and riscv
Extend the powerpc relative relocation handling from r240782 to a
handful of other architectures.  This is needed to properly read
dependency information from kernel modules.

Reviewed by:	jhb
Approved by:	scottl (implicit)
MFC after:	1 week
Sponsored by:	Ampere Computing, Inc.
Differential Revision:	https://reviews.freebsd.org/D26365
2020-09-21 22:24:46 +00:00