github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/pkg/smbios/entry.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 ) 10 11 func calcChecksum(data []byte, skipIndex int) uint8 { 12 var cs uint8 13 for i, b := range data { 14 if i == skipIndex { 15 continue 16 } 17 cs += b 18 } 19 return uint8(0x100 - int(cs)) 20 } 21 22 // ParseEntry parses SMBIOS 32 or 64-bit entrypoint structure. 23 func ParseEntry(data []byte) (*Entry32, *Entry64, error) { 24 // Entry is either 32 or 64-bit, try them both. 25 var e32 Entry32 26 if err32 := e32.UnmarshalBinary(data); err32 != nil { 27 var e64 Entry64 28 if err64 := e64.UnmarshalBinary(data); err64 != nil { 29 return nil, nil, fmt.Errorf("%s / %s", err32, err64) 30 } 31 return nil, &e64, nil 32 } 33 return &e32, nil, nil 34 }