1088b4f5fSWarner Losh-- 272e39d71SKyle Evans-- SPDX-License-Identifier: BSD-2-Clause-FreeBSD 372e39d71SKyle Evans-- 4088b4f5fSWarner Losh-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org> 5beaafe4fSKyle Evans-- Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org> 6088b4f5fSWarner Losh-- All rights reserved. 7088b4f5fSWarner Losh-- 8088b4f5fSWarner Losh-- Redistribution and use in source and binary forms, with or without 9088b4f5fSWarner Losh-- modification, are permitted provided that the following conditions 10088b4f5fSWarner Losh-- are met: 11088b4f5fSWarner Losh-- 1. Redistributions of source code must retain the above copyright 12088b4f5fSWarner Losh-- notice, this list of conditions and the following disclaimer. 13088b4f5fSWarner Losh-- 2. Redistributions in binary form must reproduce the above copyright 14088b4f5fSWarner Losh-- notice, this list of conditions and the following disclaimer in the 15088b4f5fSWarner Losh-- documentation and/or other materials provided with the distribution. 16088b4f5fSWarner Losh-- 17088b4f5fSWarner Losh-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18088b4f5fSWarner Losh-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19088b4f5fSWarner Losh-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20088b4f5fSWarner Losh-- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21088b4f5fSWarner Losh-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22088b4f5fSWarner Losh-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23088b4f5fSWarner Losh-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24088b4f5fSWarner Losh-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25088b4f5fSWarner Losh-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26088b4f5fSWarner Losh-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27088b4f5fSWarner Losh-- SUCH DAMAGE. 28088b4f5fSWarner Losh-- 29088b4f5fSWarner Losh-- $FreeBSD$ 30088b4f5fSWarner Losh-- 31088b4f5fSWarner Losh 32011eae6cSKyle Evanslocal config = require("config") 33aea262bfSKyle Evanslocal hook = require("hook") 34fa4a2394SKyle Evans 35aedd6be5SKyle Evanslocal core = {} 36088b4f5fSWarner Losh 371613f091SKyle Evanslocal default_safe_mode = false 381613f091SKyle Evanslocal default_single_user = false 391613f091SKyle Evanslocal default_verbose = false 401613f091SKyle Evans 41277f38abSMariusz Zaborskilocal bootenv_list = "bootenvs" 42277f38abSMariusz Zaborski 43322a2dddSKyle Evanslocal function composeLoaderCmd(cmd_name, argstr) 449f71d421SKyle Evans if argstr ~= nil then 45aedd6be5SKyle Evans cmd_name = cmd_name .. " " .. argstr 466d4ed94dSKyle Evans end 47aedd6be5SKyle Evans return cmd_name 486d4ed94dSKyle Evansend 496d4ed94dSKyle Evans 501613f091SKyle Evanslocal function recordDefaults() 511613f091SKyle Evans -- On i386, hint.acpi.0.rsdp will be set before we're loaded. On !i386, 521613f091SKyle Evans -- it will generally be set upon execution of the kernel. Because of 531613f091SKyle Evans -- this, we can't (or don't really want to) detect/disable ACPI on !i386 541613f091SKyle Evans -- reliably. Just set it enabled if we detect it and leave well enough 551613f091SKyle Evans -- alone if we don't. 561613f091SKyle Evans local boot_acpi = core.isSystem386() and core.getACPIPresent(false) 571613f091SKyle Evans local boot_single = loader.getenv("boot_single") or "no" 581613f091SKyle Evans local boot_verbose = loader.getenv("boot_verbose") or "no" 591613f091SKyle Evans default_single_user = boot_single:lower() ~= "no" 601613f091SKyle Evans default_verbose = boot_verbose:lower() ~= "no" 611613f091SKyle Evans 621613f091SKyle Evans if boot_acpi then 631613f091SKyle Evans core.setACPI(true) 641613f091SKyle Evans end 651613f091SKyle Evans core.setSingleUser(default_single_user) 661613f091SKyle Evans core.setVerbose(default_verbose) 671613f091SKyle Evansend 681613f091SKyle Evans 691613f091SKyle Evans 7007faaf78SKyle Evans-- Globals 715beb5507SKyle Evans-- try_include will return the loaded module on success, or false and the error 725beb5507SKyle Evans-- message on failure. 7307faaf78SKyle Evansfunction try_include(module) 74bac5966eSKyle Evans if module:sub(1, 1) ~= "/" then 75366f9979SKyle Evans local lua_path = loader.lua_path 76bac5966eSKyle Evans -- XXX Temporary compat shim; this should be removed once the 77bac5966eSKyle Evans -- loader.lua_path export has sufficiently spread. 78bac5966eSKyle Evans if lua_path == nil then 79bac5966eSKyle Evans lua_path = "/boot/lua" 8007faaf78SKyle Evans end 81bac5966eSKyle Evans module = lua_path .. "/" .. module 82bac5966eSKyle Evans -- We only attempt to append an extension if an absolute path 83bac5966eSKyle Evans -- wasn't specified. This assumes that the caller either wants 84bac5966eSKyle Evans -- to treat this like it would require() and specify just the 85bac5966eSKyle Evans -- base filename, or they know what they're doing as they've 86bac5966eSKyle Evans -- specified an absolute path and we shouldn't impede. 87bac5966eSKyle Evans if module:match(".lua$") == nil then 88bac5966eSKyle Evans module = module .. ".lua" 89bac5966eSKyle Evans end 90bac5966eSKyle Evans end 91bac5966eSKyle Evans if lfs.attributes(module, "mode") ~= "file" then 92bac5966eSKyle Evans return 93bac5966eSKyle Evans end 94bac5966eSKyle Evans 95bac5966eSKyle Evans return dofile(module) 9607faaf78SKyle Evansend 9707faaf78SKyle Evans 98b5746545SKyle Evans-- Module exports 99fe672a15SKyle Evans-- Commonly appearing constants 100aedd6be5SKyle Evanscore.KEY_BACKSPACE = 8 101aedd6be5SKyle Evanscore.KEY_ENTER = 13 102aedd6be5SKyle Evanscore.KEY_DELETE = 127 103fe672a15SKyle Evans 104230061c5SKyle Evans-- Note that this is a decimal representation, despite the leading 0 that in 105230061c5SKyle Evans-- other contexts (outside of Lua) may mean 'octal' 106aedd6be5SKyle Evanscore.KEYSTR_ESCAPE = "\027" 1072bb86aefSKyle Evanscore.KEYSTR_CSI = core.KEYSTR_ESCAPE .. "[" 10873531a2aSRyan Moellercore.KEYSTR_RESET = core.KEYSTR_ESCAPE .. "c" 10939006570SKyle Evans 110aedd6be5SKyle Evanscore.MENU_RETURN = "return" 111aedd6be5SKyle Evanscore.MENU_ENTRY = "entry" 112aedd6be5SKyle Evanscore.MENU_SEPARATOR = "separator" 113aedd6be5SKyle Evanscore.MENU_SUBMENU = "submenu" 114aedd6be5SKyle Evanscore.MENU_CAROUSEL_ENTRY = "carousel_entry" 115a7cf0562SKyle Evans 11604af4229SKyle Evansfunction core.setVerbose(verbose) 11704af4229SKyle Evans if verbose == nil then 11804af4229SKyle Evans verbose = not core.verbose 119088b4f5fSWarner Losh end 120088b4f5fSWarner Losh 12104af4229SKyle Evans if verbose then 122aedd6be5SKyle Evans loader.setenv("boot_verbose", "YES") 123088b4f5fSWarner Losh else 124aedd6be5SKyle Evans loader.unsetenv("boot_verbose") 125088b4f5fSWarner Losh end 12604af4229SKyle Evans core.verbose = verbose 127088b4f5fSWarner Loshend 128088b4f5fSWarner Losh 12904af4229SKyle Evansfunction core.setSingleUser(single_user) 13004af4229SKyle Evans if single_user == nil then 13104af4229SKyle Evans single_user = not core.su 132088b4f5fSWarner Losh end 133088b4f5fSWarner Losh 13404af4229SKyle Evans if single_user then 135aedd6be5SKyle Evans loader.setenv("boot_single", "YES") 136088b4f5fSWarner Losh else 137aedd6be5SKyle Evans loader.unsetenv("boot_single") 138088b4f5fSWarner Losh end 13904af4229SKyle Evans core.su = single_user 140088b4f5fSWarner Loshend 141088b4f5fSWarner Losh 14204af4229SKyle Evansfunction core.getACPIPresent(checking_system_defaults) 143aedd6be5SKyle Evans local c = loader.getenv("hint.acpi.0.rsdp") 1446401094fSKyle Evans 1459f71d421SKyle Evans if c ~= nil then 14604af4229SKyle Evans if checking_system_defaults then 147aedd6be5SKyle Evans return true 1486401094fSKyle Evans end 1496401094fSKyle Evans -- Otherwise, respect disabled if it's set 150aedd6be5SKyle Evans c = loader.getenv("hint.acpi.0.disabled") 1519f71d421SKyle Evans return c == nil or tonumber(c) ~= 1 1526401094fSKyle Evans end 153aedd6be5SKyle Evans return false 1546401094fSKyle Evansend 1556401094fSKyle Evans 15604af4229SKyle Evansfunction core.setACPI(acpi) 15704af4229SKyle Evans if acpi == nil then 15804af4229SKyle Evans acpi = not core.acpi 159088b4f5fSWarner Losh end 160088b4f5fSWarner Losh 16104af4229SKyle Evans if acpi then 162aedd6be5SKyle Evans loader.setenv("acpi_load", "YES") 163aedd6be5SKyle Evans loader.setenv("hint.acpi.0.disabled", "0") 164aedd6be5SKyle Evans loader.unsetenv("loader.acpi_disabled_by_user") 165088b4f5fSWarner Losh else 166aedd6be5SKyle Evans loader.unsetenv("acpi_load") 167aedd6be5SKyle Evans loader.setenv("hint.acpi.0.disabled", "1") 168aedd6be5SKyle Evans loader.setenv("loader.acpi_disabled_by_user", "1") 169088b4f5fSWarner Losh end 17004af4229SKyle Evans core.acpi = acpi 171088b4f5fSWarner Loshend 172088b4f5fSWarner Losh 17304af4229SKyle Evansfunction core.setSafeMode(safe_mode) 17404af4229SKyle Evans if safe_mode == nil then 17504af4229SKyle Evans safe_mode = not core.sm 176088b4f5fSWarner Losh end 17704af4229SKyle Evans if safe_mode then 178aedd6be5SKyle Evans loader.setenv("kern.smp.disabled", "1") 179aedd6be5SKyle Evans loader.setenv("hw.ata.ata_dma", "0") 180aedd6be5SKyle Evans loader.setenv("hw.ata.atapi_dma", "0") 181aedd6be5SKyle Evans loader.setenv("hw.ata.wc", "0") 182aedd6be5SKyle Evans loader.setenv("hw.eisa_slots", "0") 183aedd6be5SKyle Evans loader.setenv("kern.eventtimer.periodic", "1") 184aedd6be5SKyle Evans loader.setenv("kern.geom.part.check_integrity", "0") 185088b4f5fSWarner Losh else 186aedd6be5SKyle Evans loader.unsetenv("kern.smp.disabled") 187aedd6be5SKyle Evans loader.unsetenv("hw.ata.ata_dma") 188aedd6be5SKyle Evans loader.unsetenv("hw.ata.atapi_dma") 189aedd6be5SKyle Evans loader.unsetenv("hw.ata.wc") 190aedd6be5SKyle Evans loader.unsetenv("hw.eisa_slots") 191aedd6be5SKyle Evans loader.unsetenv("kern.eventtimer.periodic") 192aedd6be5SKyle Evans loader.unsetenv("kern.geom.part.check_integrity") 193088b4f5fSWarner Losh end 19404af4229SKyle Evans core.sm = safe_mode 195088b4f5fSWarner Loshend 196088b4f5fSWarner Losh 197aea262bfSKyle Evansfunction core.clearCachedKernels() 19835b0c718SKyle Evans -- Clear the kernel cache on config changes, autodetect might have 19935b0c718SKyle Evans -- changed or if we've switched boot environments then we could have 20035b0c718SKyle Evans -- a new kernel set. 20135b0c718SKyle Evans core.cached_kernels = nil 20235b0c718SKyle Evansend 20335b0c718SKyle Evans 204088b4f5fSWarner Loshfunction core.kernelList() 20535b0c718SKyle Evans if core.cached_kernels ~= nil then 20635b0c718SKyle Evans return core.cached_kernels 20735b0c718SKyle Evans end 20835b0c718SKyle Evans 209aedd6be5SKyle Evans local k = loader.getenv("kernel") 2103f4eb56bSKyle Evans local v = loader.getenv("kernels") 2113889e6cdSKyle Evans local autodetect = loader.getenv("kernels_autodetect") or "" 212088b4f5fSWarner Losh 213aedd6be5SKyle Evans local kernels = {} 214aedd6be5SKyle Evans local unique = {} 215aedd6be5SKyle Evans local i = 0 2169f71d421SKyle Evans if k ~= nil then 217aedd6be5SKyle Evans i = i + 1 218aedd6be5SKyle Evans kernels[i] = k 219aedd6be5SKyle Evans unique[k] = true 220088b4f5fSWarner Losh end 221088b4f5fSWarner Losh 2223f4eb56bSKyle Evans if v ~= nil then 223a5003419SKyle Evans for n in v:gmatch("([^;, ]+)[;, ]?") do 2249f71d421SKyle Evans if unique[n] == nil then 225aedd6be5SKyle Evans i = i + 1 226aedd6be5SKyle Evans kernels[i] = n 227aedd6be5SKyle Evans unique[n] = true 228088b4f5fSWarner Losh end 229088b4f5fSWarner Losh end 2303889e6cdSKyle Evans end 231a108046fSConrad Meyer 2323889e6cdSKyle Evans -- Base whether we autodetect kernels or not on a loader.conf(5) 2333889e6cdSKyle Evans -- setting, kernels_autodetect. If it's set to 'yes', we'll add 2343889e6cdSKyle Evans -- any kernels we detect based on the criteria described. 2353889e6cdSKyle Evans if autodetect:lower() ~= "yes" then 23635b0c718SKyle Evans core.cached_kernels = kernels 23735b0c718SKyle Evans return core.cached_kernels 2383f4eb56bSKyle Evans end 2393f4eb56bSKyle Evans 240a108046fSConrad Meyer -- Automatically detect other bootable kernel directories using a 241a108046fSConrad Meyer -- heuristic. Any directory in /boot that contains an ordinary file 242a108046fSConrad Meyer -- named "kernel" is considered eligible. 243a108046fSConrad Meyer for file in lfs.dir("/boot") do 244aedd6be5SKyle Evans local fname = "/boot/" .. file 245a108046fSConrad Meyer 2469f71d421SKyle Evans if file == "." or file == ".." then 247aedd6be5SKyle Evans goto continue 248a108046fSConrad Meyer end 249a108046fSConrad Meyer 2509f71d421SKyle Evans if lfs.attributes(fname, "mode") ~= "directory" then 251aedd6be5SKyle Evans goto continue 252a108046fSConrad Meyer end 253a108046fSConrad Meyer 2549f71d421SKyle Evans if lfs.attributes(fname .. "/kernel", "mode") ~= "file" then 255aedd6be5SKyle Evans goto continue 256a108046fSConrad Meyer end 257a108046fSConrad Meyer 2589f71d421SKyle Evans if unique[file] == nil then 259aedd6be5SKyle Evans i = i + 1 260aedd6be5SKyle Evans kernels[i] = file 261aedd6be5SKyle Evans unique[file] = true 262a108046fSConrad Meyer end 263a108046fSConrad Meyer 264a108046fSConrad Meyer ::continue:: 265a108046fSConrad Meyer end 26635b0c718SKyle Evans core.cached_kernels = kernels 26735b0c718SKyle Evans return core.cached_kernels 268088b4f5fSWarner Loshend 269088b4f5fSWarner Losh 2707efc058fSKyle Evansfunction core.bootenvDefault() 2717efc058fSKyle Evans return loader.getenv("zfs_be_active") 2727efc058fSKyle Evansend 2737efc058fSKyle Evans 2747efc058fSKyle Evansfunction core.bootenvList() 275277f38abSMariusz Zaborski local bootenv_count = tonumber(loader.getenv(bootenv_list .. "_count")) 2767efc058fSKyle Evans local bootenvs = {} 2777efc058fSKyle Evans local curenv 2787efc058fSKyle Evans local envcount = 0 2797efc058fSKyle Evans local unique = {} 2807efc058fSKyle Evans 2817efc058fSKyle Evans if bootenv_count == nil or bootenv_count <= 0 then 2827efc058fSKyle Evans return bootenvs 2837efc058fSKyle Evans end 2847efc058fSKyle Evans 2857efc058fSKyle Evans -- Currently selected bootenv is always first/default 286277f38abSMariusz Zaborski -- On the rewinded list the bootenv may not exists 287277f38abSMariusz Zaborski if core.isRewinded() then 288277f38abSMariusz Zaborski curenv = core.bootenvDefaultRewinded() 289277f38abSMariusz Zaborski else 2907efc058fSKyle Evans curenv = core.bootenvDefault() 291277f38abSMariusz Zaborski end 2927efc058fSKyle Evans if curenv ~= nil then 2937efc058fSKyle Evans envcount = envcount + 1 2947efc058fSKyle Evans bootenvs[envcount] = curenv 2957efc058fSKyle Evans unique[curenv] = true 2967efc058fSKyle Evans end 2977efc058fSKyle Evans 2987efc058fSKyle Evans for curenv_idx = 0, bootenv_count - 1 do 299277f38abSMariusz Zaborski curenv = loader.getenv(bootenv_list .. "[" .. curenv_idx .. "]") 3007efc058fSKyle Evans if curenv ~= nil and unique[curenv] == nil then 3017efc058fSKyle Evans envcount = envcount + 1 3027efc058fSKyle Evans bootenvs[envcount] = curenv 3037efc058fSKyle Evans unique[curenv] = true 3047efc058fSKyle Evans end 3057efc058fSKyle Evans end 3067efc058fSKyle Evans return bootenvs 3077efc058fSKyle Evansend 3087efc058fSKyle Evans 309277f38abSMariusz Zaborskifunction core.isCheckpointed() 310277f38abSMariusz Zaborski return loader.getenv("zpool_checkpoint") ~= nil 311277f38abSMariusz Zaborskiend 312277f38abSMariusz Zaborski 313277f38abSMariusz Zaborskifunction core.bootenvDefaultRewinded() 314277f38abSMariusz Zaborski local defname = "zfs:!" .. string.sub(core.bootenvDefault(), 5) 315277f38abSMariusz Zaborski local bootenv_count = tonumber("bootenvs_check_count") 316277f38abSMariusz Zaborski 317277f38abSMariusz Zaborski if bootenv_count == nil or bootenv_count <= 0 then 318277f38abSMariusz Zaborski return defname 319277f38abSMariusz Zaborski end 320277f38abSMariusz Zaborski 321277f38abSMariusz Zaborski for curenv_idx = 0, bootenv_count - 1 do 322*94510c29SKyle Evans local curenv = loader.getenv("bootenvs_check[" .. curenv_idx .. "]") 323277f38abSMariusz Zaborski if curenv == defname then 324277f38abSMariusz Zaborski return defname 325277f38abSMariusz Zaborski end 326277f38abSMariusz Zaborski end 327277f38abSMariusz Zaborski 328277f38abSMariusz Zaborski return loader.getenv("bootenvs_check[0]") 329277f38abSMariusz Zaborskiend 330277f38abSMariusz Zaborski 331277f38abSMariusz Zaborskifunction core.isRewinded() 332277f38abSMariusz Zaborski return bootenv_list == "bootenvs_check" 333277f38abSMariusz Zaborskiend 334277f38abSMariusz Zaborski 335277f38abSMariusz Zaborskifunction core.changeRewindCheckpoint() 336277f38abSMariusz Zaborski if core.isRewinded() then 337277f38abSMariusz Zaborski bootenv_list = "bootenvs" 338277f38abSMariusz Zaborski else 339277f38abSMariusz Zaborski bootenv_list = "bootenvs_check" 340277f38abSMariusz Zaborski end 341277f38abSMariusz Zaborskiend 342277f38abSMariusz Zaborski 343088b4f5fSWarner Loshfunction core.setDefaults() 344aedd6be5SKyle Evans core.setACPI(core.getACPIPresent(true)) 3451613f091SKyle Evans core.setSafeMode(default_safe_mode) 3461613f091SKyle Evans core.setSingleUser(default_single_user) 3471613f091SKyle Evans core.setVerbose(default_verbose) 348088b4f5fSWarner Loshend 349088b4f5fSWarner Losh 3506d4ed94dSKyle Evansfunction core.autoboot(argstr) 351a2a7830eSKyle Evans -- loadelf() only if we've not already loaded a kernel 352a2a7830eSKyle Evans if loader.getenv("kernelname") == nil then 353aedd6be5SKyle Evans config.loadelf() 354a2a7830eSKyle Evans end 355322a2dddSKyle Evans loader.perform(composeLoaderCmd("autoboot", argstr)) 356088b4f5fSWarner Loshend 357088b4f5fSWarner Losh 3586d4ed94dSKyle Evansfunction core.boot(argstr) 359a2a7830eSKyle Evans -- loadelf() only if we've not already loaded a kernel 360a2a7830eSKyle Evans if loader.getenv("kernelname") == nil then 361aedd6be5SKyle Evans config.loadelf() 362a2a7830eSKyle Evans end 363322a2dddSKyle Evans loader.perform(composeLoaderCmd("boot", argstr)) 364088b4f5fSWarner Loshend 365088b4f5fSWarner Losh 366e07fc39cSKyle Evansfunction core.isSingleUserBoot() 367aedd6be5SKyle Evans local single_user = loader.getenv("boot_single") 368aedd6be5SKyle Evans return single_user ~= nil and single_user:lower() == "yes" 369e07fc39cSKyle Evansend 370e07fc39cSKyle Evans 3715f8cfbe1SKyle Evansfunction core.isUEFIBoot() 3725f8cfbe1SKyle Evans local efiver = loader.getenv("efi-version") 3735f8cfbe1SKyle Evans 3745f8cfbe1SKyle Evans return efiver ~= nil 3755f8cfbe1SKyle Evansend 3765f8cfbe1SKyle Evans 3777efc058fSKyle Evansfunction core.isZFSBoot() 3787efc058fSKyle Evans local c = loader.getenv("currdev") 3797efc058fSKyle Evans 3807efc058fSKyle Evans if c ~= nil then 3817efc058fSKyle Evans return c:match("^zfs:") ~= nil 3827efc058fSKyle Evans end 3837efc058fSKyle Evans return false 3847efc058fSKyle Evansend 3857efc058fSKyle Evans 38690a25417SKyle Evansfunction core.isSerialConsole() 38790a25417SKyle Evans local c = loader.getenv("console") 38890a25417SKyle Evans if c ~= nil then 38990a25417SKyle Evans if c:find("comconsole") ~= nil then 39090a25417SKyle Evans return true 39190a25417SKyle Evans end 39290a25417SKyle Evans end 39390a25417SKyle Evans return false 39490a25417SKyle Evansend 39590a25417SKyle Evans 396b140d14bSKyle Evansfunction core.isSerialBoot() 397aedd6be5SKyle Evans local s = loader.getenv("boot_serial") 3989f71d421SKyle Evans if s ~= nil then 399aedd6be5SKyle Evans return true 400088b4f5fSWarner Losh end 401088b4f5fSWarner Losh 402aedd6be5SKyle Evans local m = loader.getenv("boot_multicons") 4039f71d421SKyle Evans if m ~= nil then 404aedd6be5SKyle Evans return true 405088b4f5fSWarner Losh end 406aedd6be5SKyle Evans return false 407088b4f5fSWarner Loshend 408088b4f5fSWarner Losh 409c1ab36f5SKyle Evansfunction core.isSystem386() 4109f71d421SKyle Evans return loader.machine_arch == "i386" 411c1ab36f5SKyle Evansend 412c1ab36f5SKyle Evans 4139937e979SKyle Evans-- Is the menu skipped in the environment in which we've booted? 4149937e979SKyle Evansfunction core.isMenuSkipped() 415b83a355dSKyle Evans return string.lower(loader.getenv("beastie_disable") or "") == "yes" 4169937e979SKyle Evansend 4179937e979SKyle Evans 4185c1b5165SKyle Evans-- This may be a better candidate for a 'utility' module. 419ee4e69f1SKyle Evansfunction core.deepCopyTable(tbl) 420aedd6be5SKyle Evans local new_tbl = {} 4215c1b5165SKyle Evans for k, v in pairs(tbl) do 4229f71d421SKyle Evans if type(v) == "table" then 423ee4e69f1SKyle Evans new_tbl[k] = core.deepCopyTable(v) 4245c1b5165SKyle Evans else 425aedd6be5SKyle Evans new_tbl[k] = v 4265c1b5165SKyle Evans end 4275c1b5165SKyle Evans end 428aedd6be5SKyle Evans return new_tbl 4295c1b5165SKyle Evansend 4305c1b5165SKyle Evans 4316d4ed94dSKyle Evans-- XXX This should go away if we get the table lib into shape for importing. 4326d4ed94dSKyle Evans-- As of now, it requires some 'os' functions, so we'll implement this in lua 4336d4ed94dSKyle Evans-- for our uses 4346d4ed94dSKyle Evansfunction core.popFrontTable(tbl) 4356d4ed94dSKyle Evans -- Shouldn't reasonably happen 4369f71d421SKyle Evans if #tbl == 0 then 437aedd6be5SKyle Evans return nil, nil 4389f71d421SKyle Evans elseif #tbl == 1 then 439aedd6be5SKyle Evans return tbl[1], {} 4406d4ed94dSKyle Evans end 4416d4ed94dSKyle Evans 442aedd6be5SKyle Evans local first_value = tbl[1] 443aedd6be5SKyle Evans local new_tbl = {} 4446d4ed94dSKyle Evans -- This is not a cheap operation 4456d4ed94dSKyle Evans for k, v in ipairs(tbl) do 4469f71d421SKyle Evans if k > 1 then 447aedd6be5SKyle Evans new_tbl[k - 1] = v 4486d4ed94dSKyle Evans end 4496d4ed94dSKyle Evans end 4506d4ed94dSKyle Evans 451aedd6be5SKyle Evans return first_value, new_tbl 4526d4ed94dSKyle Evansend 4536d4ed94dSKyle Evans 4548f3b3610SWarner Loshfunction core.getConsoleName() 4558f3b3610SWarner Losh if loader.getenv("boot_multicons") ~= nil then 4568f3b3610SWarner Losh if loader.getenv("boot_serial") ~= nil then 4578f3b3610SWarner Losh return "Dual (Serial primary)" 4588f3b3610SWarner Losh else 4598f3b3610SWarner Losh return "Dual (Video primary)" 4608f3b3610SWarner Losh end 4618f3b3610SWarner Losh else 4628f3b3610SWarner Losh if loader.getenv("boot_serial") ~= nil then 4638f3b3610SWarner Losh return "Serial" 4648f3b3610SWarner Losh else 4658f3b3610SWarner Losh return "Video" 4668f3b3610SWarner Losh end 4678f3b3610SWarner Losh end 4688f3b3610SWarner Loshend 4698f3b3610SWarner Losh 4708f3b3610SWarner Loshfunction core.nextConsoleChoice() 4718f3b3610SWarner Losh if loader.getenv("boot_multicons") ~= nil then 4728f3b3610SWarner Losh if loader.getenv("boot_serial") ~= nil then 4738f3b3610SWarner Losh loader.unsetenv("boot_serial") 4748f3b3610SWarner Losh else 4758f3b3610SWarner Losh loader.unsetenv("boot_multicons") 4768f3b3610SWarner Losh loader.setenv("boot_serial", "YES") 4778f3b3610SWarner Losh end 4788f3b3610SWarner Losh else 4798f3b3610SWarner Losh if loader.getenv("boot_serial") ~= nil then 4808f3b3610SWarner Losh loader.unsetenv("boot_serial") 4818f3b3610SWarner Losh else 4828f3b3610SWarner Losh loader.setenv("boot_multicons", "YES") 4838f3b3610SWarner Losh loader.setenv("boot_serial", "YES") 4848f3b3610SWarner Losh end 4858f3b3610SWarner Losh end 4868f3b3610SWarner Loshend 4878f3b3610SWarner Losh 4881613f091SKyle EvansrecordDefaults() 489aea262bfSKyle Evanshook.register("config.reloaded", core.clearCachedKernels) 490aedd6be5SKyle Evansreturn core 491