forked from platinasystems/fdt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfdt_linux.go
53 lines (46 loc) · 960 Bytes
/
fdt_linux.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Linux-specific: Read /proc/device-tree
// +build linux
package fdt
import (
"io/ioutil"
"os"
)
func (n *Node) parseDirectory(dir string) (err error) {
files, err := ioutil.ReadDir(dir)
if err != nil {
return err
}
for _, file := range files {
if file.IsDir() {
c := &Node{}
c.Name = file.Name()
c.Depth = n.Depth + 1
if n.Children == nil {
n.Children = make(map[string]*Node)
}
n.Children[c.Name] = c
c.parseDirectory(dir + string(os.PathSeparator) + c.Name)
} else {
if n.Properties == nil {
n.Properties = make(map[string][]byte)
}
v, err := ioutil.ReadFile(dir + string(os.PathSeparator) +
file.Name())
if err == nil {
n.Properties[file.Name()] = v
}
}
}
return nil
}
func (t *Tree) ParseKernel() (err error) {
var n *Node;
if n = t.RootNode; n == nil {
n = &Node{}
n.Name = "/"
n.Depth = 1
t.RootNode = n;
}
err = n.parseDirectory("/proc/device-tree")
return err
}