From ed5370ebde4b4fff8adba9d4514d9107a862e363 Mon Sep 17 00:00:00 2001 From: "Ronald G. Minnich" Date: Mon, 16 Sep 2024 10:31:15 -0700 Subject: [PATCH] gofmt, clean up some test messages Signed-off-by: Ronald G. Minnich --- cmds/fmap/fmap.go | 32 +++++----- cmds/glzma/glzma.go | 12 ++-- cmds/guid2english/main.go | 21 ++++--- cmds/utk/utk.go | 77 +++++++++++++------------ integration/utk_test.go | 13 ++--- pkg/bytes/is_zero_filled_other.go | 1 + pkg/cbfs/microcode.go | 4 +- pkg/cbfs/spd.go | 4 +- pkg/cbfs/types.go | 7 ++- pkg/guid2english/transformer.go | 6 +- pkg/intel/metadata/cbnt/key.go | 4 +- pkg/intel/metadata/fit/calc_offset.go | 15 +++-- pkg/intel/metadata/fit/entry_headers.go | 10 ++-- pkg/intel/metadata/fit/entry_type.go | 2 +- pkg/uefi/visitor.go | 26 ++++----- pkg/visitors/cli.go | 3 +- scripts/checklicenses/checklicenses.go | 4 +- 17 files changed, 128 insertions(+), 113 deletions(-) diff --git a/cmds/fmap/fmap.go b/cmds/fmap/fmap.go index 5b3f75cc..34f98134 100644 --- a/cmds/fmap/fmap.go +++ b/cmds/fmap/fmap.go @@ -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 ( diff --git a/cmds/glzma/glzma.go b/cmds/glzma/glzma.go index a28af5b7..d86a499d 100644 --- a/cmds/glzma/glzma.go +++ b/cmds/glzma/glzma.go @@ -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 ( diff --git a/cmds/guid2english/main.go b/cmds/guid2english/main.go index 12432152..faae7e00 100644 --- a/cmds/guid2english/main.go +++ b/cmds/guid2english/main.go @@ -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 ( diff --git a/cmds/utk/utk.go b/cmds/utk/utk.go index 6fc50b67..44a89526 100644 --- a/cmds/utk/utk.go +++ b/cmds/utk/utk.go @@ -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 ( diff --git a/integration/utk_test.go b/integration/utk_test.go index bacf0ef4..a70d5470 100644 --- a/integration/utk_test.go +++ b/integration/utk_test.go @@ -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) @@ -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) } }) diff --git a/pkg/bytes/is_zero_filled_other.go b/pkg/bytes/is_zero_filled_other.go index 0257b186..62905aa2 100644 --- a/pkg/bytes/is_zero_filled_other.go +++ b/pkg/bytes/is_zero_filled_other.go @@ -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) diff --git a/pkg/cbfs/microcode.go b/pkg/cbfs/microcode.go index 531dbaa7..cbee2c9b 100644 --- a/pkg/cbfs/microcode.go +++ b/pkg/cbfs/microcode.go @@ -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 @@ -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 } diff --git a/pkg/cbfs/spd.go b/pkg/cbfs/spd.go index 3e484a7f..a8efedd2 100644 --- a/pkg/cbfs/spd.go +++ b/pkg/cbfs/spd.go @@ -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 @@ -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 } diff --git a/pkg/cbfs/types.go b/pkg/cbfs/types.go index b6cb7f53..b06a2e0d 100644 --- a/pkg/cbfs/types.go +++ b/pkg/cbfs/types.go @@ -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 ( diff --git a/pkg/guid2english/transformer.go b/pkg/guid2english/transformer.go index 7e345a62..6ccb706f 100644 --- a/pkg/guid2english/transformer.go +++ b/pkg/guid2english/transformer.go @@ -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 } diff --git a/pkg/intel/metadata/cbnt/key.go b/pkg/intel/metadata/cbnt/key.go index 7dcb7bbb..4b700592 100644 --- a/pkg/intel/metadata/cbnt/key.go +++ b/pkg/intel/metadata/cbnt/key.go @@ -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 { @@ -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 { diff --git a/pkg/intel/metadata/fit/calc_offset.go b/pkg/intel/metadata/fit/calc_offset.go index 161db779..37434e97 100644 --- a/pkg/intel/metadata/fit/calc_offset.go +++ b/pkg/intel/metadata/fit/calc_offset.go @@ -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 @@ -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 @@ -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 } diff --git a/pkg/intel/metadata/fit/entry_headers.go b/pkg/intel/metadata/fit/entry_headers.go index 049f81c5..59c821c8 100644 --- a/pkg/intel/metadata/fit/entry_headers.go +++ b/pkg/intel/metadata/fit/entry_headers.go @@ -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 { @@ -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. diff --git a/pkg/intel/metadata/fit/entry_type.go b/pkg/intel/metadata/fit/entry_type.go index 099abd32..29c62f84 100644 --- a/pkg/intel/metadata/fit/entry_type.go +++ b/pkg/intel/metadata/fit/entry_type.go @@ -15,7 +15,7 @@ import ( // registered in the FIT table. type EntryType uint8 -//noinspection GoSnakeCaseUsage +// noinspection GoSnakeCaseUsage const ( EntryTypeFITHeaderEntry = EntryType(0x00) EntryTypeMicrocodeUpdateEntry = EntryType(0x01) diff --git a/pkg/uefi/visitor.go b/pkg/uefi/visitor.go index a8f2f4ea..7b02e3e5 100644 --- a/pkg/uefi/visitor.go +++ b/pkg/uefi/visitor.go @@ -8,22 +8,22 @@ package uefi // Typically, the Visit function contains a type switch for the different // firmware types and a default case. For example: // -// func (v *Example) Visit(f uefi.Firmware) error { -// switch f := f.(type) { +// func (v *Example) Visit(f uefi.Firmware) error { +// switch f := f.(type) { // -// case *uefi.File: -// fmt.Println("f is a file") -// return f.ApplyChildren(v) // Children are recursed over +// case *uefi.File: +// fmt.Println("f is a file") +// return f.ApplyChildren(v) // Children are recursed over // -// case *uefi.Section: -// fmt.Println("f is a section") -// return nil // Children are not visited +// case *uefi.Section: +// fmt.Println("f is a section") +// return nil // Children are not visited // -// default: -// // The default action is to recurse over children. -// return f.ApplyChildren(v) -// } -// } +// default: +// // The default action is to recurse over children. +// return f.ApplyChildren(v) +// } +// } type Visitor interface { // Run wraps Visit. Additionally, it performs some setup and teardown // tasks. As a consumer of the visitor, Run is typically the function diff --git a/pkg/visitors/cli.go b/pkg/visitors/cli.go index 446135ab..4246ba5e 100644 --- a/pkg/visitors/cli.go +++ b/pkg/visitors/cli.go @@ -77,7 +77,8 @@ func ExecuteCLI(f uefi.Firmware, v []uefi.Visitor) error { // ListCLI prints out the help entries in the visitor struct // as a newline-separated string in the form: -// name: help +// +// name: help func ListCLI() string { var s string names := []string{} diff --git a/scripts/checklicenses/checklicenses.go b/scripts/checklicenses/checklicenses.go index 4d18ae3a..8f140ecf 100644 --- a/scripts/checklicenses/checklicenses.go +++ b/scripts/checklicenses/checklicenses.go @@ -3,8 +3,8 @@ // license that can be found in the LICENSE file. // Run with `go run checklicenses.go`. This script has one drawback: -// - It does not correct the licenses; it simply outputs a list of files which -// do not conform and returns 1 if the list is non-empty. +// - It does not correct the licenses; it simply outputs a list of files which +// do not conform and returns 1 if the list is non-empty. package main import (