From e60b110364688cf334ec68e073edf8d9cebc9fcb Mon Sep 17 00:00:00 2001 From: Kris Alder Date: Tue, 3 May 2022 11:05:34 -0700 Subject: 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. --- pkg/build/android_linux.go | 67 ---------------------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 pkg/build/android_linux.go (limited to 'pkg/build/android_linux.go') 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")) -} -- cgit mrf-deployment