Commit graph

1382 commits

Author SHA1 Message Date
Alfredo Dal'Ava Junior
e879436ce4 loader: fix powerpc* ofw loader
With the introduction of llvm14, the powerpc* loader used on ofw/pseries
for 32 and 64 bit architectures puts the .data.rel.ro section after
.data section. This caused a crash kernel didn't boot. Bisect pointed to
change https://reviews.llvm.org/D111717 but problem could be fixed by
adding a section description to make it appear in the expected order.

This patch is based on discussion at:
        https://github.com/llvm/llvm-project/issues/56306

MFC after:	1 day
Sponsored by:	Instituto de Pesquisas Eldorado (eldorado.org.br)

(cherry picked from commit 5d48fb3b16)
2022-07-04 09:36:04 -03:00
Toomas Soome
67f8b6d985 loader: GELI encrypted disk should still use device name disk
geli_probe_and_attach() does pick geli_devsw structure for
encrypted disks, the implementation depends on device
name "disk" when device type is DEVT_DISK, but geli_devsw is
setting name field "gelidisk".

PR:		264282
Submitted by:	yamagi@yamagi.org
Reported by:	yamagi@yamagi.org

(cherry picked from commit e417249016)
2022-07-04 09:14:43 +03:00
Toomas Soome
39510c65e3 test_diskread(): detect end of the disk
Detect the end of the disk condition. This may happpen when
disk image is truncated and the reads are addressing blocks past
image end.

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

(cherry picked from commit 942e52f776)
2022-06-26 08:28:07 +03:00
Toomas Soome
c796ba5824 loader.efi: fix panic() after BS off
panic() is using multiple services - attempting to read
keyboard, accessing time functions and finally, exiting the loader.

Protect all the accessed listed above. Note, when BS are off,
we really can not just exit the loader, we only can reboot.

(cherry-picked from commit a2e02d9d8e)
2022-06-26 08:18:13 +03:00
Warner Losh
95e283e4d0 loader: abstract boot services exiting to libefi function
Move direct call of ExitBootServices to efi_exit_boot_services.  This
function sets boot_services_active to false so callers don't have to do
it everywhere (though currently only loader/bootinfo.c is affected).

Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D32226

(cherry picked from commit 77e3db0789)
2022-06-26 08:09:50 +03:00
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
Toomas Soome
412c743721 userboot is missing vdisk_dev
Add vdisk device support in userboot configuration.

(cherry picked fromcommit e368fb6eb6)
2022-06-26 07:52:57 +03:00
Yongbo Yao
721d0a045a Loader: support booting OS from memory disk (MD)
Until now, the boot image can be embedded into the loader with
/sys/tools/embed_mfs.sh, and memory disk (MD) is already supported
in loader source. But due to memory disk (MD) driver isn't registered
to the loader yet, the boot image can't be boot from embedded memory
disk.

Reviewed by:	dab, tsoome
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D29512

(cherry picked from commit 5984246f96)
2022-06-17 14:01:40 -03:00
Ed Maste
813514b573 loader.efi: add cross-reference to loader(8)
The loader.efi man page describes UEFI-specific loader details, but not
general loader information.

MFC after:	3 days
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit f70de61e56)
2022-06-16 08:49:34 -04: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
Andrew Turner
e7219c3818 Set mm before passing it to the UEFI firmware
When reading the UEFI memory map we pass in a pointer to the memory to
hold the map. Unfortunately it wasn't initialised before the first use
so clang decided it was undefined behaviour so the entire loop was
removed. This leads to everything in bi_load after this to also be
removed as dead code.

The next function after bi_load in the binary is efi_copy_init. The
above caused us to enter efi_copy_init with a return address of the
start of the function. Because of this it would enter an infinite
loop of calling the function, allocating memory, then returning to
the start of the function.

PR:		264021
(cherry picked from commit 0d6600b579)
2022-06-07 15:20:18 +01:00
Toomas Soome
8b796707e6 libsa: mark head_errlog feature supported.
head_errlog is new format for errlog, but we do not really
use errlog, so we can just mark it supported, to enable reading
from pool.

(cherry picked from commit 9cd45772a4)
2022-05-28 08:25:41 +03:00
Mark Johnston
abf56f145e libsa: Make the nvlist implementation more self-contained
Move declarations into a new nvlist.h rather than putting everything in
libzfs.h.  This makes this nvlist code easier to reuse elsewhere.  In
particular, the nvlist implementation in sys/contrib/libnv does not
provide XDR encoding, but this is needed when reading from or writing to
ZFS pools.

Also:
- Remove references to boolean_t.  It has to be a 32-bit int here, so
  just reference the underlying type.
- Add includes needed when compiling the nvlist code outside of stand/.

No functional change intended.

Reviewed by:	tsoome
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit e097436cb2)
2022-05-27 09:15:14 -04:00
Mark Johnston
f2206d2f94 libsa: Fix a bug in nvlist creation
When adding an entry to an nvlist, the data buffer might need to be
resized.  When this happens, the XDR encoder's notion of the buffer size
also needs to be updated, otherwise the operation may erroneously fail.

