github.com/linuxboot/fiano@v1.2.0/pkg/intel/me/structures.go (about) 1 // Copyright 2021 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 me 6 7 import ( 8 "fmt" 9 "strings" 10 ) 11 12 // LegacyFlashPartitionTableHeader describes the old flash partition table header 13 // in Intel ME binaries. 14 type LegacyFlashPartitionTableHeader struct { 15 Padding [16]byte // 16 zeros 16 Marker [4]byte // Always $FPT 17 NumFptEntries uint32 18 HeaderVersion uint8 19 EntryVersion uint8 20 HeaderLength uint8 // Usually 0x30 21 HeaderChecksum uint8 22 TicksToAdd uint16 23 TokensToAdd uint16 24 UMASize uint32 25 Flags uint32 26 } 27 28 func (h LegacyFlashPartitionTableHeader) String() string { 29 var b strings.Builder 30 b.WriteString("Flash partition table:\n") 31 fmt.Fprintf(&b, " Entries : %d\n", h.NumFptEntries) 32 fmt.Fprintf(&b, " HeaderVersion : 0x%x\n", h.HeaderVersion) 33 fmt.Fprintf(&b, " EntryVersion : 0x%x\n", h.EntryVersion) 34 fmt.Fprintf(&b, " HeaderLength : 0x%x\n", h.HeaderLength) 35 fmt.Fprintf(&b, " HeaderChecksum: 0x%x\n", h.HeaderChecksum) 36 fmt.Fprintf(&b, " TicksToAdd : 0x%x\n", h.TicksToAdd) 37 fmt.Fprintf(&b, " TokensToAdd : 0x%x\n", h.TokensToAdd) 38 fmt.Fprintf(&b, " UMASize : 0x%x\n", h.UMASize) 39 fmt.Fprintf(&b, " Flags : 0x%x\n", h.Flags) 40 41 return b.String() 42 } 43 44 // FlashPartitionTableHeader describes the new flash partition table header 45 // in Intel ME binaries. 46 type FlashPartitionTableHeader struct { 47 Marker [4]byte // Always $FPT 48 NumFptEntries uint32 49 HeaderVersion uint8 // Only support 2.0 50 EntryVersion uint8 51 HeaderLength uint8 // Usually 0x20 52 HeaderChecksum uint8 53 TicksToAdd uint16 54 TokensToAdd uint16 55 UMASizeOrReserved uint32 56 FlashLayoutOrFlags uint32 57 // Not Present in ME version 7 58 FitcMajor uint16 59 FitcMinor uint16 60 FitcHotfix uint16 61 FitcBuild uint16 62 } 63 64 func (h FlashPartitionTableHeader) String() string { 65 var b strings.Builder 66 67 b.WriteString("Flash partition table:\n") 68 fmt.Fprintf(&b, " Entries : %d\n", h.NumFptEntries) 69 fmt.Fprintf(&b, " HeaderVersion : 0x%x\n", h.HeaderVersion) 70 fmt.Fprintf(&b, " EntryVersion : 0x%x\n", h.EntryVersion) 71 fmt.Fprintf(&b, " HeaderLength : 0x%x\n", h.HeaderLength) 72 fmt.Fprintf(&b, " HeaderChecksum : 0x%x\n", h.HeaderChecksum) 73 fmt.Fprintf(&b, " TicksToAdd : 0x%x\n", h.TicksToAdd) 74 fmt.Fprintf(&b, " TokensToAdd : 0x%x\n", h.TokensToAdd) 75 fmt.Fprintf(&b, " UMASizeOrReserved : 0x%x\n", h.UMASizeOrReserved) 76 fmt.Fprintf(&b, " FlashLayoutOrFlags : 0x%x\n", h.FlashLayoutOrFlags) 77 fmt.Fprintf(&b, " Fitc Version : %d.%d.%d.%d\n", h.FitcMajor, h.FitcMinor, h.FitcHotfix, h.FitcBuild) 78 79 return b.String() 80 } 81 82 type name [4]byte 83 84 func (n *name) String() string { 85 return string(n[:]) 86 } 87 88 // FlashPartitionTableEntry describes information of a flash partition table entry. 89 type FlashPartitionTableEntry struct { 90 Name name 91 Owner name 92 Offset uint32 93 Length uint32 94 StartTokens uint32 95 MaxTokens uint32 96 ScratchSectors uint32 97 Flags uint32 98 } 99 100 func (e FlashPartitionTableEntry) String() string { 101 var b strings.Builder 102 b.WriteString("Flash partition entry:\n") 103 fmt.Fprintf(&b, " Name : %s\n", e.Name.String()) 104 fmt.Fprintf(&b, " Owner : %s\n", e.Owner.String()) 105 fmt.Fprintf(&b, " Offset : 0x%x\n", e.Offset) 106 fmt.Fprintf(&b, " Length : 0x%x\n", e.Length) 107 fmt.Fprintf(&b, " StartTokens : 0x%x\n", e.StartTokens) 108 fmt.Fprintf(&b, " MaxTokens : 0x%x\n", e.MaxTokens) 109 fmt.Fprintf(&b, " ScratchSectors: 0x%x\n", e.ScratchSectors) 110 fmt.Fprintf(&b, " Flags : 0x%x\n", e.Flags) 111 112 if e.Flags>>24 == 0xff { 113 b.WriteString(" Valid : No\n") 114 } else { 115 b.WriteString(" Valid : yes\n") 116 } 117 if e.Flags&1 > 0 { 118 b.WriteString(" Partition : Data\n") 119 } else { 120 b.WriteString(" Partition : Code\n") 121 } 122 123 return b.String() 124 } 125 126 // IntelME abstracts the ME/CSME/SPS firmware found on intel platforms 127 type IntelME struct { 128 hdr *FlashPartitionTableHeader 129 legacyhdr *LegacyFlashPartitionTableHeader 130 legacy bool 131 partitions []FlashPartitionTableEntry 132 }