partition

package
v0.0.0-...-913b437 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IGNORE        PartitionConfigType = "IGNORE"
	LEGACY_UBOOT                      = "LEGACY_UBOOT"
	UBOOT                             = "UBOOT"
	FIT                               = "FIT"
	FBMETA_MD5                        = "FBMETA_MD5"
	FBMETA_IMAGE                      = "FBMETA_IMAGE"
	LFMETA_IMAGE                      = "LFMETA_IMAGE"
	LFMETA_SHA256                     = "LFMETA_SHA256"
)
View Source
const (
	// FBMETA_ROM : the u-boot SPL used in verified boot systems
	FBMETA_ROM FBMetaPartInfoType = "rom"
	// FBMETA_RAW : raw binary, normally U-Boot
	FBMETA_RAW = "raw"
	// FBMETA_FIT : U-Boot defined fit
	FBMETA_FIT = "fit"
	// FBMETA_META : the image meta partition
	FBMETA_META = "meta"
	// FBMETA_DATA : data partition
	FBMETA_DATA = "data"
)
View Source
const (
	LF_PART_DATA      LFMetaPartType = "data"
	LF_PART_FIT                      = "fit"
	LF_PART_JSON                     = "json"
	LF_PART_UBOOT                    = "u-boot"
	LF_PART_TEST_ONLY                = "don't-use--testing-only"
)

Variables

View Source
var ImageFormats = []ImageFormat{
	{

		Name: "meta-big",
		PartitionConfigs: []PartitionConfigInfo{
			{

				Name:   "fbmeta-image-big",
				Offset: 0,
				Size:   128 * 1024 * 1024,
				Type:   FBMETA_IMAGE,
			},
		},
	},
	{

		Name: "meta",
		PartitionConfigs: []PartitionConfigInfo{
			{

				Name:   "fbmeta-image",
				Offset: 0,
				Size:   32 * 1024 * 1024,
				Type:   FBMETA_IMAGE,
			},
		},
	},
	{
		Name: "lf-meta",
		PartitionConfigs: []PartitionConfigInfo{
			{

				Name:   "lfmeta-image",
				Offset: 0,
				Size:   128 * 1024 * 1024,
				Type:   LFMETA_IMAGE,
			},
		},
	},
	{
		Name: "vboot",
		PartitionConfigs: []PartitionConfigInfo{
			{
				Name:   "spl+recovery",
				Offset: 0,
				Size:   384 * 1024,
				Type:   UBOOT,
			},
			{
				Name:   "env",
				Offset: 384 * 1024,
				Size:   128 * 1024,
				Type:   IGNORE,
			},
			{
				Name:          "uboot",
				Offset:        512 * 1024,
				Size:          384 * 1024,
				Type:          FIT,
				FitImageNodes: 1,
			},
			{
				Name:          "unified-fit",
				Offset:        896 * 1024,
				Size:          27776 * 1024,
				Type:          FIT,
				FitImageNodes: 2,
			},
		},
	},
	{
		Name: "fit",
		PartitionConfigs: []PartitionConfigInfo{
			{
				Name:   "u-boot",
				Offset: 0,
				Size:   384 * 1024,
				Type:   UBOOT,
			},
			{
				Name:   "env",
				Offset: 384 * 1024,
				Size:   128 * 1024,
				Type:   IGNORE,
			},
			{
				Name:          "unified-fit",
				Offset:        512 * 1024,
				Size:          27776 * 1024,
				Type:          FIT,
				FitImageNodes: 2,
			},
		},
	},
	{
		Name: "legacy",
		PartitionConfigs: []PartitionConfigInfo{
			{
				Name:   "u-boot",
				Offset: 0,
				Size:   384 * 1024,
				Type:   UBOOT,
			},
			{
				Name:   "env",
				Offset: 384 * 1024,
				Size:   128 * 1024,
				Type:   IGNORE,
			},
			{
				Name:   "kernel",
				Offset: 512 * 1024,
				Size:   4096 * 1024,
				Type:   LEGACY_UBOOT,
			},
			{
				Name:   "rootfs",
				Offset: 4608 * 1024,
				Size:   24064 * 1024,
				Type:   LEGACY_UBOOT,
			},
		},
	},
	{
		Name: "legacy-fido",
		PartitionConfigs: []PartitionConfigInfo{
			{
				Name:   "u-boot",
				Offset: 0,
				Size:   384 * 1024,
				Type:   UBOOT,
			},
			{
				Name:   "env",
				Offset: 384 * 1024,
				Size:   128 * 1024,
				Type:   IGNORE,
			},
			{
				Name:   "kernel",
				Offset: 512 * 1024,
				Size:   2560 * 1024,
				Type:   LEGACY_UBOOT,
			},
			{
				Name:   "rootfs",
				Offset: 3072 * 1024,
				Size:   12288 * 1024,
				Type:   LEGACY_UBOOT,
			},
		},
	},
}

