amdfw

package module
v0.0.0-...-2218359 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2019 License: GPL-3.0 Imports: 5 Imported by: 2

README

amdfw

Golang library for reading and writing AMD firmware components

Credit goes to @cwerling for his psptool

amddump

cmd/amddump is a small tool, that dumps all informations known to this library on a specfic image.

amddump ryzeimage.rom

Current Limitations

  • Always assumes valid FirmwareEntryTable.
    • Some AM1 CPUs are not using it.
    • Older FETs might be parsed wrong
  • Non Directory-Based Firmware (IMC, GEC, XHCI) cannot be extracted
  • All Offsets are treated as absolute. Partial Images often can't be read.

Usage

See cmd/amddump.go for read-only example code.


func main() {

	imageBytes, err := ioutil.ReadFile(os.Args[1])

	if err != nil {
		log.Fatal("Could not read file: ", err)
	}

	image, err := amdfw.ParseImage(imageBytes)

	if err != nil {
		log.Println("Error while parse Image: ", err.Error())
	}

	targetAddress := uint32(0x1C1000)
	image.FET.ImcRomBase = &targetAddress

	image.FET.Write(imageBytes, image.FET.Location)

	ioutil.WriteFile(os.Args[1], imageBytes, 666)
}

Documentation

Index

Constants

View Source
const BHDCOOCKIE = "$BHD"
View Source
const DUALPSPCOOCKIE = "2PSP"
View Source
const DefaultFlashMapping = uint32(0xFF000000)
View Source
const FETDefaultOffset = uint32(0x20000)
View Source
const FETSignature = uint32(0x55AA55AA)
View Source
const PSPCOOCKIE = "$PSP"
View Source
const SECONDBHDCOOCKIE = "$BL2"
View Source
const SECONDPSPCOOCKIE = "$PL2"

Variables

This section is empty.

Functions

func FindFirmwareEntryTable

func FindFirmwareEntryTable(firmware []byte) (uint32, error)

Looks for the FET Signature at the often used offsets.

func FindFirmwareEntryTableByScan

func FindFirmwareEntryTableByScan(firmware []byte) (uint32, error)

Looks for the FET Signature everywhere (slow)

func GetAddressFromTable

func GetAddressFromTable(romType RomType, table *FirmwareEntryTable) (uint32, error)

func GetFlashMapping

func GetFlashMapping(firmwareBytes []byte, fet *FirmwareEntryTable) (uint32, error)

Types

type Directory

type Directory struct {
	Header   DirectoryHeader
	Entries  []Entry
	Location uint32
}

func ParseDirectory

func ParseDirectory(firmwareBytes []byte, address uint32, flashMapping uint32) (*Directory, error)

func (*Directory) ValidateChecksum

func (directory *Directory) ValidateChecksum() (valid bool, actual uint32)

Validates the Directory Checksum and return the actual value

func (*Directory) Write

func (directory *Directory) Write(baseImage []byte, flashMapping uint32) error

type DirectoryEntry

type DirectoryEntry struct {
	Type     uint32
	Size     uint32
	Location uint32
	Reserved uint32
	Unknown  *uint64
}

func (*DirectoryEntry) Write

func (entry *DirectoryEntry) Write(baseImage []byte, address uint32) error

type DirectoryHeader

type DirectoryHeader struct {
	Cookie       [4]byte
	Checksum     uint32
	TotalEntries uint32
	Reserved     uint32
}

func (*DirectoryHeader) Write

func (header *DirectoryHeader) Write(baseImage []byte, address uint32) error

type Entry

type Entry struct {
	DirectoryEntry DirectoryEntry
	Header         *EntryHeader
	Raw            []byte
	Signature      []byte
	Comment        []string
	TypeInfo       *TypeInfo
	Version        string
}

func ParseEntry

func ParseEntry(firmwareBytes []byte, directoryEntry DirectoryEntry, flashMapping uint32) (*Entry, error)

func (Entry) Write

func (entry Entry) Write(baseImage []byte, address uint32) error

