aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/build/android_linux.go
diff options
context:
space:
mode:
authorKris Alder <kalder@google.com>2022-05-03 11:05:34 -0700
committerDmitry Vyukov <dvyukov@google.com>2022-05-06 08:59:20 +0200
commite60b110364688cf334ec68e073edf8d9cebc9fcb (patch)
treee10026e4c1246c6b4d7206da4a7cd3acbff8343e /pkg/build/android_linux.go
parentabda9b1a98d331fa672f556e33f18df2eed424bd (diff)
pkg/build: refactor cuttlefish image code to embedFiles()
Since most of the image mounting code is duplicated, we can instead extract it to an embedFiles() function that takes a callback. The Linux- or Android-specific code can be in the callback.
Diffstat (limited to 'pkg/build/android_linux.go')
-rw-r--r--pkg/build/android_linux.go67
1 files changed, 0 insertions, 67 deletions
diff --git a/pkg/build/android_linux.go b/pkg/build/android_linux.go
deleted file mode 100644
index a6e4e086c..000000000
--- a/pkg/build/android_linux.go
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright 2022 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"
- "io/ioutil"
- "os"
- "path/filepath"
- "time"
-
- "golang.org/x/sys/unix"
-
- "github.com/google/syzkaller/pkg/osutil"
-)
-
-// buildCuttlefishImage mounts a disk image, fetches and installs a Cuttlefish emulator binary,
-// and copies in the required kernel artifacts.
-func buildCuttlefishImage(params Params, bzImage, vmlinux, initramfs string) error {
- tempDir, err := ioutil.TempDir("", "syz-build")
- if err != nil {
- return err
- }
- defer os.RemoveAll(tempDir)
- imageFile := filepath.Join(tempDir, "image")
- if err := osutil.CopyFile(params.UserspaceDir, imageFile); err != nil {
- return err
- }
- loop, loopFile, err := linuxSetupLoop(imageFile)
- if err != nil {
- return err
- }
- defer func() {
- unix.IoctlGetInt(loop, unix.LOOP_CLR_FD)
- unix.Close(loop)
- }()
- mountDir := filepath.Join(tempDir, "mnt")
- if err := osutil.MkdirAll(mountDir); err != nil {
- return err
- }
- if err := tryMount(loopFile+"p1", mountDir); err != nil {
- return fmt.Errorf("mount(%vp1, %v) failed: %v", loopFile, mountDir, err)
- }
- defer unix.Unmount(mountDir, 0)
-
- imageHomeDir := filepath.Join(mountDir, "root")
- if _, err := osutil.RunCmd(time.Hour, imageHomeDir, "./fetchcvd"); err != nil {
- return fmt.Errorf("run fetch_cvd: %s", err)
- }
-
- if err := osutil.CopyFile(bzImage, filepath.Join(imageHomeDir, "bzImage")); err != nil {
- return err
- }
- if err := osutil.CopyFile(vmlinux, filepath.Join(imageHomeDir, "vmlinux")); err != nil {
- return err
- }
- if err := osutil.CopyFile(initramfs, filepath.Join(imageHomeDir, "initramfs.img")); err != nil {
- return err
- }
-
- if err := unix.Unmount(mountDir, 0); err != nil {
- return err
- }
-
- return osutil.CopyFile(imageFile, filepath.Join(params.OutputDir, "image"))
-}