ImageFormats is taken from fw-util (common/recipes-core/fw-util/files/image_parts.json). It maps from image format name to a array of partition configurations. The idea is that the image is validated against every single format type until one succeeds; if all fails, then the image is not valid. Differences: (1) flashy can support uboot validation, hence it is not ignored

(only in certain cases)

(2) size and offset are in bytes (3) FitImageNodes (named num-nodes in fw-util) are explicitly 1 if not

specified in fw-util.

(4) vboot spl+recovery can be treated as UBOOT. It will be ignored if the flash1

header is RO (e.g. fbtp)

PartitionFactoryMap maps from PartitionConfigType to the factory function that gets the PartitionFactory for that interface. Populated by each type of partititon in the corresponding init() function

View Source
var ValidatePartitionsFromPartitionConfigs = func(
	data []byte,
	partitionConfigs []PartitionConfigInfo,
) error {
	partitions, err := getAllPartitionsFromPartitionConfigs(
		data,
		partitionConfigs,
	)
	if err != nil {
		return errors.Errorf("Unable to get all partitions: %v",
			err)
	}
	err = validatePartitions(partitions)
	if err != nil {
		return errors.Errorf("Validation failed: %v", err)
	}
	return nil
}

ValidatePartitionsFromPartitionConfigs gets all the partitions based on the partitionConfigs then validate them. If all passed, return nil. Else return the error.

Functions

This section is empty.

Types

type FBMetaChecksum

type FBMetaChecksum struct {
	Checksum string `json:"meta_md5"`
}

FBMetaChecksum is a separate JSON that contains the md5 checksum of the image-meta partition.

type FBMetaImagePartition

type FBMetaImagePartition struct {
	Name   string
	Data   []byte
	Offset uint32
	// contains filtered or unexported fields
}

FBMetaImagePartition is a full image that contains the image-meta partition. The image-meta partition contains the information of the partitions and indicates the validation scheme required.

func (*FBMetaImagePartition) GetName

func (p *FBMetaImagePartition) GetName() string

func (*FBMetaImagePartition) GetSize

func (p *FBMetaImagePartition) GetSize() uint32

func (*FBMetaImagePartition) GetType

func (*FBMetaImagePartition) Validate

func (p *FBMetaImagePartition) Validate() error

type FBMetaInfo

type FBMetaInfo struct {
	FBOBMC_IMAGE_META_VER int              `json:"FBOBMC_IMAGE_META_VER"`
	PartInfos             []FBMetaPartInfo `json:"part_infos"`
}

FBMetaInfo contains relevant info in the image-meta partition.

type FBMetaMD5Partition

type FBMetaMD5Partition struct {
	Name     string
	Data     []byte
	Offset   uint32
	Checksum string
}

FBMetaMD5Partition validates a partition by calculating the md5sum of the whole partition and matches it against the checksum. It is similar to UbootPartition, but is simpler as it does not try to look for appended checksums nor use known UBoot checksums.

