aboutsummaryrefslogtreecommitdiff
path: root/stand/kboot
Commit message (Collapse)AuthorAgeFilesLines
* loader: Use C99 initializations for file_formatWarner Losh2025-12-282-6/+5
| | | | | | For greppability, use C99 initializers for the struct file_format. Sponsored by: Netflix
* kboot: Explicitly use host:/procWarner Losh2025-12-101-3/+10
| | | | | | | | | | | | | When looking for the boot_params symbol we need to get the UEFI memory map, use host: prefix. The short-circuit we have for this only works when we have a filesystem. During the earliest parts of boot, we can sometimes not have this yet, so making this explicit allows these environments to function. It's always in the host path. Print better error messages, and add newlines in two palces. Sponsored by: Netflix
* stand: Rename ZFSSRC to SAZFSSRC to avoid confusionWarner Losh2025-11-251-1/+1
| | | | | | | | | ZFSSRC is abiguous on its surface and too clos to ZFSTOP, so rename it to SAZFSSRC. Sponsored by: Netflix Reviewed by: tsoome Differential Revision: https://reviews.freebsd.org/D53901
* Revert "stand: Use calloc instead of malloc for initialization of filesystem ↵Warner Losh2025-09-021-1/+1
| | | | | | | | | devsw" This reverts commit dfafdbdfc3e9db8b878283bcbef35f5d8d37dae8. There's no author, and also problems with it. I'll redo it. Sponsored by: Netflix
* stand: Use calloc instead of malloc for initialization of filesystem devswnull2025-09-011-1/+1
| | | | | | | | This change is required for https://reviews.freebsd.org/D49355, so that we can check if d_dev is uninitialized by checking if it's NULL. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D49705
* kboot: Support reading the smbios vis sysfsAndrew Turner2025-07-301-6/+43
| | | | | | | | | | | When reading the smbios on Linux we try to access it via /dev/mem. On some systems we can't do this as /dev/mem is locked down. To handle this try reading the sysfs file first, and if that fails fall back to /dev/mem. Reviewed by: imp Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D51413
* Update tramp.S commenttropicahq2025-06-111-1/+1
| | | | | | Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1705 Closes: https://github.com/freebsd/freebsd-src/pull/1705
* kboot: Create quit commandWarner Losh2025-05-301-0/+12
| | | | | | | | | Create a command that just quits out of the loader. Useful for debugging. Sponsored by: Netflix Reviewed by: tsoome Differential Revision: https://reviews.freebsd.org/D50589
* stand: Retire arch_loadaddr using md_align, pending its replacementWarner Losh2025-05-303-16/+13
| | | | | | | | | | | | | | | | | | arch_loadaddr() is inconsistently used. In fact, I removed it entirely from kboot because its interface wasn't wide enough (though I broke powerpc kboot several years ago, and this commit might fix that). For now, modify uboot to put it into copyin like all the other loaders do. This might break arm ubldr. In its place, use the new md_align() and any replacement will be called from there, or via some explicit init() function. These changes allow me to load a amd64 kernel via UEFI with all the modules aligned to 16k. Sponsored by: Netflix Reviewed by: jhibbits Differential Revision: https://reviews.freebsd.org/D50587
* stand/kboot: Remove _end forward declWarner Losh2025-05-261-1/+0
| | | | | | We don't need/use it. Sponsored by: Netflix
* kboot: Initialize archsw at compile timeWarner Losh2025-05-261-10/+10
| | | | | | | No need to initialize this at runtime. This trades .bss space + code in .text for just .data and is net smaller. Sponsored by: Netflix
* kboot: Add support for UEFI booting amd64Warner Losh2025-04-173-22/+142
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In an ideal world, we'd get systbl and efi memory map from /sys/firmware/efi somewhere. They are currently not published, but may be in the future. The systab comes from the first call to the EFI entry point and there's no way to find it otherwise. Memmap is obtained from BootServices which is long gone. And besides, it's modified for the runtime entries for the call to SetVirtualAddresses call in runtime services. Even though that's in runtime services, it can be called only once. kexec tools + Pandora (the kexec boot loader embedded in the Linux kenrel) don't need this because pandora copyies this structure over when the new kernel is a bzImage. Our current trampoline doesn't do that, so we have to get it from the current kernel. Even so, we have to pass the PAs for the memory map to the trampoline which copies this over (in part so we can boot an modified kernel, otherwise we could put this into an alternative entry point, but those are hard to manage). So, we can sig out the PA of the memory map via this method, but some care is needed. For the initial round, it suffices. However, Linux on x86 does some odd things with EFI_RUNTIME that need to be preserved (so this is a temporary measure until we get the /sys/firmware/efi code working). The Linux kernel keeps this memory around, but it's not clear how long. It stops referencing it after it converts it to the BIOS e820 memory map array it uses elsewhere. It seems to be OK to use since our use case is an immediate boot to FreeBSD, not a boot after Linux runs a while and had a chance to (maybe) overwrite this data. Migrating to a proper interface that publishes the modified EFI map in /sys/firmware/efi/memmap is in the future. Update the trampoline to copy this data before jumping into the kernel. We use the simple laucnhing interface instead of the bzImage interface that kexec_file() uses, so there's no last-second chance to use the boot params data. Sponsored by: Netflix Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D49869
* kboot: Implement data_from_kernel to read kernel variablesWarner Losh2025-04-173-0/+297
| | | | | | | | | | Since the linux kernel doesn't expose enough of the EFI details to userland via /sys/firmware/efi, write a routine to extract data from the kernel directly by parsing /proc/kproc and /proc/kallsyms. Sponsored by: Netflix Reviewed by: kevans, jhibbits Differential Revision: https://reviews.freebsd.org/D49868
* kboot/amd64: Use efi_bi_loadsmap in bi_loadsmapWarner Losh2025-04-171-14/+1
| | | | | | | | | For the EFI case, we just need to call efi_bi_loadsmap in bi_loadsmap. If we need to do BIOS again, we'll revisit. Sponsored by: Netflix Reviewed by: kevans, jhibbits Differential Revision: https://reviews.freebsd.org/D49867
* kboot/amd64: Use segs framework to find kernel locationWarner Losh2025-04-171-12/+15
| | | | | | | | | Use the segs framework to find a place to land the kernel, with the same super ugly defaults as aarch64. Sponsored by: Netflix Reviewed by: kevans, jhibbits Differential Revision: https://reviews.freebsd.org/D49866
* kboot/amd64: Use common routines for memory map parsingWarner Losh2025-04-171-105/+6
| | | | | | | | | | | | | | | | | Use populate_avail_from_iomem and efi_read_from_sysfs from the refactored work rather than replicating them (imperfectly) here. Note: memmap might need to be revisited. EFI memory maps are complex on x86 and we might need to reconstruct it from /sys/firmware/memmap as well as using that for the BIOS case, should we ever want to support that again (hardware makes no sense, but many VM hosting services use that). For now, we're going all in on EFI, though, and will revisit what to do about BIOS later. The zfsboot project suggests BIOS support isn't really that hard (but is a distraction atm). Sponsored by: Netflix Reviewed by: kevans, jhibbits Differential Revision: https://reviews.freebsd.org/D49864
* kboot: Move common EFI stuff from aarch64 to libkbootWarner Losh2025-04-175-127/+200
| | | | | | | | | | | | | | | | | Move efi_read_from_pa, efi_set_systbl and efi_bi_loadsmap into efi.c Move prototype for populate_avail_from_efi as well, though that arrived previously. Move efi memory map variables into efi.c. Add efi_read_from_sysfs, but if 0 it out. We'll want to use it if we can get the proposed /sys/firmware/efi/memmap data published in the same format and the code works, it's just that the current /sys/firmware/efi/runtime-memmap isn't complete enough to use. Sponsored by: Netflix Reviewed by: kevans, jhibbits Differential Revision: https://reviews.freebsd.org/D49863
* kboot: Method to populate the avail array from EFI mapWarner Losh2025-04-172-0/+38
| | | | | | | | | | | | If we can get an efi memory map, populate_avail_from_efi will create an avail array. We only use the regiions marked as 'free' to find a place for the kernel to land. The other regions are also eligible, but usually too small to materially affect where we'd put the kernel (not to worry, the kernel will use that memory). Sponsored by: Netflix Reviewed by: kevans, jhibbits Differential Revision: https://reviews.freebsd.org/D49862
* kboot: Account for machine specific paddingWarner Losh2025-04-171-5/+19
| | | | | | | | | AMD64 kernels have an extra 2MB of padding that we need to account for. So make the padding proper on a per-architecture basis. Sponsored by: Netflix Reviewed by: kevans, jhibbits Differential Revision: https://reviews.freebsd.org/D49861
* kboot: Save the upper limit of the call stack.Warner Losh2025-04-171-0/+3
| | | | | | | | | | | | | The location of argc argument is a fine limit for the extent of the stack traceback. We could save the location of return address for the call to _start_c, but we'd have to move that into MD assembler. While not hard, it wouldn't improve the traces we can get. And the math to find it is architecture dependent (though the same for both arm64 and amd64). Sponsored by: Netflix Reviewed by: kevans, andrew, jhibbits Differential Revision: https://reviews.freebsd.org/D49858
* kboot: format nitWarner Losh2025-04-171-1/+0
| | | | | | | | Deleting trailing newline. Sponsored by: Netflix Reviewed by: kevans, andrew, emaste, jhibbits Differential Revision: https://reviews.freebsd.org/D49857
* kboot: Add option to parse 32-bit quantityWarner Losh2025-04-172-0/+14
| | | | | | | | | The type that's exposed from sysfs' memory map is 32-bit and so is the data-type of memory description. Sponsored by: Netflix Reviewed by: kevans, andrew, jhibbits Differential Revision: https://reviews.freebsd.org/D49856
* kboot: .note.GNU-stack is neededWarner Losh2025-04-176-0/+12
| | | | | | | | | | | Add '.section .note.GNU-stack,"",%progbits' to all assembler. Newer versions of clang complain when this isn't present because executable stacks are going away in the future. We don't need an executable stack anyway. Sponsored by: Netflix Reviewed by: kevans, andrew, emaste, jhibbits Differential Revision: https://reviews.freebsd.org/D49855
* kboot: Spell Reserved correctlyWarner Losh2025-04-171-2/+1
| | | | | | | | Also, remove trailing NULL entry that's no longer needed. Sponsored by: Netflix Reviewed by: kevans, jhibbits Differential Revision: https://reviews.freebsd.org/D49854
* kboot: Free prior segs in init_avail()Warner Losh2025-04-091-0/+1
| | | | | | | | We can call init_avail() multiple times. Each time, we want to toss whatever garbage may have already been there from a prior failed attempt to find a good memory map. Sponsored by: Netflix
* kboot: Start to move efi common routines to libkbootWarner Losh2025-04-094-85/+120
| | | | | | | Start to move the common efi routines into libkboot by moving the efi memory map walking and implementing a printing routine around it. Sponsored by: Netflix
* kboot: Use roundup2 instead of expanding the (old) definiution of it inlineWarner Losh2025-04-091-2/+2
| | | | | | | | | | | | | | | | | The boot loader pads efi_map_header to start the array of efi_memory_descriptor entries on the 16-byte-aligned boundary after the header. Since the header isn't naturally 16-byte aligned, we need to do this. We should have used the actual UEFI EFI_MEMORY_ATTRIBUTES_TABLE which used uint32_t's to pass all this data to the kernel (they never needed to be 64-bit quantities or size_t's even) since these entries and the total size of the table is small. However, this ship long since sailed since we've used these structures for a decade and there's little to be gained by changing them. The table header we pass to the kernel from the loader has similar names, but the seamntics of the fields are different. Sponsored by: Netflix
* termios: Do return EINVAL for bad action to tcsetattr()Warner Losh2025-04-091-1/+1
| | | | | | Set errno for bad actions in tsetattr to catch bad actions. Sponsored by: Netflix
* kboot: Move str* util routines to libkbootWarner Losh2025-04-095-6/+13
| | | | | | | | These are needed for the next round of EFI support for amd64 (partially shared with aarch64, but only partially because the Linux host interfaces are different to get the same info). Sponsored by: Netflix
* kboot: Move seg code into libkbootWarner Losh2025-04-095-20/+28
| | | | | | | | | This code is really generic segment processing and should live here. It also interfaces primarily with Linux APIs, so it's also appropriate for this if we have a version of that runs as a FreeBSD binary using FreeBSD system calls and APIs, though that's in the future somehow... Sponsored by: Netflix
* kboot: Use SRCS+= instead of continuation linesWarner Losh2025-04-091-4/+4
| | | | | | Use SRCS+= to allow for better ifdefs Sponsored by: Netflix
* loader.kboot: smbios: Add a comment about v3 entry point being favoredOlivier Certner2025-03-111-0/+4
| | | | | | | | | Note that the behavior here is consistent with BIOS and EFI boot. Reviewed by: imp, markj MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D49293
* stand/efi: move G(x) and M(x) macros to loader_efi.hAhmad Khalifa2024-12-051-5/+4
| | | | | | | | These are often needed for copying to the staging area or just general page table calculations on amd64. Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1446
* stand: move 'staging' to loader_efi.hAhmad Khalifa2024-12-051-2/+0
| | | | | | | On amd64, we need this to setup the page tables. Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1446
* kboot/aarch64: remove redundant includeAhmad Khalifa2024-12-051-1/+0
| | | | | Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1446
* stand: move efi's bi_load into loader_efi.hAhmad Khalifa2024-12-052-3/+7
| | | | | | | | For kboot, we still have to declare it manually since we don't always include loader_efi.h Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1446
* loader.kboot: Build on amd64Warner Losh2024-11-072-2/+8
| | | | | | | But comment out FDT stuff for amd64 built inside kboot. This also restricts a bit the powerpc platforms we build on to powerpc64. Sponsored by: Netflix
* loader: Bump all versions to 3.0Warner Losh2024-07-291-0/+1
| | | | | | | | | | | | | Each incompatible change we make, we bump the major version. We've not done the bump in a while, so sync everybody to 3.0. Anything older than 3.0 will be given a warning that their boot loader is too old. We check only the major version, though, so minor versions can still be bumped for individual loaders (though I honestly doubt we'll ever need to do that again). Sponsored by: Netflix Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D45888
* stand: Remove obsolete junkWarner Losh2024-07-291-5/+0
| | | | | | | | | | We long ago changed newvers.sh to make these comments bogus. Remove them since every single one of them is broken after the $FreeBSD$ removal. Sponsored by: Netflix Reviewed by: kevans, jhb Differential Revision: https://reviews.freebsd.org/D45879
* Remove residual blank line at start of MakefileWarner Losh2024-07-151-1/+0
| | | | | | | This is a residual of the $FreeBSD$ removal. MFC After: 3 days (though I'll just run the command on the branches) Sponsored by: Netflix
* stand/kboot: Fix the linker script OUTPUT_FORMATAndrew Turner2024-05-221-1/+1
| | | | | | | | | | | | ld.bfd doesn't understand elf64-aarch64 but does have elf64-littleaarch64. Switch to this so we can link kboot with it. While here switch to the single format version. We are unlikely to support booting from a big-endian Linux. Reviewed by: imp, emaste Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D45258
* kboot: Use C99 initialiers for hostconsole.Warner Losh2024-05-201-8/+7
| | | | Sponsored by: Netflix
* kboot: Initialize hostfs_root sooner (and remove kboot.conf)Warner Losh2024-05-201-4/+4
| | | | | | | | | | | | | | Move the initialization of hostfs_root to be a bit sooner. While it doesn't matter for the default case, we may want to use hostfs files sooner. Also, while we're here, remove kboot.conf. It duplicates the command line and has proven difficult to use. It will be replaced by an early script that can influence the state of the boot loader before we select a device to boot from (including strongly suggesting which one to boot from). Sponsored by: Netflix
* kboot: Move console, acpi and smbios initWarner Losh2024-05-201-12/+12
| | | | | | | | | | | | | | | Move the console probing to as early as possible. There's no real support for anything but hostcons, and setting it up early will show other error messages. ACPI and SMBIOS probing can be done just after we have the console, so move it there. This allows other parts of the early code to use info from that, as well as overriding and env vars set by these things on the command line (smbios data may be wrong during initial development phases as the automated way to populate per-board data may not be established, etc). Sponsored by: Netflix
* kboot: kbootfdt: fix error handlingWarner Losh2024-03-111-7/+6
| | | | | | | | If we are able to open /sys/firmware/fdt, but aren't able to read it, fall back to /proc/device-tree. Remove comment that's not really true, it turns out. Sponsored by: Netflix
* kboot: Use is_linux_error to check mmap return errorWarner Losh2024-03-111-1/+1
| | | | | | | Rather than checking against the (incorrect) -511, use the is_linux_error() function to check to see if host_mmap failed. Sponsored by: Netflix
* kboot: Print UEFI memory mapWarner Losh2024-03-111-0/+85
| | | | | | | | | If we can read the UEFI memory map, go ahead and print the memory map. While the kernel prints this with bootverbose, having it at this stage is useful for debugging other problems. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D44287
* kboot: hostfs -- check for llseek failure correctlyWarner Losh2024-03-111-3/+10
| | | | | | | | | | | | | | | | | | | | | | | | The host_* syscalls are all raw Linux system calls, not the POSIX wrappers that glibc / musl create. So we have to ranage change the return value of host_llseek correctly to use the negative value hack that all Linux system calls use. This fixes a false positive error detection when we do something like lseek(fd, 0xf1234567, ...); This returns 0xf1234567, which is a negative value which used to trigger the error path. Instead, we check using the is_linux_error() and store the return value in a long. Translate that errno to a host errno and set the global errno to that and return -1. lseek can't otherwise return a negative number, since it's the offset after seeking into the file, which by definition is positive. This kept the 'read the UEFI memory map out of physical memory' from working on aarch64 (whose boot loader falls back to reading it since there are restrictive kernel options that can also prevent it), since the physical address the memory map was at on my platform was like 0xfa008018. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D44286
* kboot: Avoid UB in signed shiftWarner Losh2024-03-111-2/+3
| | | | | | | | | | offset is signed. Copy it to the unsigned res before shifting. This avoids any possible undefined behavior for right shifting signed numbers. No functional change intended (and the code generated is the nearly same for aarch64). Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D44285
* kboot: Create function for error checking.Warner Losh2024-03-111-4/+20
| | | | | | | | | | | | Linux has the convention of returning -ERRNO to flag errors from its system calls. Sometimes other negative values are returned that are success... However, only values -1 to -4096 (inclusive) are really errors. The rest are either truncated values that only look negative (so use long instead of int), or are things like addresses or legal unsigned file offsets or similar that are successful returns. Filter out the latter. Sponsored by: Netflix