forked from usbarmory/armory-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdtb.go
54 lines (42 loc) · 1.07 KB
/
dtb.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
54
// https://github.com/f-secure-foundry/armory-boot
//
// Copyright (c) F-Secure Corporation
// https://foundry.f-secure.com
//
// Use of this source code is governed by the license
// that can be found in the LICENSE file.
package main
import (
"bytes"
"github.com/u-root/u-root/pkg/dt"
)
func fixupDeviceTree(dtb []byte, cmdline string) (dtbFixed []byte, err error) {
fdt, err := dt.ReadFDT(bytes.NewReader(dtb))
if err != nil {
return
}
for _, node := range fdt.RootNode.Children {
if node.Name == "chosen" {
bootargs := dt.Property{
Name: "bootargs",
Value: []byte(cmdline + "\x00"),
}
node.Properties = append(node.Properties, bootargs)
}
// temporary fixup until newer dtbs with correct device_type
// information are released
if node.Name == "memory" {
device_type := dt.Property{
Name: "device_type",
Value: []byte("memory" + "\x00"),
}
node.Properties = append(node.Properties, device_type)
}
}
dtbBuf := new(bytes.Buffer)
_, err = fdt.Write(dtbBuf)
if err != nil {
panic(err)
}
return dtbBuf.Bytes(), nil
}