hhfab

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: Apache-2.0 Imports: 61 Imported by: 0

README

How to Build OVMF (CODE and VARS) using EDK2

The Open Virtual Machine Firmware (OVMF) project aims to support firmware for Virtual Machines using the edk2 code base.

1 - Getting Started with EDK II

Follow the steps described at https://github.com/tianocore/tianocore.github.io/wiki/Using-EDK-II-with-Native-GCC:

Some dependencies: $ sudo apt install build-essential uuid-dev iasl git nasm python-is-python3

Cloning edk2: $ git clone https://github.com/tianocore/edk2

Initialize submodules:

$ cd edk2
$ git submodule update --init

Compile build tools:

$ make -C BaseTools
$ ./edksetup.sh

Setup build shell environment:

$ export EDK_TOOLS_PATH=$HOME/src/edk2/BaseTools
$ ./edksetup.sh BaseTools

Modify Conf Files - edk2/Conf/target.txt:

ACTIVE_PLATFORM = EmulatorPkg/EmulatorPkg.dsc
TOOL_CHAIN_TAG  = GCC114
TARGET_ARCH     = X64

Modify EmulatorPkg Files - edk2/EmulatorPkg/EmulatorPkg.dsc:

#
# Network definition
#
DEFINE NETWORK_SNP_ENABLE       = FALSE
DEFINE NETWORK_IP6_ENABLE       = FALSE
DEFINE NETWORK_TLS_ENABLE       = FALSE
DEFINE NETWORK_HTTP_BOOT_ENABLE = FALSE
DEFINE NETWORK_HTTP_ENABLE      = FALSE
DEFINE NETWORK_ISCSI_ENABLE     = FALSE
DEFINE SECURE_BOOT_ENABLE       = FALSE

Note:

$gcc --version
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

Once you have modified Conf/target.txt and EmulatorPkg/EmulatorPkg.dsc, you can run the build command:

$ cd edk2/OvmfPkg
$ ./build.sh

If successful, you should now have an OVMF.Fd file under the Build sub-directory. The exact directory under the Build directory will depend upon the toolchain, dsc, and processor architecture:

$cd edk2/Build/OvmfX64/DEBUG_GCC5/FV/
$ ls
OVMF.fd
OVMF_VARS.fd

Files used in hhfab/vlab:

OVMF.fd = onie_efi_code.fd
OVMF_VARS.fd = onie_efi_vars.fd
onie-kvm_x86_64.qcow2 - To generate this file, follow the procedure described at https://github.com/githedgehog/onie_kvm.

References: https://github.com/tianocore/tianocore.github.io/wiki/Getting-Started-with-EDK-II https://github.com/tianocore/tianocore.github.io/wiki/How-to-build-OVMF https://github.com/tianocore/edk2/blob/master/OvmfPkg/README http://www.tianocore.org/ovmf/ https://github.com/tianocore/ https://github.com/tianocore/tianocore.github.io/wiki/Training https://github.com/tianocore/tianocore.github.io/wiki/UEFI-EDKII-Learning-Dev

Documentation

Index

Constants

