1*088b4f5fSWarner Losh-- 2*088b4f5fSWarner Losh-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org> 3*088b4f5fSWarner Losh-- All rights reserved. 4*088b4f5fSWarner Losh-- 5*088b4f5fSWarner Losh-- Redistribution and use in source and binary forms, with or without 6*088b4f5fSWarner Losh-- modification, are permitted provided that the following conditions 7*088b4f5fSWarner Losh-- are met: 8*088b4f5fSWarner Losh-- 1. Redistributions of source code must retain the above copyright 9*088b4f5fSWarner Losh-- notice, this list of conditions and the following disclaimer. 10*088b4f5fSWarner Losh-- 2. Redistributions in binary form must reproduce the above copyright 11*088b4f5fSWarner Losh-- notice, this list of conditions and the following disclaimer in the 12*088b4f5fSWarner Losh-- documentation and/or other materials provided with the distribution. 13*088b4f5fSWarner Losh-- 14*088b4f5fSWarner Losh-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15*088b4f5fSWarner Losh-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16*088b4f5fSWarner Losh-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17*088b4f5fSWarner Losh-- ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18*088b4f5fSWarner Losh-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19*088b4f5fSWarner Losh-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20*088b4f5fSWarner Losh-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21*088b4f5fSWarner Losh-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22*088b4f5fSWarner Losh-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23*088b4f5fSWarner Losh-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24*088b4f5fSWarner Losh-- SUCH DAMAGE. 25*088b4f5fSWarner Losh-- 26*088b4f5fSWarner Losh-- $FreeBSD$ 27*088b4f5fSWarner Losh-- 28*088b4f5fSWarner Losh 29*088b4f5fSWarner Loshlocal core = {}; 30*088b4f5fSWarner Losh 31*088b4f5fSWarner Loshfunction core.setVerbose(b) 32*088b4f5fSWarner Losh if (b == nil) then 33*088b4f5fSWarner Losh b = not core.verbose; 34*088b4f5fSWarner Losh end 35*088b4f5fSWarner Losh 36*088b4f5fSWarner Losh if (b == true) then 37*088b4f5fSWarner Losh loader.setenv("boot_verbose", "YES"); 38*088b4f5fSWarner Losh else 39*088b4f5fSWarner Losh loader.unsetenv("boot_verbose"); 40*088b4f5fSWarner Losh end 41*088b4f5fSWarner Losh core.verbose = b; 42*088b4f5fSWarner Loshend 43*088b4f5fSWarner Losh 44*088b4f5fSWarner Loshfunction core.setSingleUser(b) 45*088b4f5fSWarner Losh if (b == nil) then 46*088b4f5fSWarner Losh b = not core.su; 47*088b4f5fSWarner Losh end 48*088b4f5fSWarner Losh 49*088b4f5fSWarner Losh if (b == true) then 50*088b4f5fSWarner Losh loader.setenv("boot_single", "YES"); 51*088b4f5fSWarner Losh else 52*088b4f5fSWarner Losh loader.unsetenv("boot_single"); 53*088b4f5fSWarner Losh end 54*088b4f5fSWarner Losh core.su = b; 55*088b4f5fSWarner Loshend 56*088b4f5fSWarner Losh 57*088b4f5fSWarner Loshfunction core.setACPI(b) 58*088b4f5fSWarner Losh if (b == nil) then 59*088b4f5fSWarner Losh b = not core.acpi; 60*088b4f5fSWarner Losh end 61*088b4f5fSWarner Losh 62*088b4f5fSWarner Losh if (b == true) then 63*088b4f5fSWarner Losh loader.setenv("acpi_load", "YES"); 64*088b4f5fSWarner Losh loader.setenv("hint.acpi.0.disabled", "0"); 65*088b4f5fSWarner Losh loader.unsetenv("loader.acpi_disabled_by_user"); 66*088b4f5fSWarner Losh else 67*088b4f5fSWarner Losh loader.unsetenv("acpi_load"); 68*088b4f5fSWarner Losh loader.setenv("hint.acpi.0.disabled", "1"); 69*088b4f5fSWarner Losh loader.setenv("loader.acpi_disabled_by_user", "1"); 70*088b4f5fSWarner Losh end 71*088b4f5fSWarner Losh core.acpi = b; 72*088b4f5fSWarner Loshend 73*088b4f5fSWarner Losh 74*088b4f5fSWarner Loshfunction core.setSafeMode(b) 75*088b4f5fSWarner Losh if (b == nil) then 76*088b4f5fSWarner Losh b = not core.sm; 77*088b4f5fSWarner Losh end 78*088b4f5fSWarner Losh if (b == true) then 79*088b4f5fSWarner Losh loader.setenv("kern.smp.disabled", "1"); 80*088b4f5fSWarner Losh loader.setenv("hw.ata.ata_dma", "0"); 81*088b4f5fSWarner Losh loader.setenv("hw.ata.atapi_dma", "0"); 82*088b4f5fSWarner Losh loader.setenv("hw.ata.wc", "0"); 83*088b4f5fSWarner Losh loader.setenv("hw.eisa_slots", "0"); 84*088b4f5fSWarner Losh loader.setenv("kern.eventtimer.periodic", "1"); 85*088b4f5fSWarner Losh loader.setenv("kern.geom.part.check_integrity", "0"); 86*088b4f5fSWarner Losh else 87*088b4f5fSWarner Losh loader.unsetenv("kern.smp.disabled"); 88*088b4f5fSWarner Losh loader.unsetenv("hw.ata.ata_dma"); 89*088b4f5fSWarner Losh loader.unsetenv("hw.ata.atapi_dma"); 90*088b4f5fSWarner Losh loader.unsetenv("hw.ata.wc"); 91*088b4f5fSWarner Losh loader.unsetenv("hw.eisa_slots"); 92*088b4f5fSWarner Losh loader.unsetenv("kern.eventtimer.periodic"); 93*088b4f5fSWarner Losh loader.unsetenv("kern.geom.part.check_integrity"); 94*088b4f5fSWarner Losh end 95*088b4f5fSWarner Losh core.sm = b; 96*088b4f5fSWarner Loshend 97*088b4f5fSWarner Losh 98*088b4f5fSWarner Loshfunction core.kernelList() 99*088b4f5fSWarner Losh local k = loader.getenv("kernel"); 100*088b4f5fSWarner Losh local v = loader.getenv("kernels") or ""; 101*088b4f5fSWarner Losh 102*088b4f5fSWarner Losh local kernels = {}; 103*088b4f5fSWarner Losh local i = 0; 104*088b4f5fSWarner Losh if k ~= nil then 105*088b4f5fSWarner Losh i = i + 1; 106*088b4f5fSWarner Losh kernels[i] = k; 107*088b4f5fSWarner Losh end 108*088b4f5fSWarner Losh 109*088b4f5fSWarner Losh for n in v:gmatch("([^; ]+)[; ]?") do 110*088b4f5fSWarner Losh if n ~= k then 111*088b4f5fSWarner Losh i = i + 1; 112*088b4f5fSWarner Losh kernels[i] = n; 113*088b4f5fSWarner Losh end 114*088b4f5fSWarner Losh end 115*088b4f5fSWarner Losh return kernels; 116*088b4f5fSWarner Loshend 117*088b4f5fSWarner Losh 118*088b4f5fSWarner Loshfunction core.setDefaults() 119*088b4f5fSWarner Losh core.setACPI(true); 120*088b4f5fSWarner Losh core.setSafeMode(false); 121*088b4f5fSWarner Losh core.setSingleUser(false); 122*088b4f5fSWarner Losh core.setVerbose(false); 123*088b4f5fSWarner Loshend 124*088b4f5fSWarner Losh 125*088b4f5fSWarner Loshfunction core.autoboot() 126*088b4f5fSWarner Losh loader.perform("autoboot"); 127*088b4f5fSWarner Loshend 128*088b4f5fSWarner Losh 129*088b4f5fSWarner Loshfunction core.boot() 130*088b4f5fSWarner Losh loader.perform("boot"); 131*088b4f5fSWarner Loshend 132*088b4f5fSWarner Losh 133*088b4f5fSWarner Loshfunction core.bootserial() 134*088b4f5fSWarner Losh local c = loader.getenv("console"); 135*088b4f5fSWarner Losh 136*088b4f5fSWarner Losh if c ~= nil then 137*088b4f5fSWarner Losh if c:find("comconsole") ~= nil then 138*088b4f5fSWarner Losh return true; 139*088b4f5fSWarner Losh end 140*088b4f5fSWarner Losh end 141*088b4f5fSWarner Losh 142*088b4f5fSWarner Losh local s = loader.getenv("boot_serial"); 143*088b4f5fSWarner Losh if s ~= nil then 144*088b4f5fSWarner Losh return true; 145*088b4f5fSWarner Losh end 146*088b4f5fSWarner Losh 147*088b4f5fSWarner Losh local m = loader.getenv("boot_multicons"); 148*088b4f5fSWarner Losh if m ~= nil then 149*088b4f5fSWarner Losh return true; 150*088b4f5fSWarner Losh end 151*088b4f5fSWarner Losh return false; 152*088b4f5fSWarner Loshend 153*088b4f5fSWarner Losh 154*088b4f5fSWarner Loshreturn core 155