recipes

package
v0.0.0-...-d8bc51a Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package recipes / config

Package recipes / coreboot

Package recipes / edk2

Package recipes / linux

Package recipes yay!

Package recipes / stitching

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFailedValidation          = errors.New("config failed validation")
	ErrTargetMissing             = errors.New("no target specified")
	ErrTargetInvalid             = errors.New("unsupported target")
	ErrBuildFailed               = errors.New("build failed")
	ErrDependencyTreeUndefDep    = errors.New("module has invalid dependency")
	ErrDependencyTreeUnderTarget = errors.New("target not found in dependency tree")
)

Errors for recipes

View Source
var ContainerWorkDir = "/workdir"

ContainerWorkDir specifies directory in container used as work directory

View Source
var ErrVerboseJSON = errors.New("unable to pinpoint the problem in JSON file")

ErrVerboseJSON is raised when JSONVerboseError can't find location of problem in JSON configuration file

Functions

func Build

func Build(
	ctx context.Context,
	target string,
	recursive bool,
	interactive bool,
	config *Config,
	executor func(context.Context, string, *Config, bool) error,
) ([]string, error)

Build recipes, possibly recursively

func Execute

func Execute(ctx context.Context, target string, config *Config, interactive bool) error

Execute a build step

func ExtractSizeFromString

func ExtractSizeFromString(text string) ([]uint64, error)

ExtractSizeFromString uses regex to find size of ROM in MB

func JSONVerboseError

func JSONVerboseError(jsonString string, err error)

JSONVerboseError is for getting more information out of json.Unmarshal() or Decoder.Decode()

Inspiration:
- https://adrianhesketh.com/2017/03/18/getting-line-and-character-positions-from-gos-json-unmarshal-errors/
Docs:
- https://pkg.go.dev/encoding/json#Unmarshal

func StringToSizeMB

func StringToSizeMB(text string) (uint64, error)

StringToSizeMB parses string and returns size in MB

func ValidateConfig

func ValidateConfig(conf Config) error

ValidateConfig is used to validate the configuration struct read out of JSON file

func WriteConfig

func WriteConfig(filepath string, config *Config) error

WriteConfig is for writing Config struct into JSON configuration file

Types

type BlobDef

type BlobDef struct {
	// Path to the blob (either file or directory)
	Path string `validate:"required"`

	// Blobs get renamed when moved to this string
	DestinationFilename string `validate:"required"`

	// Kconfig key specifying the filepath to the blob in defconfig
	KconfigKey string `validate:"required"`

	// Is blob a directory? If blob is file, set to FALSE
	IsDirectory bool `validate:"required,boolean"`
}

BlobDef is used to store information about a single blob. This structure is not exposed to the user, it is filled in automatically based on user input.

type CommonOpts

type CommonOpts struct {
	// Specifies the container toolchain tag to use when building the image.
	// This has an influence on the IASL, GCC and host GCC version that is used to build
	//   the target. You must match the source level and sdk_version.
	// NOTE: Updating the sdk_version might result in different binaries using the
	//   same source code.
	// Examples:
	//   https://ghcr.io/9elements/firmware-action/coreboot_4.19:main
	//   https://ghcr.io/9elements/firmware-action/coreboot_4.19:latest
	//   https://ghcr.io/9elements/firmware-action/edk2-stable202111:latest
	// See https://github.com/orgs/9elements/packages
	SdkURL string `json:"sdk_url" validate:"required"`

	// Gives the (relative) path to the target (firmware) repository.
	// If the current repository contains the selected target, specify: '.'
	// Otherwise the path should point to the target (firmware) repository submodule that
	//   had been previously checked out.
	RepoPath string `json:"repo_path" validate:"required,dirpath"`

	// Specifies the (relative) paths to directories where are produced files (inside Container).
	ContainerOutputDirs []string `json:"container_output_dirs" validate:"dive,dirpath"`

	// Specifies the (relative) paths to produced files (inside Container).
	ContainerOutputFiles []string `json:"container_output_files" validate:"dive,filepath"`

	// Specifies the (relative) path to directory into which place the produced files.
	//   Directories listed in ContainerOutputDirs and files listed in ContainerOutputFiles
	//   will be exported here.
	// Example:
	//   Following setting:
	//     ContainerOutputDirs = []string{"Build/"}
	//     ContainerOutputFiles = []string{"coreboot.rom", "defconfig"}
	//     OutputDir = "myOutput"
	//   Will result in:
	//     myOutput/
	//     ├── Build/
	//     ├── coreboot.rom
	//     └── defconfig
	OutputDir string `json:"output_dir" validate:"required,dirpath"`
}