func (*FBMetaMD5Partition) GetName

func (p *FBMetaMD5Partition) GetName() string

func (*FBMetaMD5Partition) GetSize

func (p *FBMetaMD5Partition) GetSize() uint32

func (*FBMetaMD5Partition) GetType

func (*FBMetaMD5Partition) Validate

func (p *FBMetaMD5Partition) Validate() error

type FBMetaPartInfo

type FBMetaPartInfo struct {
	Name   string             `json:"name"`
	Size   uint32             `json:"size"`
	Offset uint32             `json:"offset"`
	Type   FBMetaPartInfoType `json:"type"`
	// For now, the only checksum used is MD5
	Checksum string `json:"md5"`
	// applicable only for FIT partitions
	// this is the minimum number of children nodes of the 'images' node
	FitImageNodes uint32 `json:"num-nodes"`
}

FBMetaPartInfo is analogous to PartitionConfigInfo, but a shim is required to convert it properly to use the correct "type".

type FBMetaPartInfoType

type FBMetaPartInfoType = string

FBMetaPartInfoType represents the "Type" defined in MetaPartInfo

type FitPartition

type FitPartition struct {
	Name string
	Data []byte
	// offset in the image file
	Offset uint32
	// number of children nodes within the 'images' node
	FitImageNodes uint32
}

FitPartition represents a partition using the FIT format. Validation works by parsing a device tree / flattened image tree header. Both the beginning and end of the data region are determined from fields in the header. Used for "kernel" and "rootfs" partitions.

func (*FitPartition) GetName

func (p *FitPartition) GetName() string

func (*FitPartition) GetSize

func (p *FitPartition) GetSize() uint32

func (*FitPartition) GetType

func (p *FitPartition) GetType() PartitionConfigType

func (*FitPartition) Validate

func (p *FitPartition) Validate() error

type IgnorePartition

type IgnorePartition struct {
	Name string
	// offset in the image file
	Offset uint32
	Size   uint32
}

IgnorePartition represents a partition whose validation is ignored.

func (*IgnorePartition) GetName

func (p *IgnorePartition) GetName() string

func (*IgnorePartition) GetSize

func (p *IgnorePartition) GetSize() uint32

func (*IgnorePartition) GetType

func (p *IgnorePartition) GetType() PartitionConfigType

func (*IgnorePartition) Validate

func (p *IgnorePartition) Validate() error

type ImageFormat

type ImageFormat struct {
	Name             string
	PartitionConfigs []PartitionConfigInfo
}

ImageFormat represents a layout format for images.

type LFMetaImagePartition

type LFMetaImagePartition struct {
	Name   string
	Data   []byte
	Offset uint32
}

func (*LFMetaImagePartition) CheckLocation

func (p *LFMetaImagePartition) CheckLocation(location LFMetaLocations) error

func (*LFMetaImagePartition) ConvertPartType

func (*LFMetaImagePartition) ConvertToPartitionConfig

func (p *LFMetaImagePartition) ConvertToPartitionConfig(part LFMetaManifestPart) (PartitionConfigInfo, error)

func (*LFMetaImagePartition) ExtractMetadata

func (p *LFMetaImagePartition) ExtractMetadata(start uint32, end uint32) (LFMetaManifest, error)

func (*LFMetaImagePartition) GetName

func (p *LFMetaImagePartition) GetName() string

func (*LFMetaImagePartition) GetSize

func (p *LFMetaImagePartition) GetSize() uint32

func (*LFMetaImagePartition) GetType

func (*LFMetaImagePartition) Validate

func (p *LFMetaImagePartition) Validate() error

type LFMetaLocations

type LFMetaLocations struct {
	Offset uint32
	Size   uint32
}

type LFMetaManifest

type LFMetaManifest struct {
	Type      string               `json:"type"`
	Version   int                  `json:"version"`
	Info      LFMetaManifestInfo   `json:"info"`
	Parts     []LFMetaManifestPart `json:"partitions"`
	Sha256Sum string               `json:"manifest-sha256"`
}

