Commit Graph

95 Commits

Author SHA1 Message Date
Warner Losh
1e13416bb9 Add GUID for UEFI boot manager variables.
Sponsoered by: Netflix
2018-01-12 15:30:52 +00:00
Konstantin Belousov
85f794e126 Skip IRELATIVE relocations when loader processes ELF files.
ifuncs can be only called in the (early boot) kernel environment, so
postpone resolving until early stage of the kernel boot.  This commit
is performed in advance to make loaders on most machines updated
before ifuncs appear in the kernels.

Reviewed by:	emaste, jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D13838
2018-01-11 13:57:30 +00:00
John Baldwin
349b6dad63 Use <stand.h> instead of <inttypes.h> and <stdio.h> in boot code.
In the freestanding boot compile environment, standard headers are not
available.  Curiously, only building with clang exposed this as compiles
with external GCC still succeeded.

Sponsored by:	DARPA / AFRL
2018-01-08 18:47:35 +00:00
John Baldwin
9bd8ae10e3 Fix printf missing format variables warnings.
Include the failing kernel file name for errors in beri_elf64_exec().

Sponsored by:	DARPA / AFRL
2018-01-08 18:46:10 +00:00
John Baldwin
9433594417 Define __dmadat after #include'ing ufsread.c.
The __dmadat variable is a statically allocated I/O buffer.  The type is
declared in the ufsread.c source file and clang warns if a variable is
defined before it's type is declared.

Sponsored by:	DARPA / AFRL
2018-01-08 18:44:36 +00:00
Warner Losh
388199e5bb Invent new #defines for the biospci_{read,write}_config function to
specify the width and use them everywhere.

Sponsored by: Netflix
2018-01-06 06:00:45 +00:00
Sean Bruno
cb1103025d Handle misconfigured/nonexistent pcidev for comconsole instead of BTX panic.
PR:		203319
Reviewed by:	imp jhb
MFC after:	2 weeks
Sponsored by:	Limelight Networks
Differential Revision:	https://reviews.freebsd.org/D13776
2018-01-05 23:50:50 +00:00
John Baldwin
48ccf80238 Use 'extern uint8_t' instead of 'extern void' for external symbols.
The beri boot loaders depend on symbols defined in linker scripts or
assembly files.  The boot loaders do not care about the type of these
symbols but just want to extract a pointer to them.  Older versions of
GCC permitted external symbols to be declared of type 'void' and then
'&foo' generated a void pointer to the memory at the symbol's address.
However, void objects are not valid C and newer versions of GCC error if
these are used.  Instead, declare these symbols as being bytes (or
an array of bytes in the cheri_sdcard_vaddr case).

Sponsored by:	DARPA / AFRL
2018-01-03 17:40:51 +00:00
John Baldwin
a9ca11cb39 Don't clobber system LDFLAGS for beri boot loaders.
Prior to r325114, bsd.init.mk was included after assignments to CFLAGS and
LDFLAGS in these Makefiles.  After r325114, bare assignments (= rather than
+=) lost system-assigned default values that are needed when compiling with
an external toolchain.  CFLAGS in both Makefiles already uses +=.  This
commit changes LDFLAGS to use +=.  While here, depend on the LDFLAGS update
in the parent Makefile.inc to set -nostdlib.

Sponsored by:	DARPA / AFRL
2018-01-03 17:35:38 +00:00
Ian Lepore
b6f4732cb3 Add a validbcd() routine that uses the bcd2bin_data[] array and returns a
bool indicating whether the input value represents a valid BCD byte.

The existing bcd2bin() routine will KASSERT if asked to convert a bad value,
but sometimes the kernel has to handle BCD data from untrusted sources, so
this will provide a mechanism to validate data before attempting conversion.

This would be have easier/cleaner if the bcd2bin_data[] array contained an
out-of-range value (such as 0xff) in the infill locations that aren't valid,
but it's a global symbol that might be referenced by out-of-tree code
relying on the current scheme, so I'm leaving that alone.
2017-12-31 22:43:24 +00:00
Kyle Evans
24888292cd stand/fdt: Make fdt_overlay_apply signature-compatible with libfdt
libfdt will assume a writable fdt overlay blob has been passed in, so make
ours compatible to allow easier review when we try to drop libfdt into
place. overlay from the calling context is writable, making it safe to
simply rip out everything related to copying the overlay blob in
fdt_overlay_apply.

