path: root/stand
Commit message (Collapse)AuthorAgeFilesLines
* amd64 loader: Use efiserialio for Hyper-V booted systemsWei Hu10 days5-7/+68
| | | | | | | | | | | | | | | | | | | | | | | UEFI provides ConIn/ConOut handles for consoles that it supports, which include the text-video and serial ports. When the serial port is available, use the UEFI driver instead of direct io-port accesses to avoid conflicts between the firmware and direct hardware access, as happens on Hyper-V (Azure) setups. This change enables efiserialio to be built for efi-amd64 and has higher order priority vs comconsole, and only uses efiserialio if the hypervisor is Hyper-V. When efiserialio successfully probes, it will set efi_comconsole_avail=true which will prevent comconsole from probing in this setup. Tested on Hyper-V, ESXi and Azure VMs. PR: 264267 Reviewed by: kevans, whu Tested by: whu Obtained from: Rubicon Communications, LLC (Netgate) MFC after: 2 weeks Sponsored by: Rubicon Communications, LLC (Netgate)
* loader: Add support for booting from a ZFS snapshotAllan Jude13 days1-2/+54
| | | | | | | | | | | | | | When booting from a snapshot we need to follow a different code path to turn the objset ID into the name, and for forward lookups we need to walk the parent's snapnames_zap. With this, it is possible to set the pools BOOTFS property to a snapshot and boot with a read-only filesystem of that snapshot. Reviewed by: tsoome, rew, imp Sponsored By: Beckhoff Automation GmbH & Co. KG Sponsored By: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D38600
* Parse /kboot.confWarner Losh14 days1-0/+27
| | | | | | | | | 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
* length for the 64-bit entry is 32-bits, not 16-bits.John-Mark Gurney2023-03-031-1/+1
| | | | Reported by: Jérôme Duval (korli on github)
* kboot: Fix hostdisk_overrideWarner Losh2023-03-021-23/+12
| | | | | | | | | | | 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
* kboot: Use MIN instead of minWarner Losh2023-03-021-3/+4
| | | | | | | 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
* kboot: Better default boot deviceWarner Losh2023-03-021-6/+7
| | | | | | Provide a better message when we can't find a boot device. Sponsored by: Netflix
* kboot: Hack for running on FreeBSD hostWarner Losh2023-03-022-0/+8
| | | | | | | 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
* stand: Minor cleanupAlfonso2023-02-273-24/+27
| | | | | | | | | | Replace a cast '0' for a null pointers with NULL Replace a 'goto loop' with a do-while loop in ufs and ext2fs. Cast cp pointer to uintptr_t to test to see if it's aligned rather than long. [ minor tweaks based on my & hps' review, reworded commit message ] Reviewed by: imp, hps Pull Request: https://github.com/freebsd/freebsd-src/pull/547
* stand: fix buffer overflow in getrootmount()Robert Wing2023-02-251-4/+5
| | | | | | | Reviewed by: imp, allanjude Sponsored By: Beckhoff Automation GmbH & Co. KG Sponsored By: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D38734
* stand: fix build userboot without zfsMichael Paepcke2023-02-252-1/+5
| | | | | | | | | Fix regression in building userboot -DWITHOUT_LOADER_ZFS Fixes: e307eb94ae520 MFC After: 3 days Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/665
* Support SMBIOS v3 for 64-bit entry systemsJohn-Mark Gurney2023-02-222-9/+48
| | | | | | | | | | | | Summary: Under QEMU on arm64 systems, the smbios table is above 4GB requiring a 64-bit address to access. Reviewers: manu Subscribers: imp, bcran, dab Differential Revision: https://reviews.freebsd.org/D38721
* lua: Export loaded modules env vars via environmentWarner Losh2023-02-091-0/+7
| | | | | | | | | | To make auditing and debugging easier, export foo_load=XXX foo_name=yyy etc to the loader env that we export to the kernel. Original by: dhw Sponsored by: Netflix Discussed with: kevans Differential Revsion: https://reviews.freebsd.org/D38466
* lua: Update to 5.4.4Warner Losh2023-02-082-1/+73
| | | | | | | | | | | | | | | Merge commit '755d9301ca89f02956fd17858b9d4d821ab5c972' from the vendor branch. This updates us from lua 5.4.2 to 5.4.4. In addition, it switches around how we flavor liblua for the boot loader and flua. This is done to reduce diffs with upstream and make it easier to import new versions (the current method has too many conflicts to resolve by hand): we include luaconf.local.h from luaconf.h (the only change to this file is now that #include at the end). We then define what we need to: for flua (which does very little) and one for stand (which creates the new FLOAT type out of int64). Sponsored by: Netflix
* Skip EFI framebuffer information if there is noneSimon J. Gerraty2023-02-061-9/+12
| | | | | | | Avoid several lines of useless info if there is no EFI framebuffer Reviewed by: stevek, imp Differential Revision: https://reviews.freebsd.org/D38393
* loader.efi: include help.fdt for FDT-enabled loaderMitchell Horne2023-02-031-0/+1
* loader: always install help filesMitchell Horne2023-02-038-8/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* kboot: Keep track of what's used in the segmentWarner Losh2023-02-031-10/+19
| | | | | | | | | | | | | 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
* kboot: Allocate a really big first segmentWarner Losh2023-02-031-3/+16
| | | | | | | | | | | | | | | | | | | | | | 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: Remove externsWarner Losh2023-02-032-4/+0
| | | | | | | | | 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
* kboot: Try to read UEFI memory from physical memory on aarch64Warner Losh2023-02-031-7/+44
| | | | | | | | | | | | | | | 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
* kboot: Don't need an arch pointer to get segmentsWarner Losh2023-02-036-15/+8
| | | | | | | | | | 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
* kboot: MI fixups to enable aarch64 bootingWarner Losh2023-02-031-8/+25
| | | | | | | | | | | | | 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
* kboot: Improve amd64 bootingWarner Losh2023-02-032-110/+262
| | | | | | | | | | | | | | | | 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
* kboot: aarch64 trampoline implementationWarner Losh2023-02-032-55/+199
| | | | | | | | | | | | | | | 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
* stand: share bootinfo.c between EFI and KBOOTWarner Losh2023-02-033-469/+8
| | | | | | | | | | | | | | | 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
* kboot: aarch64 bi_loadsmapWarner Losh2023-02-031-0/+19
| | | | | | | | | | | | | 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
* kboot: bi_loadsmap for amd64Warner Losh2023-02-031-0/+19
| | | | | | | | | 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
* kboot: Powerpc provide bi_loadsmapWarner Losh2023-02-031-0/+6
| | | | | | | | 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
* kboot: Define bi_loadsmap for loading memory mapsWarner Losh2023-02-031-0/+2
| | | | | | | | | | 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
* kboot: Call enumerate_memory_arch()Warner Losh2023-02-031-0/+1
| | | | | | | | | | | 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
* kboot: Update amd64 to use enumerate_memory_arch()Warner Losh2023-02-031-20/+20
| | | | | | | | | | | | | 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
* kboot: aarch64 memory enumeration enumerate_memory_arch()Warner Losh2023-02-031-0/+154
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* kboot: Add powerpc stub for enumerate_memory_arch()Warner Losh2023-02-032-1/+12
| | | | | | | | | | | 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
* kboot: space_avail -- how much space exists from 'start' to end of segmentWarner Losh2023-02-032-0/+20
| | | | | | Sponsored by: Netflix Reviewed by: tsoome Differential Revision: https://reviews.freebsd.org/D38313
* kboot: Add parsing of /proc/iomem into seg.cWarner Losh2023-02-032-0/+151
| | | | | | | | | | | | 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
* kboot: Create segment handling code at main levelWarner Losh2023-02-033-0/+206
| | | | | | | | | | | | Create segment handling code up to the top level. Move it all into seg.c, and make necessary adjustments for it being in a new file, including inventing print_avail() and first_avail() to print the array and find the first large enough memory hole. aarch64 will use this, and I'll refactor the other platforms to use it as I make them work. Sponsored by: Netflix Discussed with: kevans Differential Revision: https://reviews.freebsd.org/D38308
* kboot: MI part of the memory enumeration codeWarner Losh2023-02-031-0/+9
| | | | | | | | | | enumerate_memory_arch is called once early in kboot's startup to allow us to discover the memory layout, reserved areas, etc of the system memory. Add the MI interface part of this. Sponsored by: Netflix Reviewed by: tsoome, kevans Differential Revision: https://reviews.freebsd.org/D38247
* kboot: Add aarch64 fdt fixupWarner Losh2023-02-032-1/+15
| | | | | | Sponsored by: Netflix Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D38256
* kboot: Probe all disks and partitions for a kernelWarner Losh2023-02-033-14/+58
| | | | | | | | | | | Guess where to boot from when bootdev= isn't on the command line or other config. Search all the disks and partitions for one that looks like it could be a boot partition (same as we do when probing zpools). Return the first one we find. Sponsored by: Netflix Reviewed by: tsoome Differential Revision: https://reviews.freebsd.org/D38319
* efiserialio: use port settings (sio->Mode) for initial setupToomas Soome2023-02-031-16/+22
| | | | | | | | | | Use serial port setup done by system firmware. ARM64 Hyper-V does hung if we attempt to override the defaults, therefore we should default to use settings from firmware. Tested by: schakrabarti@microsoft.com PR: 266248 MFC after: 1 week
* kboot: Remove kboot_loadaddrWarner Losh2023-02-021-14/+0
| | | | | | | | | | Turns out that the loadaddr interface is not sufficiently expressive to do the loading we need to do. Instead, we'll emulate some of its features with inline math in copyin/copyout. Sponsored by: Netflix Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D38260
* kboot: Assert errno is negativeWarner Losh2023-02-021-1/+8
| | | | | | | | | | When converting from a Linux error to a FreeBSD errno, assert that the value passed in is negative, as is Linux's custom. Suggested by: brooks Sponsored by: Netflix Reviewed by: tsoome, brooks Differential Revision: https://reviews.freebsd.org/D38357
* kboot: Parse memory usageWarner Losh2023-02-021-0/+41
| | | | | | | | | | | | | | To properly size segments, we have to know how much memory we have in the system, as well as how much this process can allocate. Due to our inability to overcommit, we need to know how much memory is available. commit_limit is the grand total allowed. committed_as is the current memory used. mem_avail is what Linux tells us is available. Find these from /proc/meminfo. We'll use them later to allocate the biggest possible segment sizes, but for now print the raw numbers. Sponsored by: Netflix Reviewed by: kevans (earlier version) Differential Revision: https://reviews.freebsd.org/D38267
* kboot: For hostfs, return better errors from read, where possible.Warner Losh2023-02-022-3/+12
| | | | | | | | | | | | | | | | | Translate the Linux error return from read to a FreeBSD errno. We use a simplified translation: 1-34 are the same between the systems, so any of those will be returned directly. All other errno map to EINVAL. This will suffice for some code that reads /dev/mem in producing the right diagnostic. A fully generalized version is much harder. Linux has a number of errno that don't translate well and has architecture dependent encodings. Avoid this mess with a simple macro for now. Add comment explaining why we use the simple method we do. Sponsored by: Netflix Reviewed by: kevans, andrew Differential Revision: https://reviews.freebsd.org/D38265
* kboot: Fix hostdisk fmtdevWarner Losh2023-02-021-1/+3
| | | | | | | | | The device name was totally wrong. It should be "/dev/mumble:" not just "mumble". Sponsored by: Netflix Reviewed by: tsoome Differential Revision: https://reviews.freebsd.org/D38318
* kboot: Trim initial allocation to 64MBWarner Losh2023-02-021-2/+2
| | | | | | | | | | We only need 64MB to read off ZFS pools. Since Linux doesn't do ovecommit by default, the extra 64MB is 64MB less we can allocate for things like RAM disks. Sponsored by: Netflix Reviewed by: kevans, andrew Differential Revision: https://reviews.freebsd.org/D38268
* stand: only compute symidx on x86Warner Losh2023-02-021-1/+8
| | | | | | | | | We only use symidx on x86, so only compute it on x86 to fix a set but not used warning on aarch64. Sponsored by: Netflix Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D38246
* loader: md: Use default func for fmtdev and parsedevEmmanuel Vadot2023-01-271-2/+0
| | | | | | | | | | The default function are enough for md so use them instead of the disks ones that doesn't work for it anymore. Reviewed by: imp Sponsored by: Beckhoff Automation GmbH & Co. KG MFC after: now Differential Revision: https://reviews.freebsd.org/D38218
* lua: reduce diffs between luaconf.h copiesEd Maste2023-01-261-3/+4
| | | | | | | | | | | | | Upstream luaconf.h is contrib/lua/src/luaconf.h.dist, while userland lua and loader lua have copies in lib/liblua/luaconf.h and stand/liblua/luaconf.h. Adjust whitespace, VCS tags, etc. to match upstream's version, for ease of comparison. Reviewed By: imp Sponsored By: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D38206