Create a small wrapper around the new flua hash module so we can use it
here too. There's no 4th bindings, nor will they be created.
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D43874
Now that we draw in the gfx bindings for all our interpreters only when
graphics support is compiled in, we can eliminate this from all the
loaders that don't have graphics support.
Sponsored by: Netflix
Reviewed by: kevans, jhb
Differential Revision: https://reviews.freebsd.org/D43905
host_syscalls.c: I've written, so put Netflix copyright on. It's
possible in the confusion that Nathan wrote the host_gettimeofday
implementation.
syscall_nr: These files likely can't enjoy copyright protection since
they are just facts (the per-arch Linux system calls), so add a note
they are in the public domain.
Sponsored by: Netflix
According to git blame I've 95%+ rewritten this file. Update copyright to
reflect that, but give nod to Nathan for the original I started with.
Sponsored by: Netflix
For aarch64 and amd64, we don't pull in anything from libkern, so we
don't need it in our path. However, powerpc needs ucmpdi2 from libkern,
so bring it into libkboot's build and omit it from loader.kboot.
Sponsored by: Netflix
Move the startup code from kboot/kboot to kboot/libkboot and add the
necessary infrastructure for it to build. move start_arch.h, a private
header for libkboot, over as well.
Sponsored by: Netflix
In anticipation of separating the library elements from the kboot
prorgam elements, move kboot down a level into a subdirectory. There
will be libkboot and include directories in subsequent commits,
mirroring other subsystems like i386 and efi.
Sponsored by: Netflix
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.
Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/
Sponsored by: Netflix
Preemptively address a collision with LIBFDT (to be added in the future)
from src.libnames.mk, which gets included via bsd.progs.mk. No
functional change intended.
Reviewed by: imp
MFC after: 1 week
Sponsored by: Innovate UK
Differential Revision: https://reviews.freebsd.org/D42486
Add support for getting smbios from /sys/firmware/efi/systab, if
any. Add ptov mapping that uses mmap on /dev/mem to do the mapping with
64k pages (usually we only need 1 or two mappings).
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D39792
Fix an off-by-one error that would mean we'd get stuck on the newline if
ACPI= wasn't first.
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D39817
There's plenty of stack in kboot, so use it here rather than the
malloc/free dance.
Sponsored by: Netflix
Reviewed by: tsoome, kevans
Differential Revision: https://reviews.freebsd.org/D39416
If there's a kboot.conf, prase it after the command line args are
parsed. It's not always easy to get all the right command line args
depending on the environment. Allow an escape hatch. While we can't do
everything one might like in this file, we can do enough.
Sponsored by: Netflix
We were assuming that hostdisk_override was both a directory and a
file, which is not going to work very well. It's supposed to be a
single file, so recode it as such. Simplify erorr handling a little as
well and fix a return type-mismatch that doesn't matter for the
generated code (return NULL is the same as return false in this
context)
Sponsored by: Netflix
MIN works for any type, while min() is only for integers. So we were
rounding down to 0 since that's the size of 4GB truncated to an int.
Sponsored by: Netflix
When we're running on a FreeBSD host, we can't open /proc/iomem. So,
for now, just assume that we have 32GB of ram starting at 4GB.
Sponsored by: Netflix
Address two issues with current help file logic:
The existing condition prevents the common help file from being
installed when there are no additional help files defined. This results
in no loader.help on EFI platforms, for example.
Second, due to the fact that we build and install multiple loader types,
each successive install will clobber the previous loader.help. The
result is that we could lose type-specific commands, or possibly list
them in loaders that do not have such commands.
Instead, give each loader type a uniquely named help file. The EFI
loader will look for /boot/loader.help.efi, userboot will look for
/boot/loader.help.userboot, etc. The interpreter variant has no effect
on which help file is loaded.
This leaves the old /boot/loader.help unused.
Some credit for the final approach goes to Mathieu <sigsys@gmail.com>
for their version of the fix in https://reviews.freebsd.org/D22951.
PR: 267134
Reported by: Daniel O'Connor <darius@dons.net.au>
Reviewed by: imp
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D28591
Keep track of how much is used in the segment as we allocate it to the
application. Set memsz to 0 first, and increment it as used. Adjust the
bufsz before we call kexec so the kernel copies the right amount (it's
an error for bufsz to be bigger than memsz, so we set them == when we
retrieve the segment). Make sure we round to the page size, otherwise
kexec_load gets cranky.
Sponsored by: Netflix
Reviewed by: tsoome
Differential Revision: https://reviews.freebsd.org/D38315
Allocate a huge segment for the first kexec_load segments. We limit the
lessor of:
allocation to the size of the remaining memory segment
45% of available memory
95% of the memory we can allocate
This allows us to have really large RAM disks. We likely need to limit
this to the amount we actually used, though, since this can be a lot of
memory.
We have to do this complicated calculation for a few reasons: First, we
need 2 copies of the loaded kernel in the memory: The kernel can copy
everything to a temporary buffer. Next, malloc (via mmap) is limited to
a certain amount due to over commit, so we have to not allocate all we
can (only most of what we can).
Sponsored by: Netflix
Reviewed by: tsoome
Differential Revision: https://reviews.freebsd.org/D38314
kboot_get_phys_load_segment is defined in kboot.h, so remove them from
the .c files.
Sponsored by: Netflix
Reviewed by: tsoome
Differential Revision: https://reviews.freebsd.org/D38310
Try to open /dev/mem to read in the UEFI memory map. If we can't, then
we'll read it in the trampoline.
Retain reading in /proc/iomem to find reserved areas in Linux. We need
to know them for good places to put the kernel. These are not reflected
in the UEFI memory map. However, we should not adjust the UEFI memory
map since these reserved areas of the Linux kernel are free to be used
once we enter the kexec trampoline...
Sponsored by: Netflix
Reviewed by: tsoome, kevans, andrew
Differential Revision: https://reviews.freebsd.org/D38264
There's no need for an arch pointer to get segments. We can call the
routine directly since we don't need this code to be called from
different context where a pointer is needed.
Sponsored by: Netflix
Reviewed by: kevans, andrew
Differential Revision: https://reviews.freebsd.org/D38266
A number of bug fixes to loading kernels and modules on aarch64 and amd64.
Fix offset calcuations.
Add a number of debugs, commented out for now (will GC them in the future)
With this, and the MD aarch64 commands, we can linux boot in qemu and on
real hardware.
Sponsored by: Netflix
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D38261
Copy more of the necessary state for FreeBSD to boot:
o Copy EFI memory tables
o Create custom page tables needed for the kernel to find itself
o Simplify the passing of args to the trampoline by putting them
on the stack rather than in dedicated memory.
This is only partially successful... we get only part way through the
amd64 startup code before dying. However, it's much further than before
the changes.
Sponsored by: Netflix
Reviewed by: tsoome, kevans
Differential Revision: https://reviews.freebsd.org/D38259
Update exec.c (copyied from efi/loader/arch/arm64/exec.c) to allow
execution of aarch64 kernels. This includes a new trampoline code that
handles copying the UEFI memory map, if available from the Linux FDT
provided PA. This is a complete implementation now, able to boot from
the LinuxBoot environment on an aarch64 server that only offers
LinuxBoot (though a workaround for the gicv3 inability to re-init is not
yet in FreeBSD). Many 'fit and finish' issues will be addressed in
subsequent commits.
Sponsored by: Netflix
Reviewed by: tsoome, kevans, andrew
Differential Revision: https://reviews.freebsd.org/D38258
Connect efi's bootinfo.c to the kboot build, and adjust to use
the kboot specific routines.
The getrootmount() call is independent of EFI. Remove ifdefs so it's
called for kboot too.
The differences between the kboot and efi bootinfo.c files are now tiny.
This could use some more refactoring, but this is a working checkpoint.
Sponsored by: Netflix
Reviewed by: tsoome
Differential Revision: https://reviews.freebsd.org/D38350
Since aarch64 is different, it needs a different smap. We first see if
we have the PA of the table from the FDT info. If so, we copy that and
quit. Otherwise, we do the best we can in translating the /proc/iomap
into EFI Memory Table format.
We also send the system table to the kernel.
Sponsored by: Netflix
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D38255
Copy the EFI memory tables we were able to get into the MODINFOMD_SMAP
metadata area for the kernel.
Sponsored by: Netflix
Reviewed by: tsoome, kevans
Differential Revision: https://reviews.freebsd.org/D38254
It's just a stub, since the kernel learns of memory via FDT.
Sponsored by: Netflix
Reviewed by: tsoome, kevans
Differential Revision: https://reviews.freebsd.org/D38253
Each architecture will soon be required to provide this to load memory
maps as metadata for the platforms that require it (or a stub function
for those that don't).
Sponsored by: Netflix
Reviewed by: tsoome, kevans
Differential Revision: https://reviews.freebsd.org/D38252
Now that all architectures provide this, enumerate the platform's memory
before we go to interact(). This needs to be done only once, but relies
on our ability to open host: files on some platforms, so it needs to be
done after devinit().
Sponsored by: Netflix
Reviewed by: tsoome, kevans
Differential Revision: https://reviews.freebsd.org/D38251
Move memory enumeration to the enumerate_memory_arch(), tweak the code a
bit to make that fit into that framework.
Also fix a bug in the name of the end location. The old code never found
memory (though amd64 doesn't yet work, this lead to using fallback
addresses that were good enough for QEMU...).
Sponsored by: Netflix
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D38250
We have an odd situation with aarch64 memory enumeration. The fdt that
we can get has a PA of the UEFI memory map, as modified by the current
running Linux kernel so it can retain those pages it needs for EFI and
other services. We have to pass in this EFI tablem but don't have access
to it in the boot loader. We do in the trampoline code, so a forthcoming
commit will copy it there for the kernel to use. All for want of /dev/mem
in the target environment sometimes.
However, we also have to find a place to load the kernel, so we have to
fallback to /proc/iomem when we can't read the UEFI memory map directly
from /dev/mem. It will give us good enough results to do this task. This
table isn't quite suitable to be converted to the EFI table, so we use
both methods. We'll fall back to this method also if there's no EFI
table advertised in the fdt. There's no /sys file on aarch64 that has
this information, hence using the old-style /proc/iomem. We're unlikely
to work if there's no EFI, though.
Note: The underlying Linux mechanism is different than the amd64 method
which seems like it should be MI, but unimplemented on aarch64.
Sponsored by: Netflix
Discussed with: kevans
Differential Revision: https://reviews.freebsd.org/D38249
Add stub for new MI interface for enumerating memory. Right now powerpc
looks in the FDT table at a later point in boot since we don't need to
pass a specific memory table to the kernel. Leave it like that for now,
but note plans for the future.
Sponsored by: Netflix
Reviewed by: kevans
Differential Revision: https://reviews.freebsd.org/D38248
We'll be using this code for most / all of the platforms since iomem is
the only interface that can tell us of the reserved to the linux kernel
areas that we cannot place the new kernel into, but that we are free to
use once we hit trampoline. aarch64 will use this shortly, and similar
code in amd64 will be refactored when I make that platform work.
Sponsored by: Netflix
Reviewed by: tsoome
Differential Revision: https://reviews.freebsd.org/D38309