Skip to content

Commit fd15d1b

Browse files
orangecmsArthurHeymansrminnichChriMarMePatrickRudolph
committed
Import cbfs from github.com/linuxboot/cbfs
Co-authored-by: Arthur Heymans <arthur@aheymans.xyz> Co-authored-by: Ronald G. Minnich <rminnich@gmail.com> Co-authored-by: Daniel Maslowski <info@orangecms.org> Co-authored-by: ron minnich <rminnich@gmail.com> Co-authored-by: Christopher Meis <christopher.meis@9elements.com> Co-authored-by: Patrick Rudolph <patrick.rudolph@9elements.com> Signed-off-by: Daniel Maslowski <info@orangecms.org>
1 parent 9a1898c commit fd15d1b

18 files changed

Lines changed: 1502 additions & 0 deletions

cmds/cbfs/cbfs.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"log"
7+
8+
"github.com/linuxboot/cbfs/pkg/cbfs"
9+
flag "github.com/spf13/pflag"
10+
)
11+
12+
var debug = flag.BoolP("debug", "d", false, "enable debug prints")
13+
14+
func main() {
15+
flag.Parse()
16+
17+
if *debug {
18+
cbfs.Debug = log.Printf
19+
}
20+
21+
a := flag.Args()
22+
if len(a) != 2 {
23+
log.Fatal("arg count")
24+
}
25+
26+
i, err := cbfs.Open(a[0])
27+
if err != nil {
28+
log.Fatal(err)
29+
}
30+
31+
switch a[1] {
32+
case "list":
33+
fmt.Printf("%s", i.String())
34+
case "json":
35+
j, err := json.MarshalIndent(i, " ", " ")
36+
if err != nil {
37+
log.Fatal(err)
38+
}
39+
fmt.Printf("%s", string(j))
40+
default:
41+
log.Fatal("?")
42+
}
43+
44+
}

pkg/cbfs/bootblock.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package cbfs
2+
3+
import (
4+
"io"
5+
"log"
6+
)
7+
8+
func init() {
9+
if err := RegisterFileReader(&SegReader{Type: TypeBootBlock, Name: "CBFSBootBlock", New: NewBootBlock}); err != nil {
10+
log.Fatal(err)
11+
}
12+
}
13+
14+
func NewBootBlock(f *File) (ReadWriter, error) {
15+
r := &BootBlockRecord{File: *f}
16+
Debug("Got header %s", r.String())
17+
return r, nil
18+
}
19+
20+
func (r *BootBlockRecord) Read(in io.ReadSeeker) error {
21+
return nil
22+
}
23+
24+
func (r *BootBlockRecord) String() string {
25+
return recString(r.File.Name, r.RecordStart, r.Type.String(), r.Size, "none")
26+
}
27+
28+
func (r *BootBlockRecord) Write(w io.Writer) error {
29+
return Write(w, r.FData)
30+
}
31+
32+
func (r *BootBlockRecord) GetFile() *File {
33+
return &r.File
34+
}

pkg/cbfs/cbfs.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package cbfs
2+
3+
import "os"
4+
5+
func Open(n string) (*Image, error) {
6+
f, err := os.Open(n)
7+
if err != nil {
8+
return nil, err
9+
}
10+
11+
return NewImage(f)
12+
}

pkg/cbfs/cmoslayout.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package cbfs
2+
3+
import (
4+
"io"
5+
"log"
6+
)
7+
8+
func init() {
9+
if err := RegisterFileReader(&SegReader{Type: TypeCMOSLayout, Name: "CBFSCMOSLayout", New: NewCMOSLayout}); err != nil {
10+
log.Fatal(err)
11+
}
12+
}
13+
14+
func NewCMOSLayout(f *File) (ReadWriter, error) {
15+
rec := &CMOSLayoutRecord{File: *f}
16+
return rec, nil
17+
}
18+
19+
func (r *CMOSLayoutRecord) Read(in io.ReadSeeker) error {
20+
return nil
21+
}
22+
23+
func (r *CMOSLayoutRecord) String() string {
24+
return recString(r.File.Name, r.RecordStart, r.Type.String(), r.Size, "none")
25+
}
26+
27+
func (r *CMOSLayoutRecord) Write(w io.Writer) error {
28+
return Write(w, r.FData)
29+
}
30+
31+
func (r *CMOSLayoutRecord) GetFile() *File {
32+
return &r.File
33+
}