type LFMetaManifestInfo

type LFMetaManifestInfo struct {
	Purpose         string   `json:"purpose"`
	Machine         string   `json:"machine"`
	Version         string   `json:"version"`
	BuildId         string   `json:"build-id"`
	ExtendedVersion string   `json:"extended-version"`
	CompatibleNames []string `json:"compatible-names"`
}

type LFMetaManifestPart

type LFMetaManifestPart struct {
	Name      string         `json:"name"`
	Type      LFMetaPartType `json:"type"`
	Offset    uint32         `json:"offset"`
	Size      uint32         `json:"size"`
	NumNodes  uint           `json:"num-nodes,omitempty"`
	Sha256Sum string         `json:"sha256,omitempty"`
}

type LFMetaPartType

type LFMetaPartType = string

type LFMetaSha256Partition

type LFMetaSha256Partition struct {
	Name     string
	Data     []byte
	Offset   uint32
	Checksum string
}

func (*LFMetaSha256Partition) GetName

func (p *LFMetaSha256Partition) GetName() string

func (*LFMetaSha256Partition) GetSize

func (p *LFMetaSha256Partition) GetSize() uint32

func (*LFMetaSha256Partition) GetType

func (*LFMetaSha256Partition) Validate

func (p *LFMetaSha256Partition) Validate() error

type LegacyUbootPartition

type LegacyUbootPartition struct {
	Name string
	Data []byte
	// offset in the image file
	Offset uint32
	// contains filtered or unexported fields
}

LegacyUbootPartition parses a (legacy) U-Boot header. The data region begins at the end of the header and ends where the size field in the header indicates. Used for "kernel" and "rootfs" partitions.

func (*LegacyUbootPartition) GetName

func (p *LegacyUbootPartition) GetName() string

func (*LegacyUbootPartition) GetSize

func (p *LegacyUbootPartition) GetSize() uint32

func (*LegacyUbootPartition) GetType

func (*LegacyUbootPartition) Validate

func (p *LegacyUbootPartition) Validate() error

type Partition

type Partition interface {
	GetName() string
	GetSize() uint32
	Validate() error
	GetType() PartitionConfigType
}

Partition is the base interface definition for Partition validation.

type PartitionConfigInfo

type PartitionConfigInfo struct {
	Name   string
	Offset uint32
	Size   uint32
	Type   PartitionConfigType
	// applicable only for FIT partitions
	// this is the minimum number of children nodes of the 'images' node
	FitImageNodes uint32
	// applicable only for partitions defined in image-meta
	Checksum string
}

PartitionConfigInfo contains info for each partition in PartitionConfigs.

type PartitionConfigType

type PartitionConfigType = string

PartitionConfigType is the type for the PartitionConfigType enum.

type PartitionFactory

type PartitionFactory = func(payload PartitionFactoryArgs) Partition

PartitionFactory is a generic function type to get the corresponding Partition interface.

type PartitionFactoryArgs

type PartitionFactoryArgs struct {
	Data  []byte
	PInfo PartitionConfigInfo
}

PartitionFactoryArgs contain args for PartitionFactory.

type UBootPartition

type UBootPartition struct {
	Name string
	Data []byte
	// offset in the image file
	Offset uint32
	// contains filtered or unexported fields
}

UBootPartition represents U-Boot partitions. Validation works by calculating an md5sum for the whole partition and considers it valid if the computed checksum matches any of the appended checksums/known checksums. The checksum is stored as json (appended, 4kB).

func (*UBootPartition) GetName

func (p *UBootPartition) GetName() string

func (*UBootPartition) GetSize

func (p *UBootPartition) GetSize() uint32

func (*UBootPartition) GetType

func (p *UBootPartition) GetType() PartitionConfigType

func (*UBootPartition) Validate

func (p *UBootPartition) Validate() error

Jump to

Keyboard shortcuts

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