Reviewed by:	tsoome, imp
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit bcc3148c70)
2022-05-27 09:14:58 -04:00
John Baldwin
8d3f27908b stand/efi: Pass --no-dynamic-linker to ld.bfd >= 2.34.
ld.bfd in binutils 2.34+ now reports an error in more cases for custom
ldscripts that do not place PHDRs in a LOAD segment.  However, EFI
binaries are not dynamic binaries which need PHDRs, so pass
--no-dynamic-linker to disable this check.

Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D34124

(cherry picked from commit 8bd5e2f15c)
2022-05-10 17:06:26 -07:00
Ed Maste
5e017a8474 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

(cherry picked from commit cf8880d52b)
2022-05-03 14:20:44 -04:00
Kyle Evans
0c9c8a4c64 stand: zfs: handle holes at the tail end correctly
This mirrors dmu_read_impl(), zeroing out the tail end of the buffer and
clipping the read to what's contained by the block that exists.

This fixes an issue that arose during the 13.1 release process; in
13.1-RC1 and later, setting up GELI+ZFS will result in a failure to
boot.  The culprit is this, which causes us to fail to load geom_eli.ko
as there's a residual portion after the single datablk that should be
zeroed out.

PR:		263407
Reviewed by:	tsoome

(cherry picked from commit 914dc91d12)
2022-04-23 22:51:38 -05:00
Gordon Bergling
d685aeacce libsa: Fix a typo in a panic message
- s/occured/occurred/

(cherry picked from commit 746cc38ec3)
2022-04-23 08:56:02 +02:00
Kyle Evans
c85cf49294 loader: userboot: provide a getsecs() implementation
We don't need it for userboot, but it avoids issues with BIND_NOW, so
just provide it.  time(3) isn't defined but ends up being provided by
libc linked into the host process, which is generally fine.

PR:	262920
Reviewed by:	imp, jhb

(cherry picked from commit 660c1892d5)
2022-04-21 17:35:01 -05:00
Kyle Evans
4321608d3d stand: libefi: swap /Pci() printing around
Printing device followed by interface matches, e.g., edk2.  Note that
this is only a fallback, many firmware implementations will provide the
protocol that we'll use to format device paths.

Reviewed by:	imp, tsoome
Sponsored by:	Ampere Computing
Submitted by:	Klara, Inc.

(cherry picked from commit 454630c725)
2022-04-21 17:34:51 -05: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
Gordon Bergling
3edf9d9865 loader.4th(8): Fix a typo in the manual page
- s/commmand/command/

(cherry picked from commit ad49d7c54c)
2022-04-09 08:15:25 +02:00
Mateusz Piotrowski
1df2b7c954 loader.efi: Improve the manual page
- Add SPDX tag
- Add a files section describing different locations related to the
  loader
- Add an example explaining how to install a new loader.efi to ESP
- Reference uefi(8)

Reviewed by:	tsoome
Reviewed by:	Pau Amma <pauamma@gundo.com>
Reviewed by:	Jose Luis Duran <jlduran@gmail.com>
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D34592

(cherry picked from commit 9ecf6e0f9f)
2022-04-04 19:49:55 +02:00
Gordon Bergling
a3e3d3f856 stand: Fix a common typo in source code comments
- s/existance/existence/

(cherry picked from commit 9cd75b5588)
2022-04-02 15:33:19 +02:00
Mateusz Piotrowski
1af65c5009 gptboot.8: Fix a typo and fix lint warnings
MFC after:	3 days

(cherry picked from commit e405ae3097)
2022-03-22 23:26:33 +01:00
Toomas Soome
01f549e1c9 WITHOUT_BOOT build option appears to include stand, failing on libsa
building libsa needs to use -I${LDRSRC} for some files.

PR:		260083
Submitted by:	Ivan Rozhuk
Approved by:	re (gjb, early MFC)

(cherry picked from commit 9633c3d874)
2022-03-19 01:10:36 +02:00
Ed Maste
7d59a9451d 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

(cherry picked from commit e9249ef958)
2022-03-17 21:58:51 -04:00
Ed Maste
1dcb6002c5 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)
Relnotes:	yes
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D34512

(cherry picked from commit 425e57e7a2)
2022-03-17 21:58:01 -04:00
Colin Percival
dd6c1475a6 Add support for getting early entropy from UEFI
UEFI provides a protocol for accessing randomness. This is a good way
to gather early entropy, especially when there's no driver for the RNG
on the platform (as is the case on the Marvell Armada8k (MACCHIATObin)
for now).

If the entropy_efi_seed option is enabled in loader.conf (default: YES)
obtain 2048 bytes of entropy from UEFI and pass is to the kernel as a
"module" of name "efi_rng_seed" and type "boot_entropy_platform"; if
present, ingest it into the kernel RNG.

Submitted by:	Greg V
Reviewed by:	markm, kevans
Approved by:	csprng (markm)
Differential Revision:	https://reviews.freebsd.org/D20780
2022-03-10 18:11:41 -08:00
Katsuyuki Miyoshi
9cb5ea3dd2 lualoader: fix the autoboot_delay countdown message
When the timer drops from double to single digits, a spare 'e' is left
on the end of the line as we don't overwrite it. Include an extra space
at the end to account for this and overwrite the leftover character.

