Skip to content

Commit

Permalink
gofmt, clean up some test messages
Browse files Browse the repository at this point in the history
Signed-off-by: Ronald G. Minnich <[email protected]>
  • Loading branch information
rminnich authored and orangecms committed Sep 16, 2024
1 parent 2e510d1 commit ed5370e
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 113 deletions.
32 changes: 17 additions & 15 deletions cmds/fmap/fmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@
// Fmap parses flash maps.
//
// Synopsis:
// fmap checksum [md5|sha1|sha256] FILE
// fmap extract [index|name] FILE
// fmap jget JSONFILE FILE
// fmap jput JSONFILE FILE
// fmap summary FILE
// fmap usage FILE
// fmap verify FILE
//
// fmap checksum [md5|sha1|sha256] FILE
// fmap extract [index|name] FILE
// fmap jget JSONFILE FILE
// fmap jput JSONFILE FILE
// fmap summary FILE
// fmap usage FILE
// fmap verify FILE
//
// Description:
// checksum: Print a checksum using the given hash function.
// extract: Print the i-th area or area name from the flash.
// jget: Write json representation of the fmap to JSONFILE.
// jput: Replace current fmap with json representation in JSONFILE.
// summary: Print a human readable summary.
// usage: Print human readable usage stats.
// verify: Return 1 if the flash map is invalid.
//
// This implementation is based off of https://github.com/dhendrix/flashmap.
// checksum: Print a checksum using the given hash function.
// extract: Print the i-th area or area name from the flash.
// jget: Write json representation of the fmap to JSONFILE.
// jput: Replace current fmap with json representation in JSONFILE.
// summary: Print a human readable summary.
// usage: Print human readable usage stats.
// verify: Return 1 if the flash map is invalid.
//
// This implementation is based off of https://github.com/dhendrix/flashmap.
package main