I note here that we still have problems: fdt_overlay_apply, both our version
and libfdt's, may fail and have already clobbered the base fdt to some
extent. Future work will make sure we don't apply a potentially bogus fdt,
instead discarding the base fdt if we had an error.

Reviewed by:	gonzo
Differential Revision:	https://reviews.freebsd.org/D13695
2017-12-31 05:22:26 +00:00
Nathan Whitehorn
3159111ed6 Garbage-collect loader.ps3. It is currently disconnected from the build and
is superseded by either direct loading of the kernel by petitboot (soon to
become the installer default) or loader.kboot.
2017-12-30 20:27:13 +00:00
Kyle Evans
37cb59c8ac libsa: Pull in strnlen from libc
strnlen is not used at the moment, but it will be when libfdt gets updated.
Prepare for the not-so-distant future by pulling in strnlen.

Noticed because:	segfault in ld.bfd due to strnlen missing
2017-12-30 07:03:52 +00:00
Kyle Evans
d2084bf608 stand/fdt: Swap libfdt include order
libfdt.h should be included before fdt.h, as hinted at by all of libfdt/;
standard include order being libfdt.h, libfdt_env.h, fdt.h.

The current include order also causes problems when libfdt gets updated, as
fdt.h requires some definitions from libfdt.h.

