diff options
| author | Laura Peskin <pesk@google.com> | 2024-07-03 14:15:53 -0700 |
|---|---|---|
| committer | eepeep <50846949+eepeep@users.noreply.github.com> | 2024-10-30 22:17:56 +0000 |
| commit | 96eb609f6eb9558e2fab491a2c63a11bb0556471 (patch) | |
| tree | 5f0522570f4da8f0261330d8fe6a02d5e0baa6af /pkg | |
| parent | fb888278a6b21eda7fa63551c83fd17b90305ba1 (diff) | |
pkg/build: add build command for starnix
Co-authored-by: eep@google.com
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/build/build.go | 2 | ||||
| -rw-r--r-- | pkg/build/starnix.go | 116 | ||||
| -rw-r--r-- | pkg/vcs/fuchsia.go | 11 | ||||
| -rw-r--r-- | pkg/vcs/vcs.go | 3 |
4 files changed, 128 insertions, 4 deletions
diff --git a/pkg/build/build.go b/pkg/build/build.go index c9a5b038f..86906a0f7 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -162,6 +162,8 @@ func getBuilder(targetOS, targetArch, vmType string) (builder, error) { return cuttlefish{}, nil } else if vmType == "proxyapp:android" { return android{}, nil + } else if vmType == targets.Starnix { + return starnix{}, nil } } builders := map[string]builder{ diff --git a/pkg/build/starnix.go b/pkg/build/starnix.go new file mode 100644 index 000000000..e629c004e --- /dev/null +++ b/pkg/build/starnix.go @@ -0,0 +1,116 @@ +// Copyright 2024 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package build + +import ( + "fmt" + "os" + "path/filepath" + "strings" + "time" + + "github.com/google/syzkaller/pkg/osutil" + "github.com/google/syzkaller/sys/targets" + starnixVM "github.com/google/syzkaller/vm/starnix" +) + +type starnix struct{} + +// The name of the Fuchsia assembly override defined in `overrideRule`. +const overrideName = "syzkaller_starnix" + +// A Fuchsia assembly override definition adding a package containing fuzzing dependencies. +var overrideRule = fmt.Sprintf(`import("//build/assembly/developer_overrides.gni") + +assembly_developer_overrides("%s") { + testonly = true + base_packages = [ + "//src/testing/fuzzing/syzkaller/starnix:syzkaller_starnix", + ] +} +`, overrideName) + +func (st starnix) build(params Params) (ImageDetails, error) { + sysTarget := targets.Get(targets.Linux, params.TargetArch) + arch := sysTarget.KernelArch + if arch != "x86_64" { + return ImageDetails{}, fmt.Errorf("unsupported starnix arch %v", arch) + } + arch = "x64" + product := fmt.Sprintf("%s.%s", "workbench_eng", arch) + + localDir := filepath.Join(params.KernelDir, "local") + if err := os.MkdirAll(filepath.Join(params.KernelDir, "local"), 0755); err != nil { + return ImageDetails{}, err + } + overridePath := filepath.Join(localDir, "BUILD.gn") + if err := os.WriteFile(overridePath, []byte(overrideRule), 0660); err != nil { + return ImageDetails{}, err + } + if err := osutil.SandboxChown(overridePath); err != nil { + return ImageDetails{}, err + } + if err := osutil.SandboxChown(localDir); err != nil { + return ImageDetails{}, err + } + if _, err := runSandboxed( + time.Hour, + params.KernelDir, + "scripts/fx", "--dir", "out/"+arch, + "set", product, + "--assembly-override", fmt.Sprintf("//products/workbench/*=//local:%s", overrideName), + ); err != nil { + return ImageDetails{}, err + } + + if _, err := runSandboxed(time.Hour*2, params.KernelDir, "scripts/fx", "build"); err != nil { + return ImageDetails{}, err + } + ffxBinary, err := starnixVM.GetToolPath(params.KernelDir, "ffx") + if err != nil { + return ImageDetails{}, err + } + productBundlePathRaw, err := runSandboxed( + 30*time.Second, + params.KernelDir, + ffxBinary, + "-c", "log.enabled=false,ffx.analytics.disabled=true,daemon.autostart=false", + "config", "get", "product.path", + ) + if err != nil { + return ImageDetails{}, err + } + productBundlePath := strings.Trim(string(productBundlePathRaw), "\"\n") + fxfsPathRaw, err := runSandboxed( + 30*time.Second, + params.KernelDir, + ffxBinary, + "-c", "log.enabled=false,ffx.analytics.disabled=true,daemon.autostart=false", + "product", "get-image-path", productBundlePath, + "--slot", "a", + "--image-type", "fxfs", + ) + if err != nil { + return ImageDetails{}, err + } + fxfsPath := strings.Trim(string(fxfsPathRaw), "\"\n") + if err := osutil.CopyFile(fxfsPath, filepath.Join(params.OutputDir, "image")); err != nil { + return ImageDetails{}, err + } + kernelObjPath := filepath.Join(params.KernelDir, "out", arch, "exe.unstripped", "starnix_kernel") + if err := osutil.CopyFile(kernelObjPath, filepath.Join(params.OutputDir, "obj", "vmlinux")); err != nil { + return ImageDetails{}, err + } + return ImageDetails{}, nil +} + +func (st starnix) clean(params Params) error { + _, err := runSandboxed( + time.Hour, + params.KernelDir, + "scripts/fx", "--dir", "out/"+params.TargetArch, + "clean", + ) + return err +} diff --git a/pkg/vcs/fuchsia.go b/pkg/vcs/fuchsia.go index dfe4dc597..c2704c8ea 100644 --- a/pkg/vcs/fuchsia.go +++ b/pkg/vcs/fuchsia.go @@ -24,9 +24,12 @@ func newFuchsia(dir string, opts []RepoOpt) *fuchsia { } func (ctx *fuchsia) Poll(repo, branch string) (*Commit, error) { - if repo != "https://fuchsia.googlesource.com" || branch != "master" { - // Fuchsia ecosystem is hard-wired to the main repo. - return nil, fmt.Errorf("fuchsia: can only check out https://fuchsia.googlesource.com/master") + if repo != "https://fuchsia.googlesource.com/fuchsia" || (branch != "main" && branch != "master") { + // Fuchsia ecosystem is hard-wired to the main repo + branch. + // The 'master' branch is a mirror of 'main'. + return nil, fmt.Errorf( + "fuchsia: can only check out 'main' or 'master' branch of https://fuchsia.googlesource.com/fuchsia", + ) } if _, err := runSandboxed(ctx.dir, "./.jiri_root/bin/jiri", "update"); err != nil { if err := ctx.initRepo(); err != nil { @@ -48,7 +51,7 @@ func (ctx *fuchsia) initRepo() error { if err := osutil.SandboxChown(tmpDir); err != nil { return err } - cmd := "curl -s 'https://fuchsia.googlesource.com/fuchsia/+/master/scripts/bootstrap?format=TEXT' |" + + cmd := "curl -s 'https://fuchsia.googlesource.com/fuchsia/+/main/scripts/bootstrap?format=TEXT' |" + "base64 --decode | bash" if _, err := runSandboxed(tmpDir, "bash", "-c", cmd); err != nil { return err diff --git a/pkg/vcs/vcs.go b/pkg/vcs/vcs.go index 17f54d653..cb32a4071 100644 --- a/pkg/vcs/vcs.go +++ b/pkg/vcs/vcs.go @@ -197,6 +197,9 @@ const ( func NewRepo(os, vmType, dir string, opts ...RepoOpt) (Repo, error) { switch os { case targets.Linux: + if vmType == targets.Starnix { + return newFuchsia(dir, opts), nil + } return newLinux(dir, opts, vmType), nil case targets.Fuchsia: return newFuchsia(dir, opts), nil |
