uf2

package
v0.0.0-...-5b9f931 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlockSize    = 512
	MagicStart0  = 0x0A324655 // "UF2\n"
	MagicStart1  = 0x9E5D5157 // Randomly selected
	MagicEnd     = 0x0AB16F30 // Also randomly selected.
	BlockMaxData = 476
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Flags          Flags
	TargetAddr     uint32 // Address in flash where the data should be written.
	PayloadSize    uint32 // Number of byttes used in data (often 256).
	BlockNum       uint32 // Sequential block number; starts at 0.
	NumBlocks      uint32 // Total number of blocks in file.
	SizeOrFamilyID uint32 // File size or board familyID or zero
	RawData        [BlockMaxData]byte
}

Block is the structure used for each UF2 code block sent to device. It is 512 bytes in size including magic words. Size of header is 32 bytes. This type does not include magic words as those are part of I/O validation in DecodeBlock.

func DecodeAppendBlocks

func DecodeAppendBlocks(dst []Block, r io.Reader, scratchBuf []byte) ([]Block, int, error)

func DecodeBlock

func DecodeBlock(text []byte) (Block, error)

DecodeBlock decodes a 512 byte block from the argument buffer. Buffer must be at least 512 bytes long.

func MustDecodeBlock

func MustDecodeBlock(text []byte) (block Block)

MustDecodeBlock attempts to decode 512 byte block without bounds checking. Panics if buffer is shorter than 512 bytes.

func (Block) AppendTo

func (b Block) AppendTo(dst []byte) []byte

AppendTo appends the blocks' binary representation to the argument buffer and returns the result, including magic start and end. It performs no error checking.

func (*Block) Data

func (b *Block) Data() ([]byte, error)

Data returns a pointer to this block's data field limited to the payload size it has.

func (Block) HeaderBytes

func (b Block) HeaderBytes() (hd [32]byte)

HeaderBytes returns the block's first 32 bytes including magic numbers as an array.

func (Block) String

func (block Block) String() string

func (*Block) Validate

func (b *Block) Validate() error

Validate checks block fields for inconsistencies.

type BlocksReaderAt

type BlocksReaderAt struct {
	// contains filtered or unexported fields
}

func NewBlocksReaderAt

func NewBlocksReaderAt(blocks []Block) (*BlocksReaderAt, error)

NewBlocksReaderAt

func (*BlocksReaderAt) Addrs

func (blks *BlocksReaderAt) Addrs() (start, end uint32)

func (*BlocksReaderAt) ReadAt

func (blks *BlocksReaderAt) ReadAt(b []byte, addr int64) (int, error)

type Flags

type Flags uint32
const (
	FlagNotMainFlash         Flags = 1 << 0
	FlagFamilyIDPresent      Flags = 1 << 13
	FlagFileContainer        Flags = 1 << 12
	FlagMD5ChecksumPresent   Flags = 1 << 14
	FlagExtensionTagsPresent Flags = 1 << 15
)

type Formatter

type Formatter struct {
	Flags     Flags
	FamilyID  uint32
	ChunkSize uint32 // How to chunk payload (is payload size field). By default is chosen as 256. Maximum is 476.
}

func (*Formatter) AppendTo

func (f *Formatter) AppendTo(dst, data []byte, targetAddr uint32) (uftFormatted []byte, blocksWritten int, err error)

AppendTo appends data formatted as UF2 blocks to dst and returns the result and number of blocks written. To get total size appended one can do blocksWritten*512.

func (*Formatter) SetFamilyID

func (f *Formatter) SetFamilyID(familyID string) error

Jump to

Keyboard shortcuts

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