type EntryHeader

type EntryHeader struct {
	Unknown00      [0x10]byte // 0x00
	ID             uint32     // 0x10
	SizeSigned     uint32     // 0x14
	IsEncrypted    uint32     // 0x18
	Unknown1C      uint32     // 0x1C
	EncFingerprint [0x10]byte // 0x20
	IsSigned       uint32     // 0x30
	Unknown34      uint32     // 0x34
	SigFingerprint [0x10]byte // 0x38
	IsCompressed   uint32     // 0x48
	Unknown4C      uint32     // 0x4C
	FullSize       uint32     // 0x50
	Unknown54      uint32     // 0x54
	Unknown58      [0x08]byte // 0x58
	Version        [0x04]byte // 0x60
	Unknown64      uint32     // 0x64
	Unknown68      uint32     // 0x68
	SizePacked     uint32     // 0x6C
	Unknown70      [0x10]byte // 0x70
	Unknown80      [0x10]byte // 0x80
	Unknown90      uint32     // 0x90
	Unknown94      uint32     // 0x94
	Unknown98      uint32     // 0x98
	Unknown9C      uint32     // 0x9C
	UnknownA0      uint32     // 0xA0
	UnknownA4      uint32     // 0xA4
	UnknownA8      uint32     // 0xA8
	UnknownAC      uint32     // 0xAC
	UnknownB0      [0x50]byte // 0xB0

}

type FirmwareEntryTable

type FirmwareEntryTable struct {
	Location uint32

	Signature     uint32
	ImcRomBase    *uint32
	GecRomBase    *uint32
	XHCRomBase    *uint32
	PSPDirBase    *uint32
	NewPSPDirBase *uint32
	BHDDirBase    *uint32
	NewBHDDirBase *uint32
}

func ParseFirmwareEntryTable

func ParseFirmwareEntryTable(firmware []byte, address uint32) (*FirmwareEntryTable, error)

Parses the FET at the given Address Default address is 0x20000 but some PSP versions appear to be able to search on different offsets

func (*FirmwareEntryTable) Write

func (fet *FirmwareEntryTable) Write(baseImage []byte, address uint32) error

Writes FET into existing image

type Image

type Image struct {
	FET          *FirmwareEntryTable
	FlashMapping *uint32
	Roms         []*Rom
}

func ParseImage

func ParseImage(firmwareBytes []byte) (*Image, error)

func (*Image) Write

func (image *Image) Write(baseImage []byte) ([]byte, error)

type Rom

type Rom struct {
	Type        RomType
	Directories []*Directory
	Raw         []byte
}

func ParseBHDRom

func ParseBHDRom(firmwareBytes []byte, table *FirmwareEntryTable, flashMapping uint32) (*Rom, error)

func ParseNewBHDRom

func ParseNewBHDRom(firmwareBytes []byte, table *FirmwareEntryTable, flashMapping uint32) (*Rom, error)

func ParseNewPSPRom

func ParseNewPSPRom(firmwareBytes []byte, table *FirmwareEntryTable, flashMapping uint32) (*Rom, error)

func ParsePSPRom

func ParsePSPRom(firmwareBytes []byte, table *FirmwareEntryTable, flashMapping uint32) (*Rom, error)

func ParseRoms

func ParseRoms(firmwareBytes []byte, table *FirmwareEntryTable, flashMapping uint32) ([]*Rom, []error)

func (Rom) Write

func (rom Rom) Write(baseImage []byte, table *FirmwareEntryTable, flashMapping uint32) error

type RomType

type RomType string
const (
	IMCRom    RomType = "IMC"
	GECRom    RomType = "GEC"
	XHCIRom   RomType = "XHCI"
	PSPRom    RomType = "PSP"
	NewPSPRom RomType = "NEWPSP"
	BHDRom    RomType = "BHD"
	NewBHDRom RomType = "NEWBDH"
)

type TypeInfo

type TypeInfo struct {
	Name    string
	Comment string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL