github.com/linuxboot/fiano@v1.2.0/pkg/uefi/flashmastersection.go (about) 1 // Copyright 2018 the LinuxBoot 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 uefi 6 7 import ( 8 "bytes" 9 "encoding/binary" 10 "fmt" 11 ) 12 13 // FlashMasterSectionSize is the size in bytes of the FlashMaster section 14 const FlashMasterSectionSize = 12 15 16 // RegionPermissions holds the read/write permissions for other regions. 17 type RegionPermissions struct { 18 ID uint16 19 Read uint8 20 Write uint8 21 } 22 23 func (r *RegionPermissions) String() string { 24 return fmt.Sprintf("RegionPermissions{ID=%v, Read=0x%x, Write=0x%x}", 25 r.ID, r.Read, r.Write) 26 } 27 28 // FlashMasterSection holds all the IDs and read/write permissions for other regions 29 // This controls whether the bios region can read/write to the ME for example. 30 type FlashMasterSection struct { 31 BIOS RegionPermissions 32 ME RegionPermissions 33 GBE RegionPermissions 34 } 35 36 func (m *FlashMasterSection) String() string { 37 return fmt.Sprintf("FlashMasterSection{Bios %v, Me %v, Gbe %v}", 38 m.BIOS, m.ME, m.GBE) 39 } 40 41 // NewFlashMasterSection parses a sequence of bytes and returns a FlashMasterSection 42 // object, if a valid one is passed, or an error 43 func NewFlashMasterSection(buf []byte) (*FlashMasterSection, error) { 44 if len(buf) < FlashMasterSectionSize { 45 return nil, fmt.Errorf("flash Master Section size too small: expected %v bytes, got %v", 46 FlashMasterSectionSize, 47 len(buf), 48 ) 49 } 50 var master FlashMasterSection 51 reader := bytes.NewReader(buf) 52 if err := binary.Read(reader, binary.LittleEndian, &master); err != nil { 53 return nil, err 54 } 55 return &master, nil 56 }