import (
Expand Down
12 changes: 7 additions & 5 deletions cmds/glzma/glzma.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
// glzma compresses and decompresses in the same manner as EDK2's LzmaCompress.
//
// Synopsis:
// glzma -o OUTPUT_FILE (-d|-e) [-f86] INPUT_FILE
//
// glzma -o OUTPUT_FILE (-d|-e) [-f86] INPUT_FILE
//
// Options:
// -d: decode
// -e: encode
// -f86: Use the x86 branch/call/jump filter. See `man xz` for more information.
// -o OUTPUT_FILE: output file
//
// -d: decode
// -e: encode
// -f86: Use the x86 branch/call/jump filter. See `man xz` for more information.
// -o OUTPUT_FILE: output file
package main

import (
Expand Down
21 changes: 12 additions & 9 deletions cmds/guid2english/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
// guid2english replace GUIDs with their English representation.
//
// Synopsis:
// guid2english [-t TEMPLATE] [FILE]
//
// guid2english [-t TEMPLATE] [FILE]
//
// Options:
// -t TEMPLATE:
// A template used to replace GUIDS. The template can refer to the
// following variables:
// * {{.Guid}}: The GUID being mapped
// * {{.Name}}: The English name of the GUID or "UNKNOWN"
// * {{.IsKnown}}: Set to true when the English name is not known
// The default template is "{{.GUID}} ({{.Name}})".
//
// -t TEMPLATE:
// A template used to replace GUIDS. The template can refer to the
// following variables:
// * {{.Guid}}: The GUID being mapped
// * {{.Name}}: The English name of the GUID or "UNKNOWN"
// * {{.IsKnown}}: Set to true when the English name is not known
// The default template is "{{.GUID}} ({{.Name}})".
//
// Description:
// If FILE is not specified, stdin is used.
//
// If FILE is not specified, stdin is used.
package main

import (
Expand Down
77 changes: 40 additions & 37 deletions cmds/utk/utk.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,55 @@
// The utk command performs operations on a UEFI firmware image.
//
// Synopsis:
// utk BIOS OPERATIONS...
//
// utk BIOS OPERATIONS...
//
// Examples:
// # Dump everything to JSON:
// utk winterfell.rom json
//
// # Dump a single file to JSON (using regex):
// utk winterfell.rom find Shell
// # Dump everything to JSON:
// utk winterfell.rom json
//
// # Dump a single file to JSON (using regex):
// utk winterfell.rom find Shell
//
// # Dump GUIDs and sizes to a compact table:
// utk winterfell.rom table
// # Dump GUIDs and sizes to a compact table:
// utk winterfell.rom table
//
// # Extract everything into a directory:
// utk winterfell.rom extract winterfell/
// # Extract everything into a directory:
// utk winterfell.rom extract winterfell/
//
// # Re-assemble the directory into an image:
// utk winterfell/ save winterfell2.rom
// # Re-assemble the directory into an image:
// utk winterfell/ save winterfell2.rom
//
// # Remove two files by their GUID and replace shell with Linux:
// utk winterfell.rom \
// remove 12345678-9abc-def0-1234-567890abcdef \
// remove 23830293-3029-3823-0922-328328330939 \
// replace_pe32 Shell linux.efi \
// save winterfell2.rom
// # Remove two files by their GUID and replace shell with Linux:
// utk winterfell.rom \
// remove 12345678-9abc-def0-1234-567890abcdef \
// remove 23830293-3029-3823-0922-328328330939 \
// replace_pe32 Shell linux.efi \
// save winterfell2.rom
//
// Operations:
// `json`: Dump the entire parsed image (excluding binary data) as JSON to
// stdout.
// `table`: Dump GUIDs and sizes to a compact table. This is only for human
// consumption and the format may change without notice.
// `find (GUID|NAME)`: Dump the JSON of one or more files. The file is
// found by a regex match to its GUID or name in the UI
// section.
// `remove (GUID|NAME)`: Remove the first file which matches the given GUID
// or NAME. The same matching rules and exit status
// are used as `find`.
// `replace (GUID|NAME) FILE`: Replace the first file which matches the
// given GUID or NAME with the contents of
// FILE. The same matching rules and exit
// status are used as `find`.
// `save FILE`: Save the current state of the image to the give file.
// Remember that operations are applied left-to-right, so only
// the operations to the left are included in the new image.
// `extract DIR`: Extract the BIOS to the given directory. Remember that
// operations are applied left-to-right, so only the
// operations to the left are included in the new image.
//
// `json`: Dump the entire parsed image (excluding binary data) as JSON to
// stdout.
// `table`: Dump GUIDs and sizes to a compact table. This is only for human
// consumption and the format may change without notice.
// `find (GUID|NAME)`: Dump the JSON of one or more files. The file is
// found by a regex match to its GUID or name in the UI
// section.
// `remove (GUID|NAME)`: Remove the first file which matches the given GUID
// or NAME. The same matching rules and exit status
// are used as `find`.
// `replace (GUID|NAME) FILE`: Replace the first file which matches the
// given GUID or NAME with the contents of
// FILE. The same matching rules and exit
// status are used as `find`.
// `save FILE`: Save the current state of the image to the give file.
// Remember that operations are applied left-to-right, so only
// the operations to the left are included in the new image.
// `extract DIR`: Extract the BIOS to the given directory. Remember that
// operations are applied left-to-right, so only the
// operations to the left are included in the new image.
package main

import (
Expand Down
13 changes: 6 additions & 7 deletions integration/utk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,18 @@ func TestExtractAssembleExtract(t *testing.T) {
}
}

t.Logf("walk %q and check against %q", dir1, dir2)
if err := filepath.Walk(dir1, func(n1 string, s1 fs.FileInfo, err error) error {
if err != nil {
return err
}
n2, err := filepath.Rel(dir1, n1)
if err != nil {
return fmt.Errorf("%q: can not get relative to %q:%v", n1, dir1, err)
return fmt.Errorf("filepath.Rel(%q,%q):got %v, want nil", n1, dir1, err)
}
n2 = filepath.Join(dir2, n2)
s2, err := os.Stat(n2)
if err != nil {
return fmt.Errorf("%q: expected it to exist, got %w", n2, err)
return fmt.Errorf("Stat %q: got %w, want nil", n2, err)
}
if s2.IsDir() != s1.IsDir() {
return fmt.Errorf("%q.IsDir() != %q.Isdir:%w", s1, s2, os.ErrInvalid)
Expand All @@ -126,20 +125,20 @@ func TestExtractAssembleExtract(t *testing.T) {
}
d1, err := os.ReadFile(n1)
if err != nil {
return fmt.Errorf("Reading %q:%v", n1, err)
return fmt.Errorf("Reading %q:got %v, want nil", n1, err)
}
d1 = szre.ReplaceAll(d1, []byte{})
d2, err := os.ReadFile(n2)
if err != nil {
return fmt.Errorf("Reading %q:%v", n2, err)
return fmt.Errorf("Reading %q:got %v, want nil", n2, err)
}
d2 = szre.ReplaceAll(d2, []byte{})
if string(d1) != string(d2) {
return fmt.Errorf("%q has value %q; %q has value %q; expected the to be equal:%w", n1, d1, n2, d2, os.ErrInvalid)
return fmt.Errorf("%q(%q) != %q(%q):%w", n1, d1, n2, d2, os.ErrInvalid)
}
return nil
}); err != nil {
t.Fatalf("%q and %q are not equal:%v", dir1, dir2, os.ErrInvalid)
t.Fatalf("%q != %q:%v", dir1, dir2, os.ErrInvalid)
}

})
Expand Down
1 change: 1 addition & 0 deletions pkg/bytes/is_zero_filled_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package bytes

// IsZeroFilled returns true if b consists of zeros only.
//
//go:nosplit
func IsZeroFilled(b []byte) bool {
return isZeroFilledSimple(b)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cbfs/microcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func init() {
}
}

//NewMicrocode returns a ReadWriter interface for the CBFS type TypeMicroCode
// NewMicrocode returns a ReadWriter interface for the CBFS type TypeMicroCode
func NewMicrocode(f *File) (ReadWriter, error) {
rec := &MicrocodeRecord{File: *f}
return rec, nil
Expand All @@ -33,7 +33,7 @@ func (r *MicrocodeRecord) Write(w io.Writer) error {
return Write(w, r.FData)
}

//Header returns a pointer to the corresponding File
// Header returns a pointer to the corresponding File
func (r *MicrocodeRecord) GetFile() *File {
return &r.File
}
4 changes: 2 additions & 2 deletions pkg/cbfs/spd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func init() {
}
}

//NewSPD returns a ReadWriter for the CBFS type TypeSPD
// NewSPD returns a ReadWriter for the CBFS type TypeSPD
func NewSPD(f *File) (ReadWriter, error) {
rec := &SPDRecord{File: *f}
return rec, nil
Expand All @@ -33,7 +33,7 @@ func (r *SPDRecord) Write(w io.Writer) error {
return Write(w, r.FData)
}

//Header returns a pointer to the corresponding File
// Header returns a pointer to the corresponding File
func (r *SPDRecord) GetFile() *File {
return &r.File
}
7 changes: 4 additions & 3 deletions pkg/cbfs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ const (
var Endian = binary.BigEndian

// These are standard component types for well known
// components (i.e - those that coreboot needs to consume.
// Users are welcome to use any other value for their
// components.
//
// components (i.e - those that coreboot needs to consume.
// Users are welcome to use any other value for their
// components.
type FileType uint32

const (
Expand Down
6 changes: 3 additions & 3 deletions pkg/guid2english/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ type Mapper interface {

// TemplateMapper implements mapper using Go's text/template package. The
// template can refer to the following variables:
// * {{.Guid}}: The GUID being mapped
// * {{.Name}}: The English name of the GUID or "UNKNOWN"
// * {{.IsKnown}}: Set to true when the English name is not known
// - {{.Guid}}: The GUID being mapped
// - {{.Name}}: The English name of the GUID or "UNKNOWN"
// - {{.IsKnown}}: Set to true when the English name is not known
type TemplateMapper struct {
tmpl *template.Template
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/intel/metadata/cbnt/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (k *Key) SetPubKey(key crypto.PublicKey) error {
return fmt.Errorf("unexpected key type: %T", key)
}

//PrintBPMPubKey prints the BPM public signing key hash to fuse into the Intel ME
// PrintBPMPubKey prints the BPM public signing key hash to fuse into the Intel ME
func (k *Key) PrintBPMPubKey(bpmAlg Algorithm) error {
buf := new(bytes.Buffer)
if len(k.Data) > 1 {
Expand Down Expand Up @@ -190,7 +190,7 @@ func (k *Key) PrintBPMPubKey(bpmAlg Algorithm) error {
return nil
}

//PrintKMPubKey prints the KM public signing key hash to fuse into the Intel ME
// PrintKMPubKey prints the KM public signing key hash to fuse into the Intel ME
func (k *Key) PrintKMPubKey(kmAlg Algorithm) error {
buf := new(bytes.Buffer)
if len(k.Data) > 1 {
Expand Down
15 changes: 9 additions & 6 deletions pkg/intel/metadata/fit/calc_offset.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import "github.com/linuxboot/fiano/pkg/intel/metadata/fit/consts"
// to BasePhysAddr.
//
// Examples:
// CalculatePhysAddrFromOffset(0x01, 0x2000) == 0xffffe001
// CalculatePhysAddrFromOffset(0x40, 0x2000) == 0xffffe040
//
// CalculatePhysAddrFromOffset(0x01, 0x2000) == 0xffffe001
// CalculatePhysAddrFromOffset(0x40, 0x2000) == 0xffffe040
func CalculatePhysAddrFromOffset(offset uint64, imageSize uint64) uint64 {
startAddr := consts.BasePhysAddr - imageSize
return startAddr + offset
Expand All @@ -23,8 +24,9 @@ func CalculatePhysAddrFromOffset(offset uint64, imageSize uint64) uint64 {
// the SPI chip).
//
// Examples:
// CalculateOffsetFromPhysAddr(0xffffffff, 0x1000) == 0xfff
// CalculateOffsetFromPhysAddr(0xffffffc0, 0x1000) == 0xfc0
//
// CalculateOffsetFromPhysAddr(0xffffffff, 0x1000) == 0xfff
// CalculateOffsetFromPhysAddr(0xffffffc0, 0x1000) == 0xfc0
func CalculateOffsetFromPhysAddr(physAddr uint64, imageSize uint64) uint64 {
startAddr := consts.BasePhysAddr - imageSize
return physAddr - startAddr
Expand All @@ -35,8 +37,9 @@ func CalculateOffsetFromPhysAddr(physAddr uint64, imageSize uint64) uint64 {
// the SPI chip).
//
// Examples:
// CalculateTailOffsetFromPhysAddr(0xffffffff) == 0x01
// CalculateTailOffsetFromPhysAddr(0xffffffc0) == 0x40
//
// CalculateTailOffsetFromPhysAddr(0xffffffff) == 0x01
// CalculateTailOffsetFromPhysAddr(0xffffffc0) == 0x40
func CalculateTailOffsetFromPhysAddr(physAddr uint64) uint64 {
return consts.BasePhysAddr - physAddr
}
10 changes: 5 additions & 5 deletions pkg/intel/metadata/fit/entry_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
// EntryHeaders implements a "FIT Entry Format".
//
// See "Table 1-1" in "1.2 Firmware Interface Table" in "Firmware Interface Table" specification:
// * https://www.intel.com/content/dam/www/public/us/en/documents/guides/fit-bios-specification.pdf
// - https://www.intel.com/content/dam/www/public/us/en/documents/guides/fit-bios-specification.pdf
//
// Descriptions of the fields are adapted descriptions from the document by the link above.
type EntryHeaders struct {
Expand Down Expand Up @@ -220,10 +220,10 @@ func (size SizeM16) Size() uint { return uint(size) << 4 }
func (size SizeM16) String() string { return fmt.Sprintf("0x%x*0x10", uint16(size)) }

// TypeAndIsChecksumValid combines two fields:
// * "C_V" -- Checksum Valid bit. This is a one bit field that indicates,
// whether component has a valid checksum. CPU must ignore
// "Checksum" field, if C_V bit is not set.
// * EntryType (see "entry_type.go").
// - "C_V" -- Checksum Valid bit. This is a one bit field that indicates,
// whether component has a valid checksum. CPU must ignore
// "Checksum" field, if C_V bit is not set.
// - EntryType (see "entry_type.go").
type TypeAndIsChecksumValid uint8

// IsChecksumValid returns bit "C_V" of the FIT entry.
Expand Down
2 changes: 1 addition & 1 deletion pkg/intel/metadata/fit/entry_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// registered in the FIT table.
type EntryType uint8

//noinspection GoSnakeCaseUsage
// noinspection GoSnakeCaseUsage
const (
EntryTypeFITHeaderEntry = EntryType(0x00)
EntryTypeMicrocodeUpdateEntry = EntryType(0x01)
Expand Down
Loading

0 comments on commit ed5370e

Please sign in to comment.