libpayload: configs: Add new config.featuretest to broaden CI
[coreboot.git] / util / board_status / go / src / main / board_status.go
blobc52b60f8f7b59b4ffed1d1ef8c70a77ddcb8c26c
1 package main
3 import (
4 "cbfs"
5 "cbtables"
6 "flag"
7 "fmt"
8 "io/ioutil"
9 "kconfig"
10 "log"
11 "os"
12 "os/exec"
15 var ClobberDir = flag.Bool("clobber", false, "Clobber temporary output when finished. Useful for debugging.")
17 func RunAndSave(output string, name string, arg ...string) {
18 cmd := exec.Command(name, arg...)
20 f, err := os.Create(output)
21 if err != nil {
22 log.Fatal(err)
25 cmd.Stdout = f
26 cmd.Stderr = f
28 err = cmd.Start()
29 if err != nil {
30 log.Fatal(err)
32 cmd.Wait()
35 /* Missing features: serial, upload, ssh */
37 func main() {
38 flag.Parse()
40 cb, err := cbfs.OpenROM()
41 if err != nil {
42 log.Fatal(err)
44 config, err := cb.GetFile("config")
45 if err != nil {
46 log.Fatal(err)
48 revision, err := cb.GetFile("revision")
49 if err != nil {
50 log.Fatal(err)
53 parsedConfig := kconfig.ParseKConfig(config)
54 mainboardDir := kconfig.UnQuote(parsedConfig["CONFIG_MAINBOARD_DIR"])
56 tempDir, err := ioutil.TempDir("", "coreboot_board_status")
57 if err != nil {
58 log.Fatal(err)
61 tbl, err := cbtables.Open()
62 if err != nil {
63 log.Fatal(err)
66 taggedVersion, err := tbl.GetVersion()
67 if err != nil {
68 log.Fatal(err)
70 versionTimestamp, err := tbl.GetVersionTimestamp()
71 if err != nil {
72 log.Fatal(err)
74 timestampFormated := versionTimestamp.UTC().Format("2006-01-02T15:04:05Z")
75 outputDir := tempDir + "/" + mainboardDir + "/" + taggedVersion + "/" + timestampFormated
76 os.MkdirAll(outputDir, 0755)
77 fmt.Printf("Temporarily placing output in %s\n", outputDir)
78 cf, err := os.Create(outputDir + "/cbfs.txt")
79 if err != nil {
80 log.Fatal(err)
82 defer cf.Close()
83 fmt.Fprintf(cf, "%v", cb)
85 cf, err = os.Create(outputDir + "/config.txt")
86 if err != nil {
87 log.Fatal(err)
89 defer cf.Close()
90 cf.Write(config)
92 cf, err = os.Create(outputDir + "/revision.txt")
93 if err != nil {
94 log.Fatal(err)
96 defer cf.Close()
97 cf.Write(revision)
99 RunAndSave(outputDir+"/kernel_log.txt", "dmesg")
101 cons, lost, err := tbl.GetConsole()
102 if err != nil {
103 log.Fatal(err)
106 cf, err = os.Create(outputDir + "/coreboot_console.txt")
107 if err != nil {
108 log.Fatal(err)
110 defer cf.Close()
111 cf.Write(cons)
112 switch lost {
113 case 0:
114 case 1:
115 fmt.Fprintf(cf, "\none byte lost\n")
116 default:
117 fmt.Fprintf(cf, "\n%d bytes lost\n", lost)
119 timest, err := tbl.GetTimestamps()
120 if err != nil {
121 log.Fatal(err)
124 ts, err := os.Create(outputDir + "/coreboot_timestamps.txt")
125 if err != nil {
126 log.Fatal(err)
128 defer ts.Close()
129 fmt.Fprintf(ts, "%v", timest)
131 if *ClobberDir {
132 os.RemoveAll(tempDir)