From owner-svn-soc-all@FreeBSD.ORG Sat Jul 26 00:02:33 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 649C2DAE for ; Sat, 26 Jul 2014 00:02:33 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 504202D50 for ; Sat, 26 Jul 2014 00:02:33 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6Q02XMF041332 for ; Sat, 26 Jul 2014 00:02:33 GMT (envelope-from pedrosouza@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s6Q02WA3041133 for svn-soc-all@FreeBSD.org; Sat, 26 Jul 2014 00:02:32 GMT (envelope-from pedrosouza@FreeBSD.org) Date: Sat, 26 Jul 2014 00:02:32 GMT Message-Id: <201407260002.s6Q02WA3041133@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to pedrosouza@FreeBSD.org using -f From: pedrosouza@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271394 - soc2014/pedrosouza/lua_loader/head/sys/boot/lua MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 Jul 2014 00:02:33 -0000 Author: pedrosouza Date: Sat Jul 26 00:02:32 2014 New Revision: 271394 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271394 Log: Improve kernel loading to match .4th script Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/config.lua soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.c Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/config.lua ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/config.lua Fri Jul 25 23:52:53 2014 (r271393) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/config.lua Sat Jul 26 00:02:32 2014 (r271394) @@ -166,9 +166,10 @@ function config.loadkernel() local flags = loader.getenv("kernel_options") or ""; - + local kernel = loader.getenv("kernel"); - local doload = function (names) + + local try_load = function (names) for name in names:gmatch("([^;]+)%s*;?") do r = loader.perform("load "..flags.." "..name); if r == 0 then @@ -178,19 +179,59 @@ return nil; end; - local envs = {"bootfile", "kernel"}; + local load_bootfile = function() + local bootfile = loader.getenv("bootfile"); + local res = nil; + if bootfile ~= nil then + return try_load(bootfile); + end + print("Kernel loading failed: null bootfile!\n"); + return nil; + end; - for k, v in pairs(envs) do - local names = loader.getenv(v) or ""; - local ret = doload(names); - if ret ~= nil then - print("Kernel '"..ret.."' loaded!\n"); + -- kernel not set, try load from default module_path + if kernel == nil then + local res = load_bootfile(); + + if res ~= nil then + return true; + else + print("Failed to load kernel '"..res.."'\n"); + return false; + end + else + local module_path = loader.getenv("module_path"); + local res = nil; + + -- first try load kernel with module_path = /boot/${kernel} + -- then try load with module_path=${kernel} + local paths = {"/boot/"..kernel, kernel}; + + for k,v in pairs(paths) do + + loader.perform("set module_path="..v); + res = load_bootfile(); + + -- succeeded add path to module_path + if res ~= nil then + loader.perform("set module_path="..v..";"..module_path); + return true; + end + end + + -- failed to load with ${kernel} as a directory + -- try as a file + res = try_load(kernel); + if res ~= nil then return true; + else + print("Failed to load kernel '"..res.."'\n"); + return false; end end - return false; end + function config.load(file) if not file then file = "/boot/defaults/loader.conf"; end Modified: soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.c ============================================================================== --- soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.c Fri Jul 25 23:52:53 2014 (r271393) +++ soc2014/pedrosouza/lua_loader/head/sys/boot/lua/lutils.c Sat Jul 26 00:02:32 2014 (r271394) @@ -343,4 +343,4 @@ } ++f; } -} +} \ No newline at end of file