Skip to content

Commit

Permalink
Merge branch 'main' into displaycommand
Browse files Browse the repository at this point in the history
  • Loading branch information
rminnich authored Sep 17, 2024
2 parents 45cd859 + 41e39fd commit 6df8aef
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
go: ['1.21', '1.22', '1.23']
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-latest]
name: lint
runs-on: ${{ matrix.os }}
steps:
Expand Down
11 changes: 11 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
linters:
disable-all: true
enable:
- staticcheck
- stylecheck

linters-settings:
staticcheck:
checks: ["all", "-SA1019"]
stylecheck:
checks: ["all", "-ST1003", "-ST1012", "-ST1016"]
6 changes: 3 additions & 3 deletions cmds/create-ffs/create-ffs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ var (
version = flag.String("version", "1.0", "File version")
guidString = flag.String("guid", "", "File GUID")
depex = flag.String("depex", "", "Space or comma separated protocol guid dependencies or TRUE")
compress = flag.Bool("compress", false, "Wrap section data in a compressed section")
auto = flag.Bool("auto", false, "Attempt to determine section types from file extensions")

printf = func(string, ...interface{}) {}
)
Expand Down Expand Up @@ -169,7 +167,9 @@ func main() {
mainSection := &uefi.Section{}
mainSection.SetType(secType)
mainSection.SetBuf(secData)
mainSection.GenSecHeader()
// It is not clear why the author felt it was OK to ignore
// the error.
_ = mainSection.GenSecHeader()
file.Sections = append(file.Sections, mainSection)
printf("selected section type: %v", mainSection.Header.Type)

Expand Down
6 changes: 5 additions & 1 deletion cmds/fittool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
package main

import (
"log"

"github.com/jessevdk/go-flags"

"github.com/linuxboot/fiano/cmds/fittool/commands"
Expand Down Expand Up @@ -67,5 +69,7 @@ func main() {
}

// parse arguments and execute the appropriate command
flagsParser.Parse()
if _, err := flagsParser.Parse(); err != nil {
log.Fatal(err)
}
}
7 changes: 4 additions & 3 deletions pkg/amd/apcb/apcb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"bytes"
"encoding/binary"
"fmt"
"io/ioutil"
"io"
"os"
"path"
"testing"

Expand Down Expand Up @@ -111,7 +112,7 @@ func findToken(tokenID TokenID, tokens []Token) *Token {
}

func getFile(filename string) ([]byte, error) {
compressedImage, err := ioutil.ReadFile(path.Join("testdata", filename))
compressedImage, err := os.ReadFile(path.Join("testdata", filename))
if err != nil {
return nil, fmt.Errorf("failed to read firmware image: %w", err)
}
Expand All @@ -121,7 +122,7 @@ func getFile(filename string) ([]byte, error) {
return nil, fmt.Errorf("unable to create an xz reader for a cached image: %w", err)
}

decompressedImage, err := ioutil.ReadAll(r)
decompressedImage, err := io.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("unable to decompress the image: %w", err)
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/bytes/is_zero_filled_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@
package bytes

import (
"reflect"
"unsafe"
)

// IsZeroFilled returns true if b consists of zeros only.
func IsZeroFilled(b []byte) bool {
hdr := (*reflect.SliceHeader)((unsafe.Pointer)(&b))
data := unsafe.Pointer(hdr.Data)
length := hdr.Len
length := len(b)
if length == 0 {
return true
}
var data = unsafe.Pointer(&b[0])

if uintptr(data)&0x07 != 0 {
// the data is not aligned, fallback to a simple way
Expand Down
2 changes: 1 addition & 1 deletion pkg/cbfs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,5 @@ func (f *File) Decompress() ([]byte, error) {
compressor := compression.LZ4{}
return compressor.Decode(f.FData)
}
return nil, fmt.Errorf("Unknown compression")
return nil, fmt.Errorf("unknown compression")
}
10 changes: 5 additions & 5 deletions pkg/cbfs/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewImage(rs io.ReadSeeker) (*Image, error) {
// ReadSeeker on a []byte.
b, err := io.ReadAll(rs)
if err != nil {
return nil, fmt.Errorf("ReadAll: %v", err)
return nil, fmt.Errorf("failed to read: %w", err)
}
in := bytes.NewReader(b)
f, m, err := fmap.Read(in)
Expand All @@ -53,7 +53,7 @@ func NewImage(rs io.ReadSeeker) (*Image, error) {
}
}
if i.Area == nil {
return nil, fmt.Errorf("No CBFS in fmap")
return nil, fmt.Errorf("no CBFS in fmap")
}
r := io.NewSectionReader(in, int64(i.Area.Offset), int64(i.Area.Size))

Expand Down Expand Up @@ -89,7 +89,7 @@ func NewImage(rs io.ReadSeeker) (*Image, error) {
}
Debug("Segment: %v", s)
if err := s.Read(bytes.NewReader(f.FData)); err != nil {
return nil, fmt.Errorf("Reading %#x byte subheader, type %v: %v", len(f.FData), f.Type, err)
return nil, fmt.Errorf("reading %#x byte subheader, type %v: %w", len(f.FData), f.Type, err)
}
Debug("Segment was readable")
i.Segs = append(i.Segs, s)
Expand Down Expand Up @@ -120,15 +120,15 @@ func (i *Image) Update() error {
return err
}
if _, err := b.Write(s.GetFile().Attr); err != nil {
return fmt.Errorf("Writing attr to cbfs record for %v: %v", s, err)
return fmt.Errorf("writing attr to cbfs record for %v: %w", s, err)
}
if err := s.Write(&b); err != nil {
return err
}
// This error should not happen but we need to check just in case.
end := uint32(len(b.Bytes())) + s.GetFile().RecordStart
if end > i.Area.Size {
return fmt.Errorf("Region [%#x, %#x] outside of CBFS [%#x, %#x]", s.GetFile().RecordStart, end, s.GetFile().RecordStart, i.Area.Size)
return fmt.Errorf("region [%#x, %#x] outside of CBFS [%#x, %#x]", s.GetFile().RecordStart, end, s.GetFile().RecordStart, i.Area.Size)
}

Debug("Copy %s %d bytes to i.Data[%d]", s.GetFile().Type.String(), len(b.Bytes()), i.Area.Offset+s.GetFile().RecordStart)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cbfs/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (p *PayloadRecord) Read(in io.ReadSeeker) error {
// Seek to offset (after the header); the remainder is the actual payload.
offset, err := in.Seek(0, io.SeekCurrent)
if err != nil {
return fmt.Errorf("Finding location in stream: %v", err)
return fmt.Errorf("finding location in stream: %w", err)
}
bodySize := int64(p.Size) - offset
Debug("Payload size: %v, body size: %v, offset: %v", p.Size, bodySize, offset)
Expand Down
5 changes: 2 additions & 3 deletions pkg/intel/metadata/fit/ent_startup_ac_module_entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ package fit

import (
"bytes"
"crypto/rand"
"encoding/binary"
"math/rand"
"testing"

"github.com/stretchr/testify/require"
)

func randBytes(size uint) []byte {
rand.Seed(0)
b := make([]byte, int(size))
rand.Read(b)
_, _ = rand.Read(b)
return b
}

Expand Down
20 changes: 10 additions & 10 deletions pkg/intel/microcode/microcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,26 @@ func ParseIntelMicrocode(r io.Reader) (*Microcode, error) {
var m Microcode

if err := binary.Read(r, binary.LittleEndian, &m.Header); err != nil {
return nil, fmt.Errorf("Failed to read header: %v", err)
return nil, fmt.Errorf("failed to read header: %w", err)
}

// Sanitychecks
if getTotalSize(m.Header) < getDataSize(m.Header)+uint32(binary.Size(Header{})) {
return nil, fmt.Errorf("Bad data file size")
return nil, fmt.Errorf("bad data file size")
}
if m.HeaderLoaderRevision != 1 || m.HeaderVersion != 1 {
return nil, fmt.Errorf("Invalid version or revision")
return nil, fmt.Errorf("invalid version or revision")
}
if getDataSize(m.Header)%4 > 0 {
return nil, fmt.Errorf("Data size not 32bit aligned")
return nil, fmt.Errorf("data size not 32bit aligned")
}
if getTotalSize(m.Header)%4 > 0 {
return nil, fmt.Errorf("Total size not 32bit aligned")
return nil, fmt.Errorf("total size not 32bit aligned")
}
// Read data
m.Data = make([]byte, getDataSize(m.Header))
if err := binary.Read(r, binary.LittleEndian, &m.Data); err != nil {
return nil, fmt.Errorf("Failed to read data: %v", err)
return nil, fmt.Errorf("failed to read data: %w", err)
}

// Calculcate checksum
Expand All @@ -123,7 +123,7 @@ func ParseIntelMicrocode(r io.Reader) (*Microcode, error) {
checksum += data
}
if checksum != 0 {
return nil, fmt.Errorf("Checksum is not null: %#x", checksum)
return nil, fmt.Errorf("checksum is not null: %#x", checksum)
}

if getTotalSize(m.Header) <= getDataSize(m.Header)+uint32(binary.Size(Header{})) {
Expand All @@ -132,12 +132,12 @@ func ParseIntelMicrocode(r io.Reader) (*Microcode, error) {

// Read extended header
if err := binary.Read(r, binary.LittleEndian, &m.ExtSigTable); err != nil {
return nil, fmt.Errorf("Failed to read extended sig table: %v", err)
return nil, fmt.Errorf("failed to read extended sig table: %w", err)
}
for i := uint32(0); i < m.ExtSigTable.Count; i++ {
var signature ExtendedSignature
if err := binary.Read(r, binary.LittleEndian, &signature); err != nil {
return nil, fmt.Errorf("Failed to read extended signature: %v", err)
return nil, fmt.Errorf("failed to read extended signature: %w", err)
}
m.ExtendedSignatures = append(m.ExtendedSignatures, signature)
}
Expand All @@ -160,7 +160,7 @@ func ParseIntelMicrocode(r io.Reader) (*Microcode, error) {
checksum += data
}
if checksum != 0 {
return nil, fmt.Errorf("Extended header checksum is not null: %#x", checksum)
return nil, fmt.Errorf("extended header checksum is not null: %#x", checksum)
}

return &m, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/uefi/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ type ThreeUint8 [3]uint8

func (t *ThreeUint8) UnmarshalJSON(b []byte) error {
if copy(t[:], b) == 0 {
return fmt.Errorf("Cannot unmarshal 3 uint8 from %v\n", b)
return fmt.Errorf("cannot unmarshal 3 uint8 from %v", b)
}
return nil
}
Expand Down

0 comments on commit 6df8aef

Please sign in to comment.