Skip to content

Commit

Permalink
refactor(action): refactor edk2
Browse files Browse the repository at this point in the history
- edk2: read defconfig_path file only if provided and only if exists
- a lot of code in edk2 was just commented out since it might be used
  later for simplification of usage by the end user
  • Loading branch information
AtomicFS committed Jan 24, 2024
1 parent b26acf4 commit b013bb1
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 19 deletions.
3 changes: 2 additions & 1 deletion action/recipes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type CommonOpts struct {
// Specifies the (relative) path to directory into which place the produced files.
OutputDir string `json:"output_dir" validate:"required,dirpath"`
}

// ANCHOR_END: CommonOpts

// Config is for storing parsed configuration file
Expand Down Expand Up @@ -111,7 +112,7 @@ func ReadConfig(filepath string) (Config, error) {
// Validate config
err = ValidateConfig(payload)
if err != nil {
log.Fatal("Provided JSON configuration file failed validation")
log.Print("Provided JSON configuration file failed validation")
return Config{}, err
}

Expand Down
2 changes: 2 additions & 0 deletions action/recipes/coreboot.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type CorebootBlobs struct {
// The Kconfig `CONFIG_EC_BIN_PATH` will be changed to point to the same path.
EcPath string `json:"ec_path" type:"blob"`
}

// ANCHOR_END: CorebootBlobs

// CorebootOpts is used to store all data needed to build coreboot.
Expand All @@ -106,6 +107,7 @@ type CorebootOpts struct {
// Coreboot specific options
Blobs CorebootBlobs `json:"blobs"`
}

// ANCHOR_END: CorebootOpts

// corebootProcessBlobs is used to fill figure out blobs from provided data.
Expand Down
65 changes: 51 additions & 14 deletions action/recipes/edk2.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,54 @@ import (
"context"
"errors"
"fmt"
"log"
"os"

"dagger.io/dagger"
"github.com/9elements/firmware-action/action/container"
)

var errUnknownArch = errors.New("unknown architecture")

// Edk2Specific is used to store data specific to coreboot.
// ANCHOR: Edk2Specific
/* 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 docker 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:"required"`
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 Edk2Specific struct {
// Specifies which build command to use
// GCC version is exposed in the docker 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"`
}

// ANCHOR_END: Edk2Specific

// Edk2Opts is used to store all data needed to build edk2.
Expand All @@ -40,11 +69,6 @@ type Edk2Opts 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 docker toolchain, selected by SdkURL)
DefconfigPath string `json:"defconfig_path" validate:"filepath"`

// Coreboot specific options
Expand Down Expand Up @@ -77,12 +101,15 @@ func edk2(ctx context.Context, client *dagger.Client, opts *Edk2Opts, dockerfile
}

// Get GCC version from environment variable
/* TODO: removed because of issue #92
gccVersion, err := myContainer.EnvVariable(ctx, "USE_GCC_VERSION")
if err != nil {
return err
}
*/

// Figure out target architectures
/* TODO: removed because of issue #92
architectures := map[string]string{
"AARCH64": "-a AARCH64",
"ARM": "-a ARM",
Expand All @@ -94,18 +121,28 @@ func edk2(ctx context.Context, client *dagger.Client, opts *Edk2Opts, dockerfile
if !ok {
return fmt.Errorf("%w: %s", errUnknownArch, opts.Arch)
}
*/

// Assemble build arguments
// and read content of the config file at "defconfig_path"
buildArgs := fmt.Sprintf("%s -p %s -b %s -t GCC%s", arch, opts.Platform, opts.ReleaseType, gccVersion)
defconfigFileArgs, err := os.ReadFile(opts.DefconfigPath)
if err != nil {
return err
// NOTE: removed because of issue #92
// buildArgs := fmt.Sprintf("%s -p %s -b %s -t GCC%s", arch, opts.Specific.Platform, opts.Specific.ReleaseType, gccVersion)
var defconfigFileArgs []byte
if opts.DefconfigPath != "" {
if _, err := os.Stat(opts.DefconfigPath); !errors.Is(err, os.ErrNotExist) {
defconfigFileArgs, err = os.ReadFile(opts.DefconfigPath)
if err != nil {
return err
}
} else {
log.Printf("Failed to read file '%s' as defconfig_path: file does not exist", opts.DefconfigPath)
}
}

// Assemble commands to build
buildSteps := [][]string{
{"bash", "-c", fmt.Sprintf("source ./edksetup.sh; build %s %s", buildArgs, string(defconfigFileArgs))},
//{"bash", "-c", fmt.Sprintf("source ./edksetup.sh; build %s %s", buildArgs, string(defconfigFileArgs))},
{"bash", "-c", fmt.Sprintf("%s %s", opts.BuildCommand, string(defconfigFileArgs))},
}

// Build
Expand Down
3 changes: 1 addition & 2 deletions action/recipes/edk2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ func TestEdk2(t *testing.T) {
CommonOpts: common,
DefconfigPath: "defconfig",
Edk2Specific: Edk2Specific{
Platform: "UefiPayloadPkg/UefiPayloadPkg.dsc",
ReleaseType: "DEBUG",
BuildCommand: "source ./edksetup.sh; build -a X64 -p UefiPayloadPkg/UefiPayloadPkg.dsc -b DEBUG -t GCC5",
},
},
version: "edk2-stable202105",
Expand Down
1 change: 1 addition & 0 deletions action/recipes/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type LinuxSpecific struct {
// TODO: either use or remove
GccVersion string `json:"gcc_version"`
}

// ANCHOR_END: LinuxSpecific

// LinuxOpts is used to store all data needed to build linux
Expand Down
3 changes: 1 addition & 2 deletions tests/example_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
"repo_path": "Edk2/",
"defconfig_path": "edk2_config.cfg",
"output_dir": "output/",
"platform": "UefiPayloadPkg/UefiPayloadPkg.dsc",
"release_type": "DEBUG"
"build_command": "source ./edksetup.sh; build -a X64 -p UefiPayloadPkg/UefiPayloadPkg.dsc -b DEBUG -t GCC5"
}
}
}

0 comments on commit b013bb1

Please sign in to comment.