Skip to content

Instantly share code, notes, and snippets.

@juanhuttemann
Last active July 19, 2020 19:00
Show Gist options
  • Save juanhuttemann/dff2a1cc93c349990edf1fb2e7148cdc to your computer and use it in GitHub Desktop.
Save juanhuttemann/dff2a1cc93c349990edf1fb2e7148cdc to your computer and use it in GitHub Desktop.
Access to dimm information
package main
import (
"encoding/binary"
"fmt"
"log"
"github.com/digitalocean/go-smbios/smbios"
)
func formFactorType(ff int) string {
return [...]string{"",
"Other",
"Unknown",
"SIMM",
"SIP",
"Chip",
"DIP",
"ZIP",
"Proprietary Card",
"DIMM",
"TSOP",
"Row of Chips",
"RIMM",
"SODIMM",
"SRIMM",
"FBDIMM"}[ff]
}
func memoryType(mt int) string {
return [...]string{"",
"Other",
"Unknown",
"DRAM",
"EDRAM",
"VRAM",
"SRAM",
"RAM",
"ROM",
"FLASH",
"EEPROM",
"FEPROM",
"EPROM",
"CDRAM",
"3DRAM",
"SDRAM",
"SGRAM",
"RDRAM",
"DDR",
"DDR2",
"DDR2 FB-DIMM",
"Reserved",
"Reserved",
"Reserved",
"DDR3",
"FBD2",
"DDR4",
"LPDDR",
"LPDDR2",
"LPDDR3",
"LPDDR4"}[mt]
}
func main() {
rc, _, err := smbios.Stream()
if err != nil {
log.Fatalf("failed to open stream: %v", err)
}
defer rc.Close()
d := smbios.NewDecoder(rc)
ss, err := d.Decode()
if err != nil {
log.Fatalf("failed to decode structures: %v", err)
}
for _, s := range ss {
if s.Header.Type != 17 {
continue
}
size := int(binary.LittleEndian.Uint16(s.Formatted[8:10]))
bankLocator := s.Strings[0]
if size == 0 {
bankLocator = "empty"
continue
}
if size == 0x7fff {
size = int(binary.LittleEndian.Uint32(s.Formatted[24:28]))
}
manufacturer := s.Strings[1]
serial := s.Strings[2]
assetTag := s.Strings[3]
partNumber := s.Strings[4]
totalWidth := s.Formatted[4]
dataWidth := s.Formatted[6]
formFactorBytes := s.Formatted[10]
memTypeBytes := s.Formatted[14]
memType := memoryType(int(memTypeBytes))
formFactor := formFactorType(int(formFactorBytes))
memSpeed := int(binary.LittleEndian.Uint16(s.Formatted[17:19]))
unit := "KB"
if s.Formatted[9]&0x80 == 0 {
unit = "MB"
}
fmt.Println(bankLocator, size, unit, memType, formFactor, manufacturer, serial, assetTag, partNumber, memSpeed, dataWidth, totalWidth)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment