-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.lua
More file actions
39 lines (33 loc) · 991 Bytes
/
utils.lua
File metadata and controls
39 lines (33 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
lfs = require('lfs')
local utils = {}
-- Looks in 'dir' for a file name starting with 'prefix'
-- Returns the first match
function utils.find_file(dir, prefix)
assert(dir and dir ~= '', 'invalid folder')
assert(prefix and prefix ~= '', 'invalid prefix')
for entry in lfs.dir(dir) do
if string.match(entry, prefix) then
return dir .. '/' .. entry
end
end
end
-- load device tree overlay (.dtbo file from /lib/firmware)
function utils.load_devtree(dtbo)
local sys_path = '/sys/devices'
local fname = utils.find_file(sys_path, 'bone_capemgr.')
if fname then
fname = fname .. '/slots'
else
return nil
end
local fh = assert(io.open(fname, 'w'))
fh:write(dtbo)
fh:close()
return true
end
-- onloading overlays seems to be broken. It causes kernel panics.
-- So, Im gonna implement this some other time
function utils.unload_devicetree(devtree)
return nil, "not implemented"
end
return utils