pkg/cbfs/data.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package cbfs
2+
3+
var (
4+
Master = []byte{
5+
/*0000*/ 0x5f, 0x5f, 0x46, 0x4d, 0x41, 0x50, 0x5f, 0x5f, 0x01, 0x01, 0x00, 0x00, 0xfc, 0xff, 0x00, 0x00, //|__FMAP__........|
6+
/*0010*/ 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x46, 0x4c, 0x41, 0x53, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, //|......FLASH.....|
7+
/*0020*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //|................|
8+
/*0030*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, //|................|
9+
/*0040*/ 0x42, 0x49, 0x4f, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //|BIOS............|
10+
/*0050*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //|................|
11+
/*0060*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x46, 0x4d, 0x41, 0x50, 0x00, 0x00, //|..........FMAP..|
12+
/*0070*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //|................|
13+
/*0080*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, //|................|
14+
/*0090*/ 0x00, 0xfe, 0x03, 0x00, 0x43, 0x4f, 0x52, 0x45, 0x42, 0x4f, 0x4f, 0x54, 0x00, 0x00, 0x00, 0x00, //|....COREBOOT....|
15+
/*00a0*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //|................|
16+
/*00b0*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
17+
/*00c0*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
18+
/*00d0*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
19+
/*00e0*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
20+
/*00f0*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
21+
/*0100*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
22+
/*0110*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
23+
/*0120*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
24+
/*0130*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
25+
/*0140*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
26+
/*0150*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
27+
/*0160*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
28+
/*0170*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
29+
/*0180*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
30+
/*0190*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
31+
/*01a0*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
32+
/*01b0*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
33+
/*01c0*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
34+
/*01d0*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
35+
/*01e0*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
36+
/*01f0*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
37+
/*0200*/ 0x4c, 0x41, 0x52, 0x43, 0x48, 0x49, 0x56, 0x45, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x02, //|LARCHIVE... ....|
38+
/*0210*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x63, 0x62, 0x66, 0x73, 0x20, 0x6d, 0x61, 0x73, //|.......8cbfs mas|
39+
/*0220*/ 0x74, 0x65, 0x72, 0x20, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //|ter header......|
40+
/*0230*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x52, 0x42, 0x43, 0x31, 0x31, 0x31, 0x32, //|........ORBC1112|
41+
/*0240*/ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x02, 0x00, //|...........@....|
42+
/*0250*/ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
43+
/*0260*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
44+
/*0270*/ 0x4c, 0x41, 0x52, 0x43, 0x48, 0x49, 0x56, 0x45, 0x00, 0x00, 0x00, 0x20, 0xff, 0xff, 0xff, 0xff, //|LARCHIVE..w.....|
45+
/*0280*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //|.......(........|
46+
/*0290*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
47+
/*02a0*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
48+
/*02b0*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //|................|
49+
50+
}
51+
ListOutput = `FMAP REGIOName: COREBOOT
52+
Name Offset Type Size Comp
53+
cbfs master header 0x0 cbfs header 32 none
54+
fallback/romstage 0x80 stage 15812 none
55+
fallback/ramstage 0x3ec0 stage 52417 none
56+
config 0x10bc0 raw 355 none
57+
revision 0x10d80 raw 576 none
58+
cmos_layout.bin 0x11000 cmos_layout 548 none
59+
fallback/dsdt.aml 0x11280 raw 6952 none
60+
fallback/payload 0x12e00 simple elf 28 none
61+
(empty) 0x12e80 null 183192 none
62+
bootblock 0x3fa40 bootblock 880 none
63+
`
64+
)

pkg/cbfs/empty.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package cbfs
2+
3+
import (
4+
"io"
5+
"log"
6+
)
7+
8+
func init() {
9+
if err := RegisterFileReader(&SegReader{Type: TypeDeleted, Name: "CBFSEmpty", New: NewEmptyRecord}); err != nil {
10+
log.Fatal(err)
11+
}
12+
if err := RegisterFileReader(&SegReader{Type: TypeDeleted2, Name: "CBFSEmpty", New: NewEmptyRecord}); err != nil {
13+
log.Fatal(err)
14+
}
15+
}
16+
17+
func NewEmptyRecord(f *File) (ReadWriter, error) {
18+
r := &EmptyRecord{File: *f}
19+
Debug("Got header %v", r.String())
20+
r.Type = TypeDeleted2
21+
r.Attr = make([]byte, 16)
22+
r.FData = ffbyte(f.Size)
23+
return r, nil
24+
}
25+
26+
func (r *EmptyRecord) Read(in io.ReadSeeker) error {
27+
return nil
28+
}
29+
30+
func (r *EmptyRecord) String() string {
31+
return recString("(empty)", r.RecordStart, r.Type.String(), r.Size, "none")
32+
}
33+
34+
func (r *EmptyRecord) Write(w io.Writer) error {
35+
return Write(w, r.FData)
36+
}
37+
38+
func (r *EmptyRecord) GetFile() *File {
39+
return &r.File
40+
}

0 commit comments

Comments
 (0)