bootdeploy: support zboot kernel image (MR 44)
As we move towards UEFI on more devices, we want to use systemd-boot and kernel images built with CONFIG_ZBOOT. However, these images aren't compatible with existing Android bootloaders. As a result, we must install both the old vmlinuz image for old bootloaders, and the fancy new self-extracting EFI image. When using systemd_boot, use linux.efi as the kernel file name instead of globbing on vmlinuz*. Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
This commit is contained in:
committed by
Clayton Craft
parent
98bdb23f01
commit
f0b3c1d992
@@ -10,32 +10,32 @@ import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/pkgs/deviceinfo"
|
||||
)
|
||||
|
||||
type BootDeploy struct {
|
||||
inDir string
|
||||
outDir string
|
||||
ubootBoardname string
|
||||
inDir string
|
||||
outDir string
|
||||
devinfo deviceinfo.DeviceInfo
|
||||
}
|
||||
|
||||
// New returns a new BootDeploy, which then runs:
|
||||
//
|
||||
// boot-deploy -d indir -o outDir
|
||||
//
|
||||
// ubootBoardname is used for copying in some u-boot files prior to running
|
||||
// boot-deploy. This is optional, passing an empty string is ok if this is not
|
||||
// needed.
|
||||
func New(inDir, outDir, ubootBoardname string) *BootDeploy {
|
||||
// devinfo is used to access some deviceinfo values, such as UbootBoardname
|
||||
// and GenerateSystemdBoot
|
||||
func New(inDir string, outDir string, devinfo deviceinfo.DeviceInfo) *BootDeploy {
|
||||
return &BootDeploy{
|
||||
inDir: inDir,
|
||||
outDir: outDir,
|
||||
ubootBoardname: ubootBoardname,
|
||||
inDir: inDir,
|
||||
outDir: outDir,
|
||||
devinfo: devinfo,
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BootDeploy) Run() error {
|
||||
|
||||
if err := copyUbootFiles(b.inDir, b.ubootBoardname); errors.Is(err, os.ErrNotExist) {
|
||||
if err := copyUbootFiles(b.inDir, b.devinfo.UbootBoardname); errors.Is(err, os.ErrNotExist) {
|
||||
log.Println("u-boot files copying skipped: ", err)
|
||||
} else {
|
||||
if err != nil {
|
||||
@@ -43,15 +43,9 @@ func (b *BootDeploy) Run() error {
|
||||
}
|
||||
}
|
||||
|
||||
return bootDeploy(b.inDir, b.outDir)
|
||||
}
|
||||
|
||||
func bootDeploy(workDir string, outDir string) error {
|
||||
// boot-deploy expects the kernel to be in the same dir as initramfs.
|
||||
// Assume that the kernel is in the output dir...
|
||||
kernels, _ := filepath.Glob(filepath.Join(outDir, "vmlinuz*"))
|
||||
if len(kernels) == 0 {
|
||||
return errors.New("Unable to find any kernels at " + filepath.Join(outDir, "vmlinuz*"))
|
||||
kernels, err := getKernelPath(b.outDir, b.devinfo.GenerateSystemdBoot == "true")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Pick a kernel that does not have suffixes added by boot-deploy
|
||||
@@ -71,7 +65,7 @@ func bootDeploy(workDir string, outDir string) error {
|
||||
defer kernFd.Close()
|
||||
|
||||
kernFilename := path.Base(kernFile)
|
||||
kernFileCopy, err := os.Create(filepath.Join(workDir, kernFilename))
|
||||
kernFileCopy, err := os.Create(filepath.Join(b.inDir, kernFilename))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -87,8 +81,8 @@ func bootDeploy(workDir string, outDir string) error {
|
||||
cmd := exec.Command("boot-deploy",
|
||||
"-i", "initramfs",
|
||||
"-k", kernFilename,
|
||||
"-d", workDir,
|
||||
"-o", outDir,
|
||||
"-d", b.inDir,
|
||||
"-o", b.outDir,
|
||||
"initramfs-extra")
|
||||
|
||||
cmd.Stdout = os.Stdout
|
||||
@@ -100,6 +94,22 @@ func bootDeploy(workDir string, outDir string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getKernelPath(outDir string, zboot bool) ([]string, error) {
|
||||
kernFile := "vmlinuz*"
|
||||
|
||||
if zboot {
|
||||
kernFile = "linux.efi"
|
||||
}
|
||||
|
||||
var kernels []string
|
||||
kernels, _ = filepath.Glob(filepath.Join(outDir, kernFile))
|
||||
if len(kernels) == 0 {
|
||||
return nil, errors.New("Unable to find any kernels at " + filepath.Join(outDir, kernFile))
|
||||
}
|
||||
|
||||
return kernels, nil
|
||||
}
|
||||
|
||||
// Copy copies the file at srcFile path to a new file at dstFile path
|
||||
func copy(srcFile, dstFile string) error {
|
||||
out, err := os.Create(dstFile)
|
||||
|
Reference in New Issue
Block a user