PR:		259429

(cherry picked from commit bb4c691299)
2022-03-09 15:21:54 -06:00
Leandro Lupori
ed726c3e34 powerpc64: fix loader regression
After b4cb3fe0e3, loader started crashing on PowerPC64, with a
Program Exception (700) error. The problem was that archsw was
used before being initialized, with the new mount feature. This
change fixes the issue by initializing archsw earlier, before
setting currdev, that triggers the mount.

Reviewed by:		tsoome
MFC after:		1 month
X-MFC-With:		b4cb3fe0e3
Sponsored by:		Instituto de Pesquisas Eldorado (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D32027

(cherry picked from commit 680ca73945)
2022-03-04 19:18:22 -03:00
Dimitry Andric
2152b27207 Disable clang 14 warning about bitwise operators in one more place
Follow up 5f2aca8394, where I missed the -Werror warning still being
emitted in libsa.

Fixes:		5f2aca8394
MFC after:	3 days

(cherry picked from commit 74f7afdfd2)
2022-02-11 17:42:46 +01: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
Marcin Wojtas
5b042fcbdf Disable PIE for powerpc bootloaders.
Bootloaders for powerpc are not built as position independent
code. Since bsd.prog.mk is used for building, when PIE is enabled,
the PIE flags are added and that causes the build to fail.
Adding MK_PIE=no stops bsd.prog.mk from adding PIE specific flags.

Submitted by: Dawid Gorecki <dgr@semihalf.com>
Reviewed by: emaste
Obtained from: Semihalf
Sponsored by: Stormshield
Differential Revision: https://reviews.freebsd.org/D28893

(cherry picked from commit 3aa023643e)
2022-01-23 11:09:53 +01:00
Marcin Wojtas
afd4a49407 Disable PIE for MIPS ubldr
When performing buildworld for MIPS with PIE enabled, the build fails
with "position-independent code requires '-mabicalls'" message.
-mno-abicalls and -fno-pic flags are explicitly set in MIPS ubldr
makefile, so to work around this problem, set MK_PIE=no for MIPS
ubldr.

Submitted by: Dawid Gorecki <dgr@semihalf.com>
Reviewed by: emaste
Obtained from: Semihalf
Sponsored by: Stormshield
Differential Revision: https://reviews.freebsd.org/D28370

(cherry picked from commit cd992885bc)
2022-01-23 11:09:53 +01:00
Marcin Wojtas
f79791ab60 Disable PIE for MIPS BERI boot loader
MIPS BERI boot loader is built with -mno-abicalls and -fno-pic
so prevent adding PIE-related build flags.

Fix build after 9a227a2fd6 ("Enable PIE by default on 64-bit architectures")

Obtained from: Semihalf
Sponsored by: Stormshield

(cherry picked from commit 19cd12a32a)
2022-01-23 11:09:52 +01:00
Emmanuel Vadot
b47fc941b0 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>

(cherry picked from commit b464c459ea)
2022-01-14 14:44:36 +01:00
Emmanuel Vadot
7f08e54f52 loader: Do not force comconsole for arm and arm64
This makes GOP not probed on some situation (AMD Card on PCIe slot
with EDK2 as we have a SERIAL_IO_PROTOCOL compatible uart).

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D32992
Sponsored by: Beckhoff Automation GmbH & Co. KG

(cherry picked from commit 123b5b8763)
2022-01-14 14:38:34 +01:00
Emmanuel Vadot
50af79ac2d loader: lsefi: Print more information
Printing the EFI_HANDLE pointer isn't very useful.
If the handle have a IMAGE_DEVICE_PATH or a DEVICE_PATH protocol print it.
This makes it easier to see which devices are present and what protocol they
expose.

Reviewed by:	imp, tsoome
Differential Revision:	https://reviews.freebsd.org/D32991
Sponsored by: Beckhoff Automation GmbH & Co. KG

(cherry picked from commit 2e0d67c3ed)
2022-01-14 14:38:25 +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
d37a33f52c loader: tftp: Copy the first block into the cache
tftp_open reads the first block so copy it in the cached data.
If we have more than one block (i.e. we called tftp_read before
tftp_preload) simply just reset the transfer.

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

(cherry picked from commit dfc9c1d493)
2022-01-13 08:59:03 +01:00
Emmanuel Vadot
28d2b8b700 loader: lua: test that /boot exists first
Otherwise on fs like tftp where no directory listing is possible we fail
on the .dir method.

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

(cherry picked from commit c4dc907254)
2022-01-13 08:58:54 +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
d852525555 loader: tftp: Add preload method
The preload method will transfer the whole file in a buffer and cache it
so read/lseek operations are faster.

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

(cherry picked from commit 3eb019000c)
2022-01-13 08:58:39 +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
4003cdd81b loader: ip: Do not call getsecs so much
getsecs is very costly, reuse the values we got before.

Fetching a ~30MB kernel with the tftp command use to take ~26 seconds
and now it's ~18 seconds.

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

(cherry picked from commit c5f24f5e0d)
2022-01-13 08:56:00 +01:00