CommonOpts is common to all targets Used to store data from githubaction.Action For details see action.yml ANCHOR: CommonOpts

func (CommonOpts) GetArtifacts

func (opts CommonOpts) GetArtifacts() *[]container.Artifacts

GetArtifacts returns list of wanted artifacts from container

type Config

type Config struct {
	// defined in coreboot.go
	Coreboot map[string]CorebootOpts `json:"coreboot" validate:"dive"`

	// defined in linux.go
	Linux map[string]LinuxOpts `json:"linux" validate:"dive"`

	// defined in edk2.go
	Edk2 map[string]Edk2Opts `json:"edk2" validate:"dive"`

	// defined in stitching.go
	FirmwareStitching map[string]FirmwareStitchingOpts `json:"firmware_stitching" validate:"dive"`
}

Config is for storing parsed configuration file

func ReadConfig

func ReadConfig(filepath string) (*Config, error)

ReadConfig is for reading and parsing JSON configuration file into Config struct

func (Config) AllModules

func (c Config) AllModules() map[string]FirmwareModule

AllModules method returns slice with all modules

type CorebootBlobs

type CorebootBlobs struct {
	// ** List of supported blobs **
	// NOTE: The blobs may not be added to the ROM, depends on provided defconfig.
	//
	// Gives the (relative) path to the payload.
	// In a 'coreboot' build, the file will be placed at
	//   `3rdparty/blobs/mainboard/$(MAINBOARDDIR)/payload`.
	// The Kconfig `CONFIG_PAYLOAD_FILE` will be changed to point to the same path.
	PayloadFilePath string `json:"payload_file_path" type:"blob"`

	// Gives the (relative) path to the Intel Flash descriptor binary.
	// In a 'coreboot' build, the file will be placed at
	//   `3rdparty/blobs/mainboard/$(CONFIG_MAINBOARD_DIR)/descriptor.bin`.
	// The Kconfig `CONFIG_IFD_BIN_PATH` will be changed to point to the same path.
	IntelIfdPath string `json:"intel_ifd_path" type:"blob"`

	// Gives the (relative) path to the Intel Management engine binary.
	// In a 'coreboot' build, the file will be placed at
	//   `3rdparty/blobs/mainboard/$(CONFIG_MAINBOARD_DIR)/me.bin`.
	// The Kconfig `CONFIG_ME_BIN_PATH` will be changed to point to the same path.
	IntelMePath string `json:"intel_me_path" type:"blob"`

	// Gives the (relative) path to the Intel Gigabit Ethernet engine binary.
	// In a 'coreboot' build, the file will be placed at
	//   `3rdparty/blobs/mainboard/$(CONFIG_MAINBOARD_DIR)/gbe.bin`.
	// The Kconfig `CONFIG_GBE_BIN_PATH` will be changed to point to the same path.
	IntelGbePath string `json:"intel_gbe_path" type:"blob"`

	// Gives the (relative) path to the Intel FSP binary.
	// In a 'coreboot' build, the file will be placed at
	//   `3rdparty/blobs/mainboard/$(CONFIG_MAINBOARD_DIR)/Fsp.fd`.
	// The Kconfig `CONFIG_FSP_FD_PATH` will be changed to point to the same path.
	FspBinaryPath string `json:"fsp_binary_path" type:"blob"`

	// Gives the (relative) path to the Intel FSP header folder.
	// In a 'coreboot' build, the files will be placed at
	//   `3rdparty/blobs/mainboard/$(CONFIG_MAINBOARD_DIR)/Include`.
	// The Kconfig `CONFIG_FSP_HEADER_PATH` will be changed to point to the same path.
	FspHeaderPath string `json:"fsp_header_path" type:"blob"`

	// Gives the (relative) path to the Video BIOS Table binary.
	// In a 'coreboot' build, the files will be placed at
	//   `3rdparty/blobs/mainboard/$(CONFIG_MAINBOARD_DIR)/vbt.bin`.
	// The Kconfig `CONFIG_INTEL_GMA_VBT_FILE` will be changed to point to the same path.
	VbtPath string `json:"vbt_path" type:"blob"`

	// Gives the (relative) path to the Embedded Controller binary.
	// In a 'coreboot' build, the files will be placed at
	//   `3rdparty/blobs/mainboard/$(CONFIG_MAINBOARD_DIR)/ec.bin`.
	// The Kconfig `CONFIG_EC_BIN_PATH` will be changed to point to the same path.
	EcPath string `json:"ec_path" type:"blob"`
}