View Source
const (
	RegistryConfigFile = ".registry.yaml"
	FabConfigFile      = "fab.yaml"
	IncludeDir         = "include"
	ResultDir          = "result"
	DefaultRepo        = "ghcr.io"
	DefaultPrefix      = "githedgehog"
	YAMLExt            = ".yaml"
)
View Source
const (
	ServerNamePrefix = "server-"
	VSIPerfSpeed     = 1
)
View Source
const (
	VLABDir        = "vlab"
	VLABConfigFile = "config.yaml"
	VLABSSHKeyFile = "sshkey"
	VLABVMsDir     = "vms"

	VLABSwitchMACTmpl = "0c:20:12:ff:%02x:00"
	VLABMACTmpl       = "0c:20:12:fe:%02x:%02x"

	HHFabCfgPrefix     = ".hhfab.githedgehog.com"
	HHFabCfgType       = "type" + HHFabCfgPrefix
	HHFabCfgTypeHW     = "hw"
	HHFabCfgLinkPrefix = "link" + HHFabCfgPrefix + "/"
	HHFabCfgPCIPrefix  = "pci@"
)
View Source
const (
	VLABPCIBridgePrefix  = "pcibr"
	VLABNICsPerPCIBridge = 32
	VLABPCIBridges       = 2
	VLABMaxNICs          = VLABNICsPerPCIBridge * VLABPCIBridges
	VLABBaseSSHPort      = 22000
	VLABBaseDirectPort   = 22100
	VLABTapPrefix        = "hhtap"
	VLABBridge           = "hhbr"
	VLABUUIDPrefix       = "77924ab4-a93b-41d4-928e-"
	VLABUUIDTmpl         = VLABUUIDPrefix + "%012d"
)
View Source
const (
	NICTypeSep         = ":"
	NICTypeNoop        = "noop"
	NICTypeUsernet     = "usernet"
	NICTypeManagement  = "management"
	NICTypeDirect      = "direct"
	NICTypePassthrough = "passthrough"
)
View Source
const (
	VLABOSImageFile  = "os.img"
	VLABEFICodeFile  = "efi_code.fd"
	VLABEFIVarsFile  = "efi_vars.fd"
	VLABUSBImageFile = "usb.img"
	VLABISOImageFile = "usb.iso"

	VLABSerialLog  = "serial.log"
	VLABSerialSock = "serial.sock"
	VLABMonSock    = "mon.sock"
	VLABQMPSock    = "qmp.sock"

	VLABCmdSudo       = "sudo"
	VLABCmdQemuImg    = "qemu-img"
	VLABCmdQemuSystem = "qemu-system-x86_64"
	VLABCmdSocat      = "socat"
	VLABCmdSSH        = "ssh"
	VLABCmdLess       = "less"
	VLABCmdExpect     = "expect"

	VLABIgnition = "ignition.json"

	VLABKubeConfig = "kubeconfig"

	VLABEnvPDUUsername = "HHFAB_VLAB_PDU_USERNAME"
	VLABEnvPDUPassword = "HHFAB_VLAB_PDU_PASSWORD" //nolint:gosec
)
View Source
const (
	DefaultVLABGeneratedFile = "vlab.generated.yaml"
)

Variables

View Source
var (
	ErrExist    = fmt.Errorf("already exists")
	ErrNotExist = fmt.Errorf("does not exist")
	ErrNotDir   = fmt.Errorf("not a directory")
)
View Source
var (
	ErrConsole = errors.New("Connection to console failed")
	ErrLogin   = errors.New("Login to switch failed")
	ErrInstall = errors.New("OS Install failed")
	ErrHHFab   = errors.New("hhfab vlab serial failed")
	ErrUnknown = errors.New("Unknown expect error")
)
View Source
var DefaultSizes = VMSizes{
	Control: VMSize{CPU: 6, RAM: 6144, Disk: 100},
	Switch:  VMSize{CPU: 4, RAM: 5120, Disk: 50},
	Server:  VMSize{CPU: 2, RAM: 768, Disk: 10},
}
View Source
var ErrExit = fmt.Errorf("exit")
View Source
var SSHQuietFlags = []string{
	"-o", "GlobalKnownHostsFile=/dev/null",
	"-o", "UserKnownHostsFile=/dev/null",
	"-o", "StrictHostKeyChecking=no",
	"-o", "LogLevel=ERROR",
}

Functions

func AddrsFrom

func AddrsFrom(prefixes ...netip.Prefix) iter.Seq[netip.Prefix]

func Build

func Build(ctx context.Context, workDir, cacheDir string, opts BuildOpts) error

func CheckStaleVMs

func CheckStaleVMs(ctx context.Context, kill bool) ([]int32, error)

func CollectN

func CollectN[E any](n int, seq iter.Seq[E]) []E

func DoSwitchPower added in v0.33.0

func DoSwitchPower(ctx context.Context, workDir, cacheDir string, opts SwitchPowerOpts) error

func DoSwitchReinstall added in v0.33.0

func DoSwitchReinstall(ctx context.Context, workDir, cacheDir string, opts SwitchReinstallOpts) error

func DoVLABSSH

func DoVLABSSH(ctx context.Context, workDir, cacheDir, name string, args []string) error

func DoVLABSerial

func DoVLABSerial(ctx context.Context, workDir, cacheDir, name string, args []string) error

func DoVLABSerialLog

func DoVLABSerialLog(ctx context.Context, workDir, cacheDir, name string, args []string) error

func DoVLABSetupPeerings

func DoVLABSetupPeerings(ctx context.Context, workDir, cacheDir string, opts SetupPeeringsOpts) error

func DoVLABSetupVPCs

func DoVLABSetupVPCs(ctx context.Context, workDir, cacheDir string, opts SetupVPCsOpts) error

func DoVLABTestConnectivity

func DoVLABTestConnectivity(ctx context.Context, workDir, cacheDir string, opts TestConnectivityOpts) error

func Init

func Init(ctx context.Context, c InitConfig) error

func PreparePassthrough

