github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/cmds/exp/fdtdump/fdtdump.go (about) 1 // Copyright 2019 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // fdtdump prints a readable version of Flattened Device Tree or dtb. 6 // 7 // Synopsis: 8 // 9 // fdtdump [-json] FILE 10 // 11 // Options: 12 // 13 // -json: Print json with base64 encoded values. 14 package main 15 16 import ( 17 "encoding/json" 18 "flag" 19 "fmt" 20 "log" 21 "os" 22 23 "github.com/mvdan/u-root-coreutils/pkg/dt" 24 ) 25 26 var asJSON = flag.Bool("json", false, "Print json with base64 encoded values.") 27 28 func main() { 29 flag.Parse() 30 31 if flag.NArg() != 1 { 32 log.Fatalf("usage: %s [-json] FILE", os.Args[0]) 33 } 34 35 // Open and parse Device Tree. 36 f, err := os.Open(flag.Arg(0)) 37 if err != nil { 38 log.Fatal(err) 39 } 40 defer f.Close() 41 fdt, err := dt.ReadFDT(f) 42 if err != nil { 43 log.Fatal(err) 44 } 45 46 if *asJSON { 47 out, err := json.MarshalIndent(fdt, "", " ") 48 if err != nil { 49 log.Fatal(err) 50 } 51 fmt.Println(string(out)) 52 } else { 53 if err := fdt.PrintDTS(os.Stdout); err != nil { 54 log.Fatalf("error printing dts: %v", err) 55 } 56 } 57 }