socsvn commit: r271394 - soc2014/pedrosouza/lua_loader/head/sys/boot/lua

pedrosouza at FreeBSD.org pedrosouza at FreeBSD.org
Sat Jul 26 00:02:33 UTC 2014


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


More information about the svn-soc-all mailing list