func PreparePassthrough(_ context.Context, devs []string) error

func PrepareTaps

func PrepareTaps(_ context.Context, count int) error

func SubPrefixesFrom

func SubPrefixesFrom(bits int, prefixes ...netip.Prefix) iter.Seq[netip.Prefix]

func VLABGenerate

func VLABGenerate(ctx context.Context, workDir, cacheDir string, builder VLABBuilder, target string) error

func VLABUp

func VLABUp(ctx context.Context, workDir, cacheDir string, opts VLABUpOpts) error

func VLANsFrom

func VLANsFrom(ranges ...meta.VLANRange) iter.Seq[uint16]

func Validate

func Validate(ctx context.Context, workDir, cacheDir string, hMode HydrateMode) error

func Versions

func Versions(ctx context.Context, workDir, cacheDir string, hMode HydrateMode) error

Types

type BuildOpts

type BuildOpts struct {
	HydrateMode HydrateMode
	BuildMode   recipe.BuildMode
}

type Config

type Config struct {
	WorkDir  string
	CacheDir string
	RegistryConfig
	Fab      fabapi.Fabricator
	Controls []fabapi.ControlNode
	Wiring   client.Reader
}

func (*Config) PrepareVLAB

func (c *Config) PrepareVLAB(ctx context.Context, opts VLABUpOpts) (*VLAB, error)

func (*Config) SetupPeerings

func (c *Config) SetupPeerings(ctx context.Context, vlab *VLAB, opts SetupPeeringsOpts) error

func (*Config) SetupVPCs

func (c *Config) SetupVPCs(ctx context.Context, vlab *VLAB, opts SetupVPCsOpts) error

func (*Config) TestConnectivity

func (c *Config) TestConnectivity(ctx context.Context, vlab *VLAB, opts TestConnectivityOpts) error

func (*Config) VLABAccess

func (c *Config) VLABAccess(ctx context.Context, vlab *VLAB, t VLABAccessType, name string, inArgs []string) error

func (*Config) VLABRun

func (c *Config) VLABRun(ctx context.Context, vlab *VLAB, opts VLABRunOpts) error

func (*Config) VLABSwitchPower added in v0.33.0

func (c *Config) VLABSwitchPower(ctx context.Context, opts SwitchPowerOpts) error

func (*Config) VLABSwitchReinstall added in v0.33.0

func (c *Config) VLABSwitchReinstall(ctx context.Context, opts SwitchReinstallOpts) error

type HydrateMode

type HydrateMode string
const (
	HydrateModeNever        HydrateMode = "never"
	HydrateModeIfNotPresent HydrateMode = "if-not-present"
	HydrateModeOverride     HydrateMode = "override"
)

type HydrationStatus

type HydrationStatus string
const (
	HydrationStatusNone    HydrationStatus = "none"
	HydrationStatusPartial HydrationStatus = "partial"
	HydrationStatusFull    HydrationStatus = "full"
)

type InitConfig

type InitConfig struct {
	WorkDir            string
	CacheDir           string
	Repo               string
	Prefix             string
	ImportConfig       string
	Force              bool
	Wiring             []string
	ImportHostUpstream bool
	fab.InitConfigInput
}

type OnReady

type OnReady string
const (
	OnReadyExit             OnReady = "exit"
	OnReadySetupVPCs        OnReady = "setup-vpcs"
	OnReadySwitchReinstall  OnReady = "switch-reinstall"
	OnReadyTestConnectivity         = "test-connectivity"
)

type RegistryConfig

type RegistryConfig struct {
	Repo   string `json:"repo,omitempty"`
	Prefix string `json:"prefix,omitempty"`
}

type SetupPeeringsOpts

type SetupPeeringsOpts struct {
	WaitSwitchesReady bool
	Requests          []string
}

type SetupVPCsOpts

type SetupVPCsOpts struct {
	WaitSwitchesReady bool
	ForceCleanup      bool
	VLANNamespace     string
	IPv4Namespace     string
	ServersPerSubnet  int
	SubnetsPerVPC     int
	DNSServers        []string
	TimeServers       []string
	InterfaceMTU      uint16
}

type SwitchPowerOpts added in v0.33.0

type SwitchPowerOpts struct {
	Switches    []string   // All switches if empty
	Action      pdu.Action // Power action (e.g., on, off, cycle)
	PDUUsername string
	PDUPassword string
}

type SwitchReinstallMode added in v0.33.0

type SwitchReinstallMode string
const (
	ReinstallModeReboot    SwitchReinstallMode = "reboot"
	ReinstallModeHardReset SwitchReinstallMode = "hard-reset"
)

