Lines Matching +full:mode +full:- +full:loader

1 --
2 -- SPDX-License-Identifier: BSD-2-Clause
3 --
4 -- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
5 -- Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
6 -- All rights reserved.
7 --
8 -- Redistribution and use in source and binary forms, with or without
9 -- modification, are permitted provided that the following conditions
10 -- are met:
11 -- 1. Redistributions of source code must retain the above copyright
12 -- notice, this list of conditions and the following disclaimer.
13 -- 2. Redistributions in binary form must reproduce the above copyright
14 -- notice, this list of conditions and the following disclaimer in the
15 -- documentation and/or other materials provided with the distribution.
16 --
17 -- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 -- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 -- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 -- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 -- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 -- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 -- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 -- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 -- SUCH DAMAGE.
28 --
50 local boot_single = loader.getenv("boot_single") or "no"
51 local boot_verbose = loader.getenv("boot_verbose") or "no"
63 -- Globals
64 -- try_include will return the loaded module on success, or false and the error
65 -- message on failure.
68 local lua_path = loader.lua_path
69 -- XXX Temporary compat shim; this should be removed once the
70 -- loader.lua_path export has sufficiently spread.
75 -- We only attempt to append an extension if an absolute path
76 -- wasn't specified. This assumes that the caller either wants
77 -- to treat this like it would require() and specify just the
78 -- base filename, or they know what they're doing as they've
79 -- specified an absolute path and we shouldn't impede.
84 if lfs.attributes(module, "mode") ~= "file" then
91 -- Module exports
92 -- Commonly appearing constants
97 -- Note that this is a decimal representation, despite the leading 0 that in
98 -- other contexts (outside of Lua) may mean 'octal'
115 loader.setenv("boot_verbose", "YES")
117 loader.unsetenv("boot_verbose")
128 loader.setenv("boot_single", "YES")
130 loader.unsetenv("boot_single")
136 -- We can't trust acpi.rsdp to be set if the loader binary doesn't do
137 -- ACPI detection early enough. UEFI loader historically didn't, so
138 -- we'll fallback to assuming ACPI is enabled if this binary does not
139 -- declare that it probes for ACPI early enough
140 if loader.getenv("acpi.rsdp") ~= nil then
152 -- Otherwise, respect disabled if it's set
153 local c = loader.getenv("hint.acpi.0.disabled")
164 loader.setenv("hint.acpi.0.disabled", "0")
167 loader.setenv("hint.acpi.0.disabled", "1")
177 loader.setenv("kern.smp.disabled", "1")
178 loader.setenv("hw.ata.ata_dma", "0")
179 loader.setenv("hw.ata.atapi_dma", "0")
180 loader.setenv("kern.eventtimer.periodic", "1")
181 loader.setenv("kern.geom.part.check_integrity", "0")
182 loader.setenv("boot_safe", "YES")
184 loader.unsetenv("kern.smp.disabled")
185 loader.unsetenv("hw.ata.ata_dma")
186 loader.unsetenv("hw.ata.atapi_dma")
187 loader.unsetenv("kern.eventtimer.periodic")
188 loader.unsetenv("kern.geom.part.check_integrity")
189 loader.unsetenv("boot_safe")
195 -- Clear the kernel cache on config changes, autodetect might have
196 -- changed or if we've switched boot environments then we could have
197 -- a new kernel set.
206 local default_kernel = loader.getenv("kernel")
207 local v = loader.getenv("kernels")
208 local autodetect = loader.getenv("kernels_autodetect") or ""
230 -- Do not attempt to autodetect if underlying filesystem
231 -- do not support directory listing (e.g. tftp, http)
232 if not lfs.attributes("/boot", "mode") then
234 loader.setenv("kernels_autodetect", "NO")
237 -- Base whether we autodetect kernels or not on a loader.conf(5)
238 -- setting, kernels_autodetect. If it's set to 'yes', we'll add
239 -- any kernels we detect based on the criteria described.
247 -- Automatically detect other bootable kernel directories using a
248 -- heuristic. Any directory in /boot that contains an ordinary file
249 -- named "kernel" is considered eligible.
261 elseif lfs.attributes(fname, "mode") ~= "directory" then
265 if lfs.attributes(fname .. "/kernel", "mode") ~= "file" then
280 -- If we found more than one kernel, prune the "kernel" specified kernel
281 -- off of the list if it wasn't found during traversal. If we didn't
282 -- actually find any kernels, we just assume that they know what they're
283 -- doing and leave it alone.
299 return loader.getenv("zfs_be_active")
303 local bootenv_count = tonumber(loader.getenv(bootenv_list .. "_count"))
313 -- Currently selected bootenv is always first/default
314 -- On the rewinded list the bootenv may not exists
326 for curenv_idx = 0, bootenv_count - 1 do
327 curenv = loader.getenv(bootenv_list .. "[" .. curenv_idx .. "]")
338 return loader.getenv("zpool_checkpoint") ~= nil
349 for curenv_idx = 0, bootenv_count - 1 do
350 local curenv = loader.getenv("bootenvs_check[" .. curenv_idx .. "]")
356 return loader.getenv("bootenvs_check[0]")
373 if (loader.getenv("entropy_efi_seed") or "no"):lower() == "yes" then
374 local seedsize = loader.getenv("entropy_efi_seed_size") or "2048"
375 loader.perform("efi-seed-entropy " .. seedsize)
388 -- loadelf() only if we've not already loaded a kernel
389 if loader.getenv("kernelname") == nil then
393 loader.perform(composeLoaderCmd("autoboot", argstr))
397 -- loadelf() only if we've not already loaded a kernel
398 if loader.getenv("kernelname") == nil then
402 loader.perform(composeLoaderCmd("boot", argstr))
406 if not loader.has_feature then
407 -- Loader too old, no feature support
408 return nil, "No feature support in loaded loader"
411 return loader.has_feature(name)
415 local single_user = loader.getenv("boot_single")
420 local efiver = loader.getenv("efi-version")
426 local c = loader.getenv("currdev")
435 local c = loader.getenv("console")
440 if loader.getenv("screen.depth") ~= nil then
448 local c = loader.getenv("console")
450 -- serial console is comconsole, but also userboot.
451 -- userboot is there, because we have no way to know
452 -- if the user terminal can draw unicode box chars or not.
461 local s = loader.getenv("boot_serial")
466 local m = loader.getenv("boot_multicons")
473 -- Is the menu skipped in the environment in which we've booted?
475 return string.lower(loader.getenv("beastie_disable") or "") == "yes"
478 -- This may be a better candidate for a 'utility' module.
491 -- XXX This should go away if we get the table lib into shape for importing.
492 -- As of now, it requires some 'os' functions, so we'll implement this in lua
493 -- for our uses
495 -- Shouldn't reasonably happen
504 -- This is not a cheap operation
507 new_tbl[k - 1] = v
515 if loader.getenv("boot_multicons") ~= nil then
516 if loader.getenv("boot_serial") ~= nil then
522 if loader.getenv("boot_serial") ~= nil then
531 if loader.getenv("boot_multicons") ~= nil then
532 if loader.getenv("boot_serial") ~= nil then
533 loader.unsetenv("boot_serial")
535 loader.unsetenv("boot_multicons")
536 loader.setenv("boot_serial", "YES")
539 if loader.getenv("boot_serial") ~= nil then
540 loader.unsetenv("boot_serial")
542 loader.setenv("boot_multicons", "YES")
543 loader.setenv("boot_serial", "YES")
548 -- The graphical-enabled loaders have unicode drawing character support. The
549 -- text-only ones do not. We check the old and new bindings for term_drawrect as
550 -- a proxy for unicode support, which will work on older boot loaders as well
551 -- as be future proof for when we remove the old binding. This also abstracts
552 -- out the test to one spot in case we start to export this notion more directly.
554 return gfx.term_drawrect ~= nil or loader.term_drawrect ~= nil
557 -- Sanity check the boot loader revision
558 -- Loaders with version 3.0 have everything that we need without backwards
559 -- compatible hacks. Warn users that still have old versions to upgrade so
560 -- that we can remove the backwards compatible hacks in the future since
561 -- they have been there a long time.
565 return loader.version == nil or loader.version < loader_major * 1000
572 print("***** BOOT LOADER IS TOO OLD. PLEASE UPGRADE. *****")