CorebootBlobs is used to store data specific to coreboot. ANCHOR: CorebootBlobs

type CorebootOpts

type CorebootOpts struct {
	// List of IDs this instance depends on
	Depends []string `json:"depends"`

	// Common options like paths etc.
	CommonOpts

	// Gives the (relative) path to the defconfig that should be used to build the target.
	DefconfigPath string `json:"defconfig_path" validate:"required,filepath"`

	// Coreboot specific options
	Blobs CorebootBlobs `json:"blobs"`
}

CorebootOpts is used to store all data needed to build coreboot. ANCHOR: CorebootOpts

func (CorebootOpts) GetArtifacts

func (opts CorebootOpts) GetArtifacts() *[]container.Artifacts

GetArtifacts returns list of wanted artifacts from container

func (CorebootOpts) GetDepends

func (opts CorebootOpts) GetDepends() []string

GetDepends is used to return list of dependencies

type Edk2Opts

type Edk2Opts struct {
	// List of IDs this instance depends on
	// Example: [ "MyLittleCoreboot", "MyLittleLinux"]
	Depends []string `json:"depends"`

	// Common options like paths etc.
	CommonOpts

	// Specifies target architecture, such as 'x86' or 'arm64'. Currently unused for coreboot.
	// Supported options:
	//   - 'AARCH64'
	//   - 'ARM'
	//   - 'IA32'
	//   - 'IA32X64'
	//   - 'X64'
	Arch string `json:"arch"`

	// Gives the (relative) path to the defconfig that should be used to build the target.
	// For EDK2 this is a one-line file containing the build arguments such as
	//   '-D BOOTLOADER=COREBOOT -D TPM_ENABLE=TRUE -D NETWORK_IPXE=TRUE'.
	DefconfigPath string `json:"defconfig_path" validate:"filepath"`

	// Coreboot specific options
	Edk2Specific `validate:"required"`
}

Edk2Opts is used to store all data needed to build edk2.

func (Edk2Opts) GetArtifacts

func (opts Edk2Opts) GetArtifacts() *[]container.Artifacts

GetArtifacts returns list of wanted artifacts from container

func (Edk2Opts) GetDepends

func (opts Edk2Opts) GetDepends() []string

GetDepends is used to return list of dependencies

type Edk2Specific

type Edk2Specific struct {
	// Specifies which build command to use
	// GCC version is exposed in the container container as USE_GCC_VERSION environment variable
	// Examples:
	//   "source ./edksetup.sh; build -t GCC5 -a IA32 -p UefiPayloadPkg/UefiPayloadPkg.dsc"
	//   "python UefiPayloadPkg/UniversalPayloadBuild.py"
	//   "Intel/AlderLakeFspPkg/BuildFv.sh"
	BuildCommand string `json:"build_command" validate:"required"`
}

Edk2Specific is used to store data specific to coreboot.