Differential Revision:	https://reviews.freebsd.org/D13688
2017-12-30 06:53:27 +00:00
Warner Losh
8701bb8fae Fix ubldr. uboot/lib uses defines for the loader. It's part of the
loader, but not compile as loader (it's building a library), so we
can't just include loader.mk for the defines. Move LOADER_DISK_SUPPORT
back to defs.mk for the moment.

Sponsored by: Netflix
2017-12-29 18:08:35 +00:00
Kyle Evans
06d6750e0d stand/fdt: Consistently apply fdt_overlays
Overlays were previously not applied when U-Boot provides FDT or EFI
provides FDT, only when we load FDT from /boot/dtb given name from U-Boot.

Make all three paths lead to loading fdt_overlays and applying them, so that
fdt_overlays can be expected to Just Work.

Reviewed by:	gonzo, imp, manu
Differential Revision:	https://reviews.freebsd.org/D13664
2017-12-29 18:08:30 +00:00
Kyle Evans
5c0700f692 stand/fdt: Avoid bailout when dtbo has no fixups
In the case of a simple dtbo where fragment uses target-path and the overlay
contains no references, /__fixups__ will not be included by either our dtc
or dtc from ports, but the file still has valid fragments to be applied.

Additional testing found that /__symbols__ might also be omitted if it's
empty, which is not necessarily an error.

Reviewed by:	gonzo, imp
Differential Revision:	https://reviews.freebsd.org/D13663
2017-12-28 21:12:27 +00:00
Kyle Evans
a609d03b04 stand/fdt: Fix loading of multiple fdt_overlays
fdt_load_dtb_overlays was written to unload previous overlay when a new
valid one is come across. fdt_apply_overlays further down is written to
iterate over all .dtbo's currently loaded and apply them one-by-one. Correct
fdt_load_dtb_overlays to stop dropping valid overlays that were previously
loaded and match expectations.

Reviewed by:	gonzo, imp
Differential Revision:	https://reviews.freebsd.org/D13659
2017-12-28 21:09:36 +00:00
Michael Zhilin
5e6e2d38c1 [boot/efi] scan all display modes rather than sequential try-fail way
This patch allows to scan all display modes in boot1 as loader does.

Before system tried to select optimal display mode by sequential scan of
modes and if error then stop scanning. This way is not good, because
if mode N is not present, mode N+1 may exist.

In loader we use conout->Mode->MaxMode to identify maximum number of modes.
This commit is to use same way in boot1 as in loader.

Reported by:	Andrey Pustovetov <andrey.pustovetov@gmail.com>
Reviewed by:	tsoome
Differential Revision:	https://reviews.freebsd.org/D13541
2017-12-21 12:21:35 +00:00
Warner Losh
fc1340fb40 No need to use relative paths like this here.
Sponsored by: Netflix
2017-12-19 04:06:07 +00:00
Warner Losh
ca481bffc2 Hoist btx include stuff to i386/Makefile.inc
Sponsored by: Netflix
2017-12-19 04:06:02 +00:00
Warner Losh
6bc860372d Interact is always called with NULL. Simplify code a little by
removing this argument, and expanding when rc is NULL. This
effectively completes the back out of custom scripts for tftp booted
loaders from r269153 that was started in r292344 with the new path
tricks that obsoleted it.

Submitted by: Netflix
2017-12-19 04:05:55 +00:00
Warner Losh
0ff3f28b2d Simplify things a little. The RETURN macro isn't required. It's only
used once, inside an #ifdef where it would be defined to be return.

Sponsored by: Netflix
2017-12-19 04:05:43 +00:00
Warner Losh
76a8f5b0be libficl is only ever used in a loader (never a boot) program. Move it
to loader.mk.

Sponsored by: Netflix
2017-12-18 04:51:45 +00:00
Warner Losh
25c2f4cb95 Move loader help file definitions to being 100% inside of loader.mk.
HELP_FILES is a loader only thing, so move it to loader.mk. Only
generate the help file if HELP_FILES is defined. Adjust Makefiles to
new convention. Fix a few cases where ${.CURDIR}/ was missing
resulting in missing bits from the help files.

Sponsored by: Netflix
2017-12-18 04:51:34 +00:00
Warner Losh
4927bbce9d Move loader-only defines to loader.mk from defs.mk
Produces the same .o's, verified with md5.

Sponsored by: Netflix
2017-12-16 21:33:21 +00:00
Warner Losh
6562843997 Remove the 'mini libstand in libstand' that util.[ch] provided. These
weren't needed, and their existance interfered with things in subtle
ways. One of these subtle ways was that malloc could be different
based on what files were included when (even within the same .c file,
it turns out). Move to a single malloc implementation as well by
adding the calls to setheap() to gptboot.c and zfsboot.c. Once upon a
time, these boot loaders strove to not use libstand. However, with the
proliferation of features, that striving is too hard for too little
gain and lead to stupid mistakes.

This fixes the GELI-enabled (but not even using) boot environment. The
geli routines were calling libstand malloc but zfsboot.c and gptboot.c
were using the mini libstand malloc, so this failed when we tried to
probe for GELI partitions. Subtle changes in build order when moving
to self-contained stand build in r326593 toggled what it used from one
type to another due to odd nesting of the zfs implementation code that
differed subtly between zfsloader and zfsboot.

Sponsored by: Netflix
2017-12-15 23:16:53 +00:00
Warner Losh
9a7c084993 Panic in sbrk if setheap hasn't been called yet. This is preferable to
a mysterious crash.

Sponsored by: Netflix
2017-12-15 23:16:47 +00:00
Warner Losh
65b8a300df Revert r326855: Cargo cut a fix for the regressions r326585 caused.
This was an experiment that landed in the wrong branch and was pushed
accidentally. It's best if it is ignored because the difference was
due to vers.o being different, not float.o... And it was confirmed to
not fix anything...

Pointy Hat to: imp
2017-12-14 18:57:17 +00:00
Warner Losh
86375a7ea9 Turn loader GELI support in the boot loaders off by default as a
temporary workaround. This fixes zfs booting generally, but breaks all
GELI booting by default. Add note to UPDATING to this effect. When the
GELI issues are resolved, this will be reverted.
2017-12-14 17:00:24 +00:00
Warner Losh
bcee07a1af Fix comments after bump in size. 2017-12-14 16:51:43 +00:00
Warner Losh
108bcd504e Cargo cut a fix for the regressions r326585 caused.
We need to include ficl.h after the standard includes, rather than
before them. It changes the generated code in ways that haven't been
completely analyized. This restores the old code generation (as
verified by md5 changing back for zfsloader).

This should restore GPT + ZFS and GPT + ZFS + GELI booting that was
broken in r326585 (or would have been if r326584 hadn't broken the
build).

Sponsored by: Netflix
2017-12-14 16:51:26 +00:00
Toomas Soome
9f9b430b19 libefi: make efichar.h more usable in stand code
Use _STANDALONE for guard expression in efichar.[ch] and add efi_char typedef.
clean up boot1.c, and replace for loop in efipart.c with ucs2len().

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D13488
2017-12-14 16:41:52 +00:00
Warner Losh
ba25195ebf Revert r326792, r326784, r326772, r326712
Something subtle is creating problems for disk access on ubldr. Back
it out unti that can be sorted out.

Sponsored by: Netflix
2017-12-12 22:06:22 +00:00
Antoine Brodin
435680d2d8 Attempt to unbreak buildworld 2017-12-12 09:46:53 +00:00
Warner Losh
2ccd1dd900 Revert part of 362772. It was causing problems for includes and making
the menus disappear.

Sponsored by: Netflix
2017-12-11 23:15:43 +00:00
Warner Losh
c83457486b Fix regression with lua import
Don't print when we can't find a file. Copy it instead to the error
buffer. Higher level routines determine if it's appropriate to print
the error message.

Also, remove dead code (labeled bogusly lost functionality) since we
never used that functionality. Remove unused arg from interact() too.

Sponsored by: Netflix
2017-12-11 16:18:05 +00:00
Warner Losh
5ba722fe30 Fix a comment to be more accurate 2017-12-11 14:47:23 +00:00
Ian Lepore
5fa28b3d97 When building for arm arches, set PKGALIGN to the max cache line size
supported by the arch, to meet u-boot's requirement that I/O be done
in cache-aligned chunks.

PR:		223977
2017-12-10 23:06:45 +00:00
Ian Lepore
12b92a343c Save and restore r9 register in arm ubldr. In old gcc 4.2, r9 was a callee-
saved register, but in arm EABI it may be either callee-saved or dedicated
to some special purpose (such as a TLS pointer).  It appears clang does not
treat it as a callee-saved register (instead using it as another work
register, similar to r12).

Another important side effect of these changes is that saving an extra
register in the push/pop statements keeps the stack aligned to an 8-byte
boundary during the self_reloc() call, as it always should have been.

As stated in the PR...

Essentially the important caller-saved registers are pushed (r0, r1, r9, lr)
before the relocation call, and popped after.  Then r8/r9 are saved as usual
for the syscall trampoline, and lr is stored in r8 (now free) as a
callee-saved value before calling into `main`.

The call to `main` can no longer be a tail call because we must restore r9
especially after main returns (although since we have used r8 to hold lr we
must also restore this).

PR:		224008
2017-12-10 21:51:27 +00:00
Warner Losh
29374678a6 This path belongs in ficl/Makefile, not the common defines for users
of ficl.

Sponsored by: Netflix
2017-12-08 22:19:41 +00:00
Warner Losh
f0408ed054 boot1.c needs EFI_ZFS_BOOT too, so add it globally. Otherwise we'll
not be able to actually read ZFS partitions.

Submitted by: kevans@
2017-12-08 19:57:26 +00:00
Warner Losh
fb5af39a82 Create interp class.
Create an interp class. Use it to separate out the different types of
interpreters: forth and simple with function pointers rather than
via #ifdefs.

Obtained from: lua boot loader project
    (via https://bsdimp@github.com/bsdimp/freebsd.git lua-bootloader)
Sponsored by: Netflix
2017-12-08 19:57:16 +00:00
Warner Losh
bd04a914bc Const poison a couple of interfaces.
Obtained from: lua boot project
Sponsored by: Netflix
2017-12-08 19:57:11 +00:00
Warner Losh
c5095910a0 Put the files we're copying over into a few variables and add them to
CLEANDIRS and CLEANFILES so make clean removes any divots.

Sponsored by: Netflix
2017-12-08 19:57:06 +00:00
Warner Losh
6856cf6893 Provide implementations for iscntrl, ispunct and isgraph.
Sponsored by: Netflix
2017-12-08 19:57:02 +00:00
Warner Losh
c008ab0879 Remove _KERNEL hack now that errno.h does the right thing when
_STANDALONE is defined.

Sponsored By: Netflix
2017-12-08 19:56:57 +00:00
Warner Losh
49cb01302c Add partial support signal.h functioanlity. Pull in machine/signal.h
to define sig_atomic_t.

Sponsored by: Netflix
2017-12-08 19:56:35 +00:00
Mark Johnston
2dbeaed483 Avoid setting -Wno-tentative-definition-incomplete-type with gcc.
No version of gcc that I've tried accepts this flag.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D13415
2017-12-07 22:11:23 +00:00
Toomas Soome
78fdf7f396 dhcp_try_rfc1048() is not used any more
Remove unused function.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D13382
2017-12-06 06:49:53 +00:00