-
Notifications
You must be signed in to change notification settings - Fork 47
/
ent_boot_policy_manifest.go
54 lines (42 loc) · 1.8 KB
/
ent_boot_policy_manifest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2017-2021 the LinuxBoot Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package fit
import (
"bytes"
"fmt"
"io"
"github.com/linuxboot/fiano/pkg/intel/metadata/manifest/bootpolicy"
)
// EntryBootPolicyManifestRecord represents a FIT entry of type "Boot Policy Manifest" (0x0C)
type EntryBootPolicyManifestRecord struct{ EntryBase }
var _ EntryCustomGetDataSegmentSizer = (*EntryBootPolicyManifestRecord)(nil)
func (entry *EntryBootPolicyManifestRecord) CustomGetDataSegmentSize(firmware io.ReadSeeker) (uint64, error) {
return uint64(entry.Headers.Size.Uint32()), nil
}
var _ EntryCustomRecalculateHeaderser = (*EntryBootPolicyManifestRecord)(nil)
// CustomRecalculateHeaders recalculates metadata to be consistent with data.
// For example, it fixes checksum, data size, entry type and so on.
func (entry *EntryBootPolicyManifestRecord) CustomRecalculateHeaders() error {
mostCommonRecalculateHeadersOfEntry(entry)
entry.Headers.Size.SetUint32(uint32(len(entry.DataSegmentBytes)))
return nil
}
// ParseData creates EntryKeyManifestRecord from EntryKeyManifest
func (entry *EntryBootPolicyManifestRecord) ParseData() (*bootpolicy.Manifest, error) {
var bpManifest bootpolicy.Manifest
_, err := bpManifest.ReadFrom(bytes.NewReader(entry.DataSegmentBytes))
if err != nil {
return nil, fmt.Errorf("failed to parse KeyManifest, err: %v", err)
}
return &bpManifest, nil
}
// ParseBootPolicyManifest returns a boot policy manifest if it was able to
// parse one.
func (table Table) ParseBootPolicyManifest(firmware []byte) (*bootpolicy.Manifest, error) {
hdr := table.First(EntryTypeBootPolicyManifest)
if hdr == nil {
return nil, ErrNotFound{}
}
return hdr.GetEntry(firmware).(*EntryBootPolicyManifestRecord).ParseData()
}