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:
Caleb Connolly
2023-12-04 18:51:39 +00:00
committed by Clayton Craft
parent 98bdb23f01
commit f0b3c1d992
2 changed files with 37 additions and 27 deletions

View File

@@ -154,7 +154,7 @@ func main() {
// Final processing of initramfs / kernel is done by boot-deploy // Final processing of initramfs / kernel is done by boot-deploy
if !disableBootDeploy { if !disableBootDeploy {
if err := bootDeploy(workDir, *outDir, devinfo.UbootBoardname); err != nil { if err := bootDeploy(workDir, *outDir, devinfo); err != nil {
log.Println(err) log.Println(err)
log.Println("boot-deploy failed") log.Println("boot-deploy failed")
retCode = 1 retCode = 1
@@ -163,10 +163,10 @@ func main() {
} }
} }
func bootDeploy(workDir, outDir, ubootBoardname string) error { func bootDeploy(workDir string, outDir string, devinfo deviceinfo.DeviceInfo) error {
log.Print("== Using boot-deploy to finalize/install files ==") log.Print("== Using boot-deploy to finalize/install files ==")
defer misc.TimeFunc(time.Now(), "boot-deploy") defer misc.TimeFunc(time.Now(), "boot-deploy")
bd := bootdeploy.New(workDir, outDir, ubootBoardname) bd := bootdeploy.New(workDir, outDir, devinfo)
return bd.Run() return bd.Run()
} }

View File

@@ -10,32 +10,32 @@ import (
"path" "path"
"path/filepath" "path/filepath"
"strings" "strings"
"gitlab.com/postmarketOS/postmarketos-mkinitfs/pkgs/deviceinfo"
) )
type BootDeploy struct { type BootDeploy struct {
inDir string inDir string
outDir string outDir string
ubootBoardname string devinfo deviceinfo.DeviceInfo
} }
// New returns a new BootDeploy, which then runs: // New returns a new BootDeploy, which then runs:
// //
// boot-deploy -d indir -o outDir // boot-deploy -d indir -o outDir
// //
// ubootBoardname is used for copying in some u-boot files prior to running // devinfo is used to access some deviceinfo values, such as UbootBoardname
// boot-deploy. This is optional, passing an empty string is ok if this is not // and GenerateSystemdBoot
// needed. func New(inDir string, outDir string, devinfo deviceinfo.DeviceInfo) *BootDeploy {
func New(inDir, outDir, ubootBoardname string) *BootDeploy {
return &BootDeploy{ return &BootDeploy{
inDir: inDir, inDir: inDir,
outDir: outDir, outDir: outDir,
ubootBoardname: ubootBoardname, devinfo: devinfo,
} }
} }
func (b *BootDeploy) Run() error { func (b *BootDeploy) Run() error {
if err := copyUbootFiles(b.inDir, b.devinfo.UbootBoardname); errors.Is(err, os.ErrNotExist) {
if err := copyUbootFiles(b.inDir, b.ubootBoardname); errors.Is(err, os.ErrNotExist) {
log.Println("u-boot files copying skipped: ", err) log.Println("u-boot files copying skipped: ", err)
} else { } else {
if err != nil { if err != nil {
@@ -43,15 +43,9 @@ func (b *BootDeploy) Run() error {
} }
} }
return bootDeploy(b.inDir, b.outDir) kernels, err := getKernelPath(b.outDir, b.devinfo.GenerateSystemdBoot == "true")
} if err != nil {
return err
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*"))
} }
// Pick a kernel that does not have suffixes added by boot-deploy // 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() defer kernFd.Close()
kernFilename := path.Base(kernFile) kernFilename := path.Base(kernFile)
kernFileCopy, err := os.Create(filepath.Join(workDir, kernFilename)) kernFileCopy, err := os.Create(filepath.Join(b.inDir, kernFilename))
if err != nil { if err != nil {
return err return err
} }
@@ -87,8 +81,8 @@ func bootDeploy(workDir string, outDir string) error {
cmd := exec.Command("boot-deploy", cmd := exec.Command("boot-deploy",
"-i", "initramfs", "-i", "initramfs",
"-k", kernFilename, "-k", kernFilename,
"-d", workDir, "-d", b.inDir,
"-o", outDir, "-o", b.outDir,
"initramfs-extra") "initramfs-extra")
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
@@ -100,6 +94,22 @@ func bootDeploy(workDir string, outDir string) error {
return nil 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 // Copy copies the file at srcFile path to a new file at dstFile path
func copy(srcFile, dstFile string) error { func copy(srcFile, dstFile string) error {
out, err := os.Create(dstFile) out, err := os.Create(dstFile)