github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/pkg/smbios/info_linux.go (about)

     1  // Copyright 2016-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 smbios
     6  
     7  import (
     8  	"fmt"
     9  	"io/ioutil"
    10  	"path/filepath"
    11  )
    12  
    13  // FromSysfs parses SMBIOS info from sysfs tables.
    14  func FromSysfs() (*Info, error) {
    15  	return fromSysfs("/sys/firmware/dmi/tables")
    16  }
    17  
    18  func fromSysfs(sysfsPath string) (*Info, error) {
    19  	entry, err := ioutil.ReadFile(filepath.Join(sysfsPath, "smbios_entry_point"))
    20  	if err != nil {
    21  		return nil, fmt.Errorf("error reading SMBIOS entry data: %v", err)
    22  	}
    23  	data, err := ioutil.ReadFile(filepath.Join(sysfsPath, "DMI"))
    24  	if err != nil {
    25  		return nil, fmt.Errorf("error reading DMI data: %v", err)
    26  	}
    27  	return ParseInfo(entry, data)
    28  }