type SwitchReinstallOpts added in v0.33.0

type SwitchReinstallOpts struct {
	Switches       []string            // All switches if empty
	Mode           SwitchReinstallMode // "reboot" or "hard-reset"
	SwitchUsername string              // Username for switch access (reboot mode only )
	SwitchPassword string              // Password for switch access (reboot mode only)
	PDUUsername    string              // (hard-reset mode only)
	PDUPassword    string              // (hard-reset mode only)
	WaitReady      bool                // Wait for the switch to be ready
}

type TestConnectivityOpts

type TestConnectivityOpts struct {
	WaitSwitchesReady bool
	PingsCount        int
	PingsParallel     int64
	IPerfsSeconds     int
	IPerfsMinSpeed    float64
	IPerfsParallel    int64
	CurlsCount        int
	CurlsParallel     int64
}

type VLAB

type VLAB struct {
	SSHKey       string
	VMs          []VM
	Taps         int
	Passthroughs []string
}

type VLABAccessInfo

type VLABAccessInfo struct {
	SSHPort      uint // local ssh port
	SerialSock   string
	SerialLog    string
	IsSwitch     bool   // ssh through control node only
	RemoteSerial string // ssh to get serial
}

type VLABAccessType

type VLABAccessType string
const (
	VLABAccessSSH       VLABAccessType = "ssh"
	VLABAccessSerial    VLABAccessType = "serial"
	VLABAccessSerialLog VLABAccessType = "serial log"
)

type VLABBuilder

type VLABBuilder struct {
	SpinesCount       uint8  // number of spines to generate
	FabricLinksCount  uint8  // number of links for each spine <> leaf pair
	MCLAGLeafsCount   uint8  // number of MCLAG server-leafs to generate
	ESLAGLeafGroups   string // eslag leaf groups - comma separated list of number of ESLAG switches in each group, should be 2-4 per group, e.g. 2,4,2 for 3 groups with 2, 4 and 2 switches
	OrphanLeafsCount  uint8  // number of non-MCLAG server-leafs to generate
	MCLAGSessionLinks uint8  // number of MCLAG session links to generate
	MCLAGPeerLinks    uint8  // number of MCLAG peer links to generate
	VPCLoopbacks      uint8  // number of VPC loopbacks to generate per leaf switch
	MCLAGServers      uint8  // number of MCLAG servers to generate for MCLAG switches
	ESLAGServers      uint8  // number of ESLAG servers to generate for ESLAG switches
	UnbundledServers  uint8  // number of unbundled servers to generate for switches (only for one of the first switch in the redundancy group or orphan switch)
	BundledServers    uint8  // number of bundled servers to generate for switches (only for one of the second switch in the redundancy group or orphan switch)
	NoSwitches        bool   // do not generate any switches
	// contains filtered or unexported fields
}

func (*VLABBuilder) Build

func (b *VLABBuilder) Build(ctx context.Context, l *apiutil.Loader, fabricMode meta.FabricMode) error

type VLABConfig

type VLABConfig struct {
	SSHKey string              `json:"-"`
	Sizes  VMSizes             `json:"sizes"`
	VMs    map[string]VMConfig `json:"vms"`
}

type VLABRunOpts

type VLABRunOpts struct {
	KillStale          bool
	ControlsRestricted bool
	ServersRestricted  bool
	BuildMode          recipe.BuildMode
	ControlUpgrade     bool
	FailFast           bool
	OnReady            []string
}

type VLABUpOpts

type VLABUpOpts struct {
	HydrateMode HydrateMode
	NoCreate    bool
	ReCreate    bool
	BuildMode   recipe.BuildMode
	VLABRunOpts
}

type VM

type VM struct {
	ID         uint
	Name       string
	Type       VMType
	Restricted bool
	NICs       []string
	Size       VMSize
}

type VMConfig

type VMConfig struct {
	Type VMType            `json:"type"`
	NICs map[string]string `json:"nics"`
}

type VMSize

type VMSize struct {
	CPU  uint `json:"cpu"`  // in cores
	RAM  uint `json:"ram"`  // in MB
	Disk uint `json:"disk"` // in GB
}

type VMSizes

type VMSizes struct {
	Control VMSize `json:"control"`
	Switch  VMSize `json:"switch"`
	Server  VMSize `json:"server"`
}

type VMType

type VMType string
const (
	VMTypeControl VMType = "control"
	VMTypeSwitch  VMType = "switch"
	VMTypeServer  VMType = "server"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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