Commit Graph

1316 Commits

Author SHA1 Message Date
Ed Maste
bf4a70bb40 libc: Use musl's optimized strchr and strchrnul
Parentheses added to HASZERO macro to avoid a GCC warning, and formatted
with clang-format as we have adopted these and don't consider them
'contrib' code.

Obtained from:	musl (snapshot at commit 4d0a82170a25)
Reviewed by:	kib (libc integration), mjg (both earlier)
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D17630

(cherry picked from commit 7f72497ef7)
2021-12-12 17:32:33 -05:00
Alfonso
85ba40da4c ANSIify libsa functions
Convert libsa files to use ANSI function definitions.

Pull request: https://github.com/freebsd/freebsd-src/pull/508
[ cut and paste error corrected ]

(cherry picked from commit 1f629966d6)
2021-12-06 08:55:54 -07:00
Gordon Bergling
179e795f0d ficl: Fix a typo in a comment
- s/segement/segment/

(cherry picked from commit 54c1a65736)
2021-12-03 16:53:00 +01:00
Gordon Bergling
0729442a85 efi(8): Fix a typo in a source code comment
- s/writting/writing/

(cherry picked from commit 2b0f6ad444)
2021-11-11 17:26:43 +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
John Baldwin
de705beeef crypto: Permit variable-sized IVs for ciphers with a reinit hook.
Add a 'len' argument to the reinit hook in 'struct enc_xform' to
permit support for AEAD ciphers such as AES-CCM and Chacha20-Poly1305
which support different nonce lengths.

Reviewed by:	markj
Sponsored by:	Chelsio Communications, The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32105

(cherry picked from commit 1833d6042c)
(cherry picked from commit d586c978b9)
2021-10-21 13:47:58 -07: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
Konstantin Belousov
caaf4ae21e amd64 UEFI loader: enable automatic disable of staging area copying
(cherry picked from commit 6032b6ba95)
2021-10-01 03:32:24 +03:00
Leandro Lupori
cc8e726c85 powerpc64: change CAS to support Radix MMU
Use radix_mmu environment variable to select between Hash or Radix
MMU, when performing the CAS method call. This matches kernel's
behavior, by selecting Hash MMU by default and Radix if radix_mmu
is not zero, to make sure that both loader and kernel always select
the same MMU.

The device tree is queried to detect Radix/GTSE support and to
find out if CAS is supported, making the old CPU version and HV
bit checks unnecessary now.

Reviewed by:		jhibbits
Sponsored by:		Instituto de Pesquisas Eldorado (eldorado.org.br)
Differential Revision:	https://reviews.freebsd.org/D31951

(cherry picked from commit a58abcde2c)
2021-09-30 08:34:16 -03:00
Mark Johnston
bd4fbd4e14 efi loader: Typo
(cherry picked from commit 0e3ce6d082)
2021-09-24 09:00:56 -04:00
Dimitry Andric
6d8f2277de 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.

(cherry picked from commit c90cab0d66)
2021-09-15 12:28:44 +02:00
Warner Losh
c5d7cc4fb4 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

(cherry picked from commit 879675e9a0)
2021-09-12 09:56:17 -06:00
Warner Losh
6c8ad124a2 cli.lua.8: make the command match the code
It's disable-device, not device-disable

Spotted by:		jrtc27
Sponsored by:		Netflix

(cherry picked from commit 6b51baf6a8)
2021-09-12 09:56:15 -06:00
Warner Losh
25b4b24edf 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

(cherry picked from commit 07c4b78d0a)
2021-09-12 09:56:15 -06:00
John Hood
3a4b9e30d4 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

(cherry picked from commit dbdf2b52f5)
2021-09-12 09:56:15 -06:00
Kyle Evans
8df27f0ace 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.

(cherry picked from commit ed107537b4)
2021-09-12 00:34:28 -05:00
Kyle Evans
0c675cb9c9 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.

(cherry picked from commit e19d9a9b6e)
2021-09-12 00:34:28 -05:00
Kyle Evans
b359fcb1cb lualoader: remove shadowed local from graphics:drawitem()
for loop vars are local already and distinct from this earlier
declaration; remove it.

(cherry picked from commit 763bcebe0b)
2021-09-12 00:34:28 -05: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
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