TODO: removed because of issue #92
type Edk2Specific struct {
	// Gives the (relative) path to the defconfig that should be used to build the target.
	// For EDK2 this is a one-line file containing the build arguments such as
	//   '-D BOOTLOADER=COREBOOT -D TPM_ENABLE=TRUE -D NETWORK_IPXE=TRUE'.
	//   Some arguments will be added automatically:
	//     '-a <architecture>'
	//     '-p <edk2__platform>'
	//     '-b <edk2__release_type>'
	//     '-t <GCC version>' (defined as part of container toolchain, selected by SdkURL)
	DefconfigPath string `json:"defconfig_path" validate:"filepath"`

	// Specifies the DSC to use when building EDK2
	// Example: UefiPayloadPkg/UefiPayloadPkg.dsc
	Platform string `json:"platform" validate:"filepath"`

	// Specifies the build type to use when building EDK2
	// Supported options: DEBUG, RELEASE
	ReleaseType string `json:"release_type" validate:"required"`

	// Specifies which build command to use
	// Examples:
	//   "source ./edksetup.sh; build"
	//   "python UefiPayloadPkg/UniversalPayloadBuild.py"
	//   "Intel/AlderLakeFspPkg/BuildFv.sh"
	BuildCommand string `json:"build_command" validate:"required"`
}

ANCHOR: Edk2Specific Edk2Specific is used to store data specific to coreboot.

type FirmwareModule

type FirmwareModule interface {
	GetDepends() []string
	GetArtifacts() *[]container.Artifacts
	// contains filtered or unexported methods
}

FirmwareModule interface

type FirmwareStitchingOpts

type FirmwareStitchingOpts struct {
	// List of IDs this instance depends on
	Depends []string `json:"depends"`

	// Common options like paths etc.
	CommonOpts

	// BaseFile into which inject files.
	// !!! Must contain IFD !!!
	// Examples:
	//   - coreboot.rom
	//   - ifd.bin
	BaseFilePath string `json:"base_file_path" validate:"required,filepath"`

	// Platform - passed to all `ifdtool` calls with `--platform`
	Platform string `json:"platform"`

	// List of instructions for ifdtool
	IfdtoolEntries []IfdtoolEntry `json:"ifdtool_entries"`
}

FirmwareStitchingOpts is used to store all data needed to stitch firmware

func (FirmwareStitchingOpts) GetArtifacts

func (opts FirmwareStitchingOpts) GetArtifacts() *[]container.Artifacts

GetArtifacts returns list of wanted artifacts from container

func (FirmwareStitchingOpts) GetDepends

func (opts FirmwareStitchingOpts) GetDepends() []string

GetDepends is used to return list of dependencies

type IfdtoolEntry

type IfdtoolEntry struct {
	// Gives the (relative) path to the binary blob
	Path string `json:"path" validate:"required,filepath"`

	// Region where to inject the file
	// For supported options see `ifdtool --help`
	TargetRegion string `json:"target_region" validate:"required"`

	// Additional (optional) arguments and flags
	// For example:
	//   `--platform adl`
	// For supported options see `ifdtool --help`
	OptionalArguments []string `json:"optional_arguments"`
}

IfdtoolEntry is for injecting a file at `path` into region `TargetRegion`

type LinuxOpts

type LinuxOpts struct {
	// List of IDs this instance depends on
	// Example: [ "MyLittleCoreboot", "MyLittleEdk2"]
	Depends []string `json:"depends"`

	// Common options like paths etc.
	CommonOpts

	// Specifies target architecture, such as 'x86' or 'arm64'.
	// Supported options:
	//   - 'x86'
	//   - 'x86_64'
	//   - 'arm'
	//   - 'arm64'
	Arch string `json:"arch"`

	// Gives the (relative) path to the defconfig that should be used to build the target.
	DefconfigPath string `json:"defconfig_path" validate:"required,filepath"`

	// Coreboot specific options
	LinuxSpecific
}

LinuxOpts is used to store all data needed to build linux

func (LinuxOpts) GetArtifacts

func (opts LinuxOpts) GetArtifacts() *[]container.Artifacts

GetArtifacts returns list of wanted artifacts from container

func (LinuxOpts) GetDepends

func (opts LinuxOpts) GetDepends() []string

GetDepends is used to return list of dependencies

type LinuxSpecific

type LinuxSpecific struct {
	// TODO: either use or remove
	GccVersion string `json:"gcc_version"`
}

LinuxSpecific is used to store data specific to linux ANCHOR: LinuxSpecific

Jump to

Keyboard shortcuts

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