github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/pkg/dt/fdt_linux.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  // Package dt contains utilities for device tree reading on Linux.
     6  package dt
     7  
     8  import (
     9  	"io"
    10  )
    11  
    12  const sysfsFDT = "/sys/firmware/fdt"
    13  
    14  // LoadFDT loads a flattened device tree from current running system.
    15  //
    16  // It first tries to load it from given io.ReaderAt, then from
    17  // that passed-in file name. If there are not passed-in file names,
    18  // it will try sysfsFDT.
    19  //
    20  // BUGS:
    21  // It is a bit clunky due to its origins; in the original version it
    22  // even had a race. hopefully we can deprecate it in a future u-root
    23  // release.
    24  func LoadFDT(dtb io.ReaderAt, names ...string) (*FDT, error) {
    25  	f := []FDTReader{}
    26  	if dtb != nil {
    27  		f = append(f, WithReaderAt(dtb))
    28  	}
    29  	if len(names) == 0 {
    30  		f = append(f, WithFileName(sysfsFDT))
    31  	} else {
    32  		for _, n := range names {
    33  			f = append(f, WithFileName(n))
    34  		}
    35  	}
    36  	return New(f...)
    37  }