aboutsummaryrefslogtreecommitdiff
path: root/stand/common
Commit message (Collapse)AuthorAgeFilesLines
* loader: Use %u to print unsigned valueWarner Losh10 days1-1/+1
| | | | | Fixes: 7055aa7a070f Sponsored by: Netflix
* loader: add standalone network configurationWarner Losh11 days2-27/+57
| | | | | | | | | Allow callers to obtain DHCP configuration without opening a network file, enabling loader.efi to discover an initmd URL before handing the interface back to firmware HTTP. Differential Revision: https://reviews.freebsd.org/D59429 Sponsored by: Netflix
* loader: Allow dynmaic creation of MD disksWarner Losh11 days2-32/+101
| | | | | | | | | Augment the md device to allow creation of md devices. This is useful when UEFI doesn't support RamDisk and in other cases where we have a handy initrd-like image we want to use. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D59418
* loader: Move ramdisk export to md.cWarner Losh11 days2-0/+22
| | | | | | | Move the common routine to md.c and use it where we do memdisks today. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D59417
* loader: Allow this to compile w/o MD_IMAGE_SIZE definedWarner Losh11 days1-3/+3
| | | | | | | | | Slight tweak to allow md.c to be compiled when MD_IMAGE_SIZE isn't defined. Sponsored by: Netflix Reviewed by: olivier, tsoome Differential Revision: https://reviews.freebsd.org/D59415
* stand: Reject ELF files with PT_LOAD segments where filesz > memszJohn Baldwin2026-07-311-0/+6
| | | | | Reviewed by: jrtc27, kib Differential Revision: https://reviews.freebsd.org/D58543
* stand: Improve error handling when loading ELF filesJohn Baldwin2026-07-311-18/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | Previously all the 'goto out' statements after the image was loaded into memory returned success rather than an error. This is despite comments indicating some of these conditions were in fact errors, and some of these error conditions (such as missing PT_DYNAMIC) are treated as errors in the kernel linker. In addition, when failing to looking up the symbols for the linker set, those cases returned failure leaking memory (though it's clear from the original code from commit ca49b3342d1e that only the second failure was intended to be an actual error). To avoid more confusion, move the assignment of `ret` to just before the `out` label so that `goto out` always returns an error. This is a more consistent pattern with other code in the tree that tends to use labels for the error case. Restructure some other code to avoid a few bogus errors. Specifically, a symbol table is not required so don't treat lack of a symbol table as an error. Also, if the start symbol for the module metadata linker set is not found, don't treat that as an error either. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D58540
* stand: Remove a pointless gotoJohn Baldwin2026-07-311-3/+0
| | | | | | | | | Commit 505222d35fea removed a batch of code that this goto used to skip around. Reviewed by: olce, kib, markj Fixes: 505222d35fea ("Implement the long-awaited module->file cache database. A userland tool (kldxref(8)) keeps a cache of what modules and versions are inside what .ko files. I have tested this on both Alpha and i386.") Differential Revision: https://reviews.freebsd.org/D58539
* stand: Recognize SHT_INIT_ARRAY sections as constructor sectionsMark Johnston2026-07-151-1/+2
| | | | | | | | | | | Pass such a section to the kernel using modinfo, otherwise link_elf.c won't execute constructors for the file. This is required for KASAN, otherwise redzones for global buffers are not poisoned during boot. Reviewed by: kib MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D58244
* stand: Fix shadow buffer offset handlingShengYi Hung2026-06-301-11/+15
| | | | | | | | | | | | | | | | | | | | | | | The shadow buffer is addressed relative to `tg_origin`, which includes the padding offset, whereas `gfxfb_blt` operates on coordinates without that offset. To make `gfx_fb_copy_area` emulate the behavior of `gfxfb_blt`, the source coordinates must include the padding offset, while the destination coordinates must not. The original implementation omitted the offset from the source coordinates; this change corrects that. Additionally, `gfx_fb_cons_display` already applies the padding offset, so the redundant adjustment is removed. PR: 296246 Reported by: 2khramtsov@gmail.com Reviewed by: imp Tested by: 2khramtsov@gmail.com, junchoon@dec.sakura.ne.jp, naito.yuichiro_@gmail.com Fixes: 32da2f23ae4d MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D57821
* stand: Bulk operations on each gfxfb_blt if shadow buffer enabledShengYi Hung2026-06-182-22/+210
| | | | | | | | | | | | | | | | | | | Previously, gfxfb_blt flushed the framebuffer on every call. Since a single drawing operation may invoke gfxfb_blt multiple times, this can result in unnecessary flushes. Instead, write updates to the shadow buffer (when present) and mark the affected area as dirty. Flushing is deferred so multiple gfxfb_blt calls can be coalesced into a single update. As before, only the dirty region is flushed. This fixes the slow bootloader problem in some platforms. Reviewed by: imp, adrian, obiwac Tested by: obiwac, jrm MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D57373
* stand/common/load_elf: Do kernel module relocations for PPCLexi Winter2026-04-181-3/+4
| | | | | | | | | | | | | | | | reloc_ptr() skips relocations for the kernel module, because on most platforms the kernel is ET_EXEC and this is not required. On PPC, the kernel is ET_DYN and we need to relocate here, otherwise the module metadata will not be loaded properly and the kernel module will have an incorrect version, preventing module dependencies from resolving. This fixes loading kernel modules from loader.conf on powerpc. Diagnosed by: jrtc27 Reviewed by: jrtc27, adrian Sponsored by: https://www.patreon.com/bsdivy Differential Revision: https://reviews.freebsd.org/D56457
* Pass severity to vectx_open() rather than vectx_close()Simon J. Gerraty2026-04-104-8/+22
| | | | | | | | | | | | | | | | file_loadraw() can have a need to load unverified files like "dtrace_dof". Allow severity_guess() to look at the filename but if it returns less than VE_MUST check that the type is not one we insist on verifying. In vectx_open if severity < VE_MUST we can allow it to be unverified. If passed VE_GUESS we call severity_guess(). Regardless, we record severity in ctx so it is available to vectx_close(). Sponsored by: Hewlett Packard Enterprise Development LP Reviewed by: khng Differential Revision: https://reviews.freebsd.org/D56297
* Add boot_setenvSimon J. Gerraty2026-04-071-57/+3
| | | | | | | | | | | | | Move is_restricted_var() to libsa/environment.c so it can be leveraged by boot_setenv called from subr_boot with not truted input. Also, allow for local tuning via ENV_IS_RESTRICTED_ALLOWED_LIST and ENV_IS_RESTRICTED_LIST Sponsored by: Hewlett Packard Enterprise Development LP. Reviewed by: kevans, imp Differential Revision: https://reviews.freebsd.org/D56287
* splash: add shutdown splashQuentin Thébault2026-04-032-5/+19
| | | | | | | | | | | This commit adds a shutdown splash to the existing kernel startup splash(4) screen feature. It can be customized by providing a PNG image to the shutdown_splash directive loader.conf(5). Sponsored by: Defenso MFC after: 2 weeks Reviewed by: vexeduxr, ziaee, manu Differential Revision: https://reviews.freebsd.org/D55140
* stand: fix typo in common/nvstore.cToomas Soome2026-01-281-1/+1
| | | | Some out of order chars.
* loader.efi: only use firmware provided Blt on GOPAhmad Khalifa2026-01-041-2/+6
| | | | | | | | | | | | | | gfx_state.tg_private points to a EFI_GRAPHICS_OUTPUT_PROTOCOL only when using GOP. The firmware provided Blt functions on UGA platforms have been observed to not work on old MacBooks, and are likley hit or miss anyways as UGA has been deprecated since 2006. Reviewed by: tsoome PR: 291935 MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D54432
* stand: Cut over to using the EDK2 filesWarner Losh2025-11-161-1/+2
| | | | | | | | | | | | | | | | | | | | | | Remove the old EFI SDK files that we've been nursing along for too many years. Replace them with files from EDK2 edk2-stable202502 and tweak the interfaces we need to tweak. Mostly include different things or change the names of the protocols that no longer have old-school compat names. I gave up in the middle of env.c, too damn tedious to find all those new GUIDs. Also, many of the guids were mystery meat, most likely from the EDK2 sources, but just not the Include subdirectory. Need to investigate those. And the memory info? Is it just an oboslete thing, or embedded knowledge of EDK2. Delete the now-redundant copies of things in Guid and Protocol. I debated keeping ZeroGuid.h, but EDK2 has moved on from when I snagged it years ago (or maybe I just invented it out of whole cloth: edk2 does radically different things today and I didn't do the git deep-dive to find out). Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D53655
* stand: Try to parse vdisk correctlyWarner Losh2025-11-111-1/+12
| | | | | | | | PR: 289306 Sponsored by: Netflix Reviewed by: dab MFC After: 5 days Differential Revision: https://reviews.freebsd.org/D52500
* stand: remove unused variablesAhmad Khalifa2025-09-091-1/+0
|
* 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
* stand: add a mechanism to avoid env var propagation to kenvKyle Evans2025-08-222-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Our only user of this at the moment is teken.{fg,bg}_color. These are special because teken is a library common to both the kernel and the loader, and we want to avoid having special vars to control the loader vs. the kernel. Ideally, if a user wants a different set of console colors, then they set the appropriate teken variable and it Just Works(TM) everywhere. We can't just avoid setting the env vars, because we specifically want to install a hook to adjust how loader is drawn. This allows us to avoid breaking a kernel config(5) that has some default teken colors set with our defaults. That's a valid configuration, even if it might seem weird that they don't want to set colors in both loader and the kernel -- they may not anticipate spending any time in loader, and thus prefer to just let it do its default behavior. NOKENV is expected to be unset if the value is overwritten, rather than acting as a persistent marker that we do not want the value to persist under any circumstance. We can always add another flag bit later for persistence if we find a use for that, but most variables are fine to carry over. This is mostly needed for environment variables that we really just want to set a hook for. Future work could expand this to break it out to the scripted interfaces. We have discussed some options like a new built-in command, or adding a flag to the existing `set` command, but haven't really come up with a concrete plan to avoid confusion. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D50888
* stand: split fg/bg handling up a little furtherKyle Evans2025-08-221-16/+41
| | | | | | | | | | | | | | | | These can be setup independently, so we should also check them and initialize each independently. This fixes a pre-existing bug where-in we may not pickup a bg color specified in the environment if a fg color wasn't set. The new version also ensures that we're hooking the color vars properly if we're using a value that was already there, as the console may need to adjust if something wants to switch them up again. Otherwise, a teken.fg_color set in loader could conceivably occur that only changes the color when you get to the kernel, which could be surprising. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D50887
* stand: use a common function in gfx_fb for setting up teken colorsKyle Evans2025-08-222-0/+32
| | | | | | | | | | These are basically identical, with exception to the hook installed which is specific to the loader we're building by necessity. Pull these out into common/gfx_fb.c and just parameterize the hooks to make it easier to change the logic. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D50886
* Stub is_tftp when LOADER_NET_SUPPORT is not enabledSimon J. Gerraty2025-08-211-0/+13
| | | | | | | | | common/misc.c is a non-optional part of loader. If LOADER_NET_SUPPORT is not defined provide a stub that always returns false. Reviewed by: kevans, des Differential Revision: https://reviews.freebsd.org/D52060
* Allow secure-netbootSimon J. Gerraty2025-08-201-11/+21
| | | | | | | | | | | | | | | | | | When doing file verification, tftp needs to be able to handle multiple open files concurrently. We also need tftp_stat() to provide useful values for st_dev and st_ino. Allow an architecture to define NETPROTO_DEFAULT. The default is NET_NFS for backwards compatability. In net_parse_rootpath() fix parsing of <scheme>://<ip>[:<port]/<path> and ensure we return INADDR_NONE unless we successfully parsed an addr, so we don't end up clobbering rootip obtained from bootp(). Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D51187
* loader: do not try to open directories with TFTPSimon J. Gerraty2025-08-201-1/+8
| | | | | | | | | | | | | | | Attempting to mount or even open / with some tftp servers causes a several minute delay in boot. Since opening a directory via TFTP does not make sense, we avoid it. We don't know if using TFTP until after net_open() has been called. Add an is_tftp() accessor to avoid everyone having to include all the net* headers. Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D51447
* install: allow ENV in metatagsSimon J. Gerraty2025-07-211-1/+3
| | | | | | | | | The metatags file informs install of kernel and modules to load, allow it to also case variables to be set in env. Reviewed by: imp Sponsored by: Juniper Networks, Inc Differential Revision: https://reviews.freebsd.org/D51446
* stand: Add print_delay environment variable in loaderAymeric Wibo2025-07-212-0/+25
| | | | | | | | | | | This adds support for a new `print_delay` environment variable, which inserts a delay in microseconds when `putchar` encounters a newline character. This can be useful when debugging. Reviewed by: markj, imp, ziaee, mckusick (mentor) Approved by: markj, imp, ziaee, mckusick (mentor) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D50832
* Add DEBUG_PRINTF to stand.hSimon J. Gerraty2025-07-171-40/+17
| | | | | | | | | | | | | | | | | | | | | | | | stand/ is mostly debugged with printfs, in an ad hoc and sometimes fragile manner. For example BOOTP_DEBUG in bootp.c cannot be defined unless NETIF_DEBUG is defined in dev_net.c or build fails for lack of the symbol debug. The DEBUG_PRINTF implementation in stand.h addresses that and allows for more control over debug output. It is compatible with the usage in libsecureboot. Simply define _DEBUG_LEVEL to the desired level of debug or in the case of libsecureboot _DEBUG_LEVEL_VAR to the variable that will hold that value - default is _debug which is static so each translation unit can be controlled independently. The 1st arg to DEBUG_PRINTF is a level which must be greater than or equal to _DEBUG_LEVEL_VAR if the printf is to be called. See libsecureboot for more examples. Reviewed by: imp Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D51269
* machine/stdarg.h -> sys/stdarg.hBrooks Davis2025-06-112-2/+3
| | | | | | | | | | | | | Switch to using sys/stdarg.h for va_list type and va_* builtins. Make an attempt to insert the include in a sensible place. Where style(9) was followed this is easy, where it was ignored, aim for the first block of sys/*.h headers and don't get too fussy or try to fix other style bugs. Reviewed by: imp Exp-run by: antoine (PR 286274) Pull Request: https://github.com/freebsd/freebsd-src/pull/1595
* loader: allow for exceptions to restricted settings.Simon J. Gerraty2025-06-021-22/+73
| | | | | | | | | | | | We restrict what an unverified loader.conf etc can set, and the same restrictions are applied to interactive input. We need to allow for exceptions (eg boot_verbose). It is best if any allowed settings match up to '='. If we do not allow it to be set, do not allow it to be unset Reviewed by: stevek Sponsored by: Juniper Networks, Inc.
* install: must set netproto for tftp://Simon J. Gerraty2025-06-021-0/+1
| | | | | | tftp_open requires netproto is NET_TFTP Reviewed by: stevek
* style: Use static consistentlyWarner Losh2025-05-301-4/+4
| | | | | | | | | | | C doesn't require that we have static on both the declaration and definition of a function. But stylistically, FreeBSD does. Make that so. Also make a function static that wasn't because, it seems, that static and struct look a lot alike in a column of text. Sponsored by: Netflix Reviewed by: tsoome, jhibbits Differential Revision: https://reviews.freebsd.org/D50588
* stand: Retire arch_loadaddr using md_align, pending its replacementWarner Losh2025-05-305-24/+8
| | | | | | | | | | | | | | | | | | 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: Style nitWarner Losh2025-05-301-1/+2
| | | | | | Sponsored by: Netflix Reviewed by: chs, tsoome Differential Revision: https://reviews.freebsd.org/D50586
* stand: Introduce md_alignWarner Losh2025-05-303-4/+27
| | | | | | | | | | | | | | When we're loading metadata, we need to align it in a certain way. Right now that way is hard-coded to be PAGE_SIZE. Rather than do the actual physical thing in all these places, move this into a wrapper routine. We may want to load a 16k kernel and align all these on 16k or a 4k kernel and align on 4k on aarch64 (today you have to compile the loader with the right page size). This will also reduce the number of places we might have to touch to do that. Sponsored by: Netflix Reviewed by: tsoome, jhibbits Differential Revision: https://reviews.freebsd.org/D50585
* stand: Update commentWarner Losh2025-05-261-1/+2
| | | | | | Some routines are necessary, so note that. Sponsored by: Netflix
* stand allow for local.defs.mkSimon J. Gerraty2025-05-221-1/+5
| | | | | | | | | | | This allows us to change the VERSION_FILE used for loaders as well as set NEWVERS_DATE and BUILD_UTC to reflect the publish date of loaders for secure-boot. Sponsored by: Juniper Networks, Inc. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D50478
* loader - guard against empty rootdevSimon J. Gerraty2025-05-201-1/+1
| | | | | | | | | | At least one instance of u-boot pretending to be EFI is passing empty rootdev to loader which does not end well. A simple precaution is harmless. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D50334
* loader: loader can pick too large font (check if one side is larger)Toomas Soome2025-05-131-1/+1
| | | | The 5e25f7b09977 still allows one side to be too large, fix it.
* loader: loader can pick too large fontToomas Soome2025-05-111-3/+12
| | | | | | | | | | While calculating font size based on EDID data, we can end up selecting too large font and too small terminal. Add check to prevent it. Tested by: bz, ziaee Reviewed by: adrian Differential Revision: https://reviews.freebsd.org/D50258
* loader: Instrument gfx_fb_fill with tslogColin Percival2025-05-111-0/+4
| | | | | | | | | | | Some systems boot absurdly slowly, apparently due to problems with UEFI framebuffer accesses being sluggish. This does not fix the problem, but at least makes gfx_fb_fill show up as a large block in boot flamecharts, which will save time when the next user needs to identify why their system is booting slowly. PR: 284595 Tested by: Peter Miller
* loader: Remove unneeded includesWarner Losh2025-04-172-6/+0
| | | | | | | | | | | | We've not needed to include link.h in the loader for a long time. I shoud have removed it in f38658e1408c rather than going link.h -> sys/sys_link.h. It's purely a userland shared library thing. Remove it now, since it's not needed. Also remove a few headers that are redundant with stand.h in this environment. Sponsored by: Netflix Reviewed by: kevans, andrew, jhibbits Differential Revision: https://reviews.freebsd.org/D49859
* loader.efi: add "gop blt <on|off>" commandToomas Soome2025-02-201-1/+9
| | | | | | | | | | | | | | | | | | | Some systems have very slow console output and it may be about either wrong memory attributes are set or gop->Blt() implementation is bad. We do not have good way to set memory attributes, but we can choose which Blt() to use (or we can set "gop off" to fall back on use of SimpleTextOutput protocol). This update adds argument for "gop" command to switch gop->Blt() use. Note, this update does not fix the problem, but allows us to try to understand the possible cause. PR: 254381 Reported by: Michael Galassi Reviewed by: manu, imp Differential Revision: https://reviews.freebsd.org/D49073
* stand: Use SOURCE_DATE_EPOCH in newvers.shColin Percival2025-02-031-1/+9
| | | | | | | | | | | | | | The newvers.sh script is used to generate vers.c for 10 programs (at latest count on amd64): 4 EFI loaders, 3 x86 loaders, two userboots, and one kboot. When building without MK_REPRODUCIBLE_BUILD this resulted in 10 different timestamps being compiled into various files. If SOURCE_DATE_EPOCH is set, use that value rather than the current date and time. Reviewed by: emaste, imp Sponsored by: Amazon Differential Revision: https://reviews.freebsd.org/D48803
* stand: use globals for the kernel and module typesAhmad Khalifa2025-01-246-15/+23
| | | | | Reviewed by: imp, kib Pull Request: https://github.com/freebsd/freebsd-src/pull/1394
* stand: file_loadraw: make 'type' a const char *Ahmad Khalifa2025-01-242-2/+2
| | | | | Reviewed by: imp, kib Pull Request: https://github.com/freebsd/freebsd-src/pull/1394
* stand: remove unnecessary checks for "elfN kernel"Ahmad Khalifa2025-01-243-8/+2
| | | | | | | | We never set the kernel type to either "elf64 kernel" nor "elf32 kernel". Reviewed by: imp, kib Pull Request: https://github.com/freebsd/freebsd-src/pull/1394