fmap

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: BSD-3-Clause Imports: 10 Imported by: 5

Documentation

Overview

Package fmap parses flash maps.

Index

Constants

View Source
const (
	FmapAreaStatic = 1 << iota
	FmapAreaCompressed
	FmapAreaReadOnly
)

Flags which can be applied to Area.Flags.

Variables

View Source
var Signature = []byte("__FMAP__")

Signature of the fmap structure.

Functions

func FlagNames

func FlagNames(flags uint16) string

FlagNames returns human readable representation of the flags.

func Read

func Read(f io.Reader) (*FMap, *Metadata, error)

Read an FMap into the data structure.

func Write

func Write(f io.WriteSeeker, fmap *FMap, m *Metadata) error

Write overwrites the fmap in the flash file.

Types

type Area

type Area struct {
	Offset uint32
	Size   uint32
	Name   String
	Flags  uint16
}

Area describes each area.

type FMap

type FMap struct {
	Header
	Areas []Area
}

FMap structure serializable using encoding.Binary.

func (*FMap) Checksum

func (f *FMap) Checksum(r io.ReaderAt, h hash.Hash) ([]byte, error)

Checksum performs a hash of the static areas.

func (*FMap) IndexOfArea added in v1.0.1

func (f *FMap) IndexOfArea(name string) int

IndexOfArea returns the index of an area in the fmap given its name. If no names match, -1 is returned.

func (*FMap) ReadArea

func (f *FMap) ReadArea(r io.ReaderAt, i int) ([]byte, error)

ReadArea reads an area from the flash image as a byte array given its index.

func (*FMap) ReadAreaByName added in v1.0.1

func (f *FMap) ReadAreaByName(r io.ReaderAt, name string) ([]byte, error)

ReadAreaByName is the same as ReadArea but uses the area's name.

func (*FMap) WriteArea added in v1.0.1

func (f *FMap) WriteArea(r io.WriterAt, i int, data []byte) error

WriteArea writes a byte array to an area on the flash image given its index. If the data is too large for the fmap area, the write is not performed and an error returned. If the data is too small, the remainder is left untouched.

func (*FMap) WriteAreaByName added in v1.0.1

func (f *FMap) WriteAreaByName(r io.WriterAt, name string, data []byte) error

WriteAreaByName is the same as WriteArea but uses the area's name.

type Header struct {
	Signature [8]uint8
	VerMajor  uint8
	VerMinor  uint8
	Base      uint64
	Size      uint32
	Name      String
	NAreas    uint16
}

Header describes the flash part.

type Metadata

type Metadata struct {
	Start uint64
}

Metadata contains additional data not part of the FMap.

type String

type String struct {
	Value [32]uint8
}

String wraps around byte array to give us more control over how strings are serialized.

func (*String) MarshalJSON

func (s *String) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*String) String

func (s *String) String() string

func (*String) UnmarshalJSON

func (s *String) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

Jump to

Keyboard shortcuts

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