Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMD + Intel analyze commands #351

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions cmds/amdana/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"

amd "github.com/linuxboot/fiano/pkg/amd/manifest"
)

const (
// This needed a look at the image; how can we fully automate it?
mapping = 0xff000000
)

// this is only for Go - would be 5 lines inline in JS, thanks...
type image []byte

func (f image) ImageBytes() []byte {
return []byte(f)
}

func (f image) PhysAddrToOffset(physAddr uint64) uint64 {
return physAddr - mapping
}

func (f image) OffsetToPhysAddr(offset uint64) uint64 {
return offset + mapping
}

func main() {
flag.Parse()
args := flag.Args()

var path string

if len(args) > 0 {
path = args[0]
data, err := ioutil.ReadFile(path)
if err != nil {
log.Fatal(err)
}
// We could also use this, but its mapping wouldn't work with some images
// FIXME: figure out those mappings
// var amdfw amd.FirmwareImage = data
var amdfw image = data
fw, err := amd.NewAMDFirmware(amdfw)
if err != nil {
log.Fatal(err)
}
a := fw.PSPFirmware()
j, err := json.MarshalIndent(a, "", " ")
if err != nil {
log.Fatal(err)
}
fmt.Printf(string(j))

Check failure on line 58 in cmds/amdana/main.go

View workflow job for this annotation

GitHub Actions / lint (1.21, macos-latest)

SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)

Check failure on line 58 in cmds/amdana/main.go

View workflow job for this annotation

GitHub Actions / lint (1.22, ubuntu-latest)

SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)

Check failure on line 58 in cmds/amdana/main.go

View workflow job for this annotation

GitHub Actions / lint (1.22, macos-latest)

SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)

Check failure on line 58 in cmds/amdana/main.go

View workflow job for this annotation

GitHub Actions / lint (1.23, macos-latest)

SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)
}
}
61 changes: 61 additions & 0 deletions cmds/intelana/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"

fit "github.com/linuxboot/fiano/pkg/intel/metadata/fit"
"github.com/linuxboot/fiano/pkg/uefi"
)

func main() {
flag.Parse()
args := flag.Args()

if len(args) > 0 {
path := args[0]
data, err := ioutil.ReadFile(path)
if err != nil {
log.Fatal(err)
}

fmt.Printf("\n== IFD ==\n")
regions := [...]uefi.FlashRegionType{
uefi.RegionTypeBIOS,
uefi.RegionTypeME,
uefi.RegionTypeGBE,
uefi.RegionTypePTT,
uefi.RegionTypeEC,
uefi.RegionTypeMicrocode,
}

fi, err := uefi.NewFlashImage(data)

Check failure on line 35 in cmds/intelana/main.go

View workflow job for this annotation

GitHub Actions / lint (1.21, macos-latest)

SA4006: this value of `err` is never used (staticcheck)

Check failure on line 35 in cmds/intelana/main.go

View workflow job for this annotation

GitHub Actions / lint (1.22, ubuntu-latest)

SA4006: this value of `err` is never used (staticcheck)

Check failure on line 35 in cmds/intelana/main.go

View workflow job for this annotation

GitHub Actions / lint (1.22, macos-latest)

SA4006: this value of `err` is never used (staticcheck)

Check failure on line 35 in cmds/intelana/main.go

View workflow job for this annotation

GitHub Actions / lint (1.23, macos-latest)

SA4006: this value of `err` is never used (staticcheck)
if fi != nil {
for _, r := range regions {
if fi.IFD.Region.FlashRegions[r].Valid() {
offset := fi.IFD.Region.FlashRegions[r].BaseOffset()
size := fi.IFD.Region.FlashRegions[r].EndOffset() - offset
fmt.Printf("%-9s offset %x size %x\n", r, offset, size)
} else {
fmt.Printf("%-9s region not found/invalid\n", r)
}
}
}

fmt.Printf("\n== FIT ==\n")
table, err := fit.GetTable(data)

Check failure on line 49 in cmds/intelana/main.go

View workflow job for this annotation

GitHub Actions / lint (1.21, macos-latest)

SA4006: this value of `err` is never used (staticcheck)

Check failure on line 49 in cmds/intelana/main.go

View workflow job for this annotation

GitHub Actions / lint (1.22, ubuntu-latest)

SA4006: this value of `err` is never used (staticcheck)

Check failure on line 49 in cmds/intelana/main.go

View workflow job for this annotation

GitHub Actions / lint (1.22, macos-latest)

SA4006: this value of `err` is never used (staticcheck)

Check failure on line 49 in cmds/intelana/main.go

View workflow job for this annotation

GitHub Actions / lint (1.23, macos-latest)

SA4006: this value of `err` is never used (staticcheck)
doJson := false
if doJson {
j, err := json.MarshalIndent(table, "", " ")
if err != nil {
log.Fatal(err)
}
fmt.Printf(string(j))

Check failure on line 56 in cmds/intelana/main.go

View workflow job for this annotation

GitHub Actions / lint (1.21, macos-latest)

SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)

Check failure on line 56 in cmds/intelana/main.go

View workflow job for this annotation

GitHub Actions / lint (1.22, ubuntu-latest)

SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)

Check failure on line 56 in cmds/intelana/main.go

View workflow job for this annotation

GitHub Actions / lint (1.22, macos-latest)

SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)

Check failure on line 56 in cmds/intelana/main.go

View workflow job for this annotation

GitHub Actions / lint (1.23, macos-latest)

SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck)
} else {
fmt.Printf("\n%s", table)
}
}
}
6 changes: 5 additions & 1 deletion pkg/uefi/firmwarevolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ func (fv *FirmwareVolume) InsertFile(alignedOffset uint64, fBuf []byte) error {
// Check size
fLen := uint64(len(fBuf))
if fLen == 0 {
return errors.New("trying to insert empty file")
if true {
return nil
} else {
return errors.New("trying to insert empty file")
}
}
// Overwrite old data in the firmware volume.
fv.buf = append(fv.buf, fBuf...)
Expand Down
3 changes: 2 additions & 1 deletion pkg/visitors/assemble.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ func (v *Assemble) Visit(f uefi.Firmware) error {
for _, file := range f.Files {
fileBuf := file.Buf()
fileLen := uint64(len(fileBuf))
log.Warnf("adding %v ", file.Header.GUID)
if fileLen == 0 {
log.Fatalf("%v", file.Header.GUID)
log.Warnf("%v empty?", file.Header.GUID)
}

// Pad to the 8 byte alignments.
Expand Down
Loading