ota

package
v0.0.0-...-4022ef6 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OffsetLength      = 0
	OffsetCRC32       = 4
	OffsetMagicNumber = 8
	OffsetVersion     = 12
	OffsetPayload     = 20
	HeaderSize        = 20
)

Variables

View Source
var (
	BoardTypes = map[uint32]string{
		0x45535033: "ESP32",
		0x23418054: "MKR_WIFI_1010",
		0x23418057: "NANO_33_IOT",
		0x2341025B: "PORTENTA_H7_M7",
		0x2341005E: "NANO_RP2040_CONNECT",
		0x2341025F: "NICLA_VISION",
		0x23410064: "OPTA",
		0x23410266: "GIGA",
		0x23410070: "NANO_ESP32",
		0x23411002: "UNOR4WIFI",
	}

	ArduinoPidToFQBN = map[string]string{
		"1002": "arduino:renesas_uno:unor4wifi",
		"0070": "arduino:esp32:nano_nora",
		"8057": "arduino:samd:nano_33_iot",
		"804E": "arduino:samd:mkr1000",
		"8052": "arduino:samd:mkrgsm1400",
		"8055": "arduino:samd:mkrnb1500",
		"8054": "arduino:samd:mkrwifi1010",
		"005E": "arduino:mbed_nano:nanorp2040connect",
		"025B": "arduino:mbed_portenta:envie_m7",
		"025F": "arduino:mbed_nicla:nicla_vision",
		"0064": "arduino:mbed_opta:opta",
		"0266": "arduino:mbed_giga:giga",
	}

	ArduinoFqbnToPID = map[string]string{
		"arduino:samd:nano_33_iot":            "8057",
		"arduino:samd:mkr1000":                "804E",
		"arduino:samd:mkrgsm1400":             "8052",
		"arduino:samd:mkrnb1500":              "8055",
		"arduino:samd:mkrwifi1010":            "8054",
		"arduino:mbed_nano:nanorp2040connect": "005E",
		"arduino:mbed_portenta:envie_m7":      "025B",
		"arduino:mbed_nicla:nicla_vision":     "025F",
		"arduino:mbed_opta:opta":              "0064",
		"arduino:mbed_giga:giga":              "0266",
		"arduino:renesas_uno:unor4wifi":       "1002",
		"arduino:esp32:nano_nora":             "0070",
	}

	ArduinoVendorID = "2341"

	Esp32MagicNumberPart1 = "4553"
	Esp32MagicNumberPart2 = "5033"
)
View Source
var (
	ErrCRC32Mismatch  = fmt.Errorf("CRC32 mismatch")
	ErrLengthMismatch = fmt.Errorf("file length mismatch")
)

Functions

This section is empty.

Types

type Encoder

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

Encoder writes a binary to an output stream in the ota format.

func NewEncoder

func NewEncoder(w io.Writer, magicNumberPart1, magicNumberPart2 string) *Encoder

NewEncoder creates a new ota encoder.

func (*Encoder) Encode

func (e *Encoder) Encode(data []byte) error

Encode compresses data using a lzss algorithm, encodes the result in ota format and writes it to e's underlying writer.

type OtaFileReader

type OtaFileReader interface {
	io.Reader
	io.Closer
}

type OtaMetadata

type OtaMetadata struct {
	Length         uint32
	CRC32          uint32
	MagicNumber    uint32
	BoardType      string
	FQBN           *string
	VID            string
	PID            string
	IsArduinoBoard bool
	Compressed     bool
	PayloadSHA256  string // SHA256 of the payload (decompressed if compressed). This is the SHA256 as seen ny the board.
	OtaSHA256      string // SHA256 of the whole file (header + payload).
}

func DecodeOtaFirmwareHeader

func DecodeOtaFirmwareHeader(otafileptr OtaFileReader) (*OtaMetadata, error)

DecodeOtaFirmwareHeader decodes the OTA firmware header from a binary file. File is composed by an header and a payload (optionally lzss compressed). Method is also checking CRC32 of the file, verifying that file is not corrupted. OTA header layout: LENGTH (4 B) | CRC (4 B) | MAGIC NUMBER = VID + PID (4 B) | VERSION (8 B) | PAYLOAD (LENGTH - 12 B) See https://arduino.atlassian.net/wiki/spaces/RFC/pages/1616871540/OTA+header+structure

func DecodeOtaFirmwareHeaderFromFile

func DecodeOtaFirmwareHeaderFromFile(binaryFilePath string) (*OtaMetadata, error)

DecodeOtaFirmwareHeader decodes the OTA firmware header from a binary file. File is composed by an header and a payload (optionally lzss compressed). Method is also checking CRC32 of the file, verifying that file is not corrupted. OTA header layout: LENGTH (4 B) | CRC (4 B) | MAGIC NUMBER = VID + PID (4 B) | VERSION (8 B) | PAYLOAD (LENGTH - 12 B) See https://arduino.atlassian.net/wiki/spaces/RFC/pages/1616871540/OTA+header+structure

func (OtaMetadata) Data

func (r OtaMetadata) Data() interface{}

func (OtaMetadata) String

func (r OtaMetadata) String() string

type Version

type Version struct {
	HeaderVersion   uint8
	Compression     bool
	Signature       bool
	Spare           uint8
	PayloadTarget   uint8
	PayloadMayor    uint8
	PayloadMinor    uint8
	PayloadPatch    uint8
	PayloadBuildNum uint32
}

Version contains all the OTA header information Check out https://arduino.atlassian.net/wiki/spaces/RFC/pages/1616871540/OTA+header+structure for more information on the OTA header specs.

func (*Version) Bytes

func (v *Version) Bytes() []byte

Bytes builds a 8 byte length representation of the Version Struct for the OTA update.

Jump to

Keyboard shortcuts

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