Compare commits
1 Commits
2.7.0
...
caleb/mult
Author | SHA1 | Date | |
---|---|---|---|
|
2e37a7c645 |
@@ -40,6 +40,7 @@ func main() {
|
|||||||
defer func() { os.Exit(retCode) }()
|
defer func() { os.Exit(retCode) }()
|
||||||
|
|
||||||
outDir := flag.String("d", "/boot", "Directory to output initfs(-extra) and other boot files")
|
outDir := flag.String("d", "/boot", "Directory to output initfs(-extra) and other boot files")
|
||||||
|
kernVerArg := flag.String("k", "guess", "Kernel version to run for")
|
||||||
|
|
||||||
var showVersion bool
|
var showVersion bool
|
||||||
flag.BoolVar(&showVersion, "version", false, "Print version and quit.")
|
flag.BoolVar(&showVersion, "version", false, "Print version and quit.")
|
||||||
@@ -48,6 +49,8 @@ func main() {
|
|||||||
flag.BoolVar(&disableBootDeploy, "no-bootdeploy", false, "Disable running 'boot-deploy' after generating archives.")
|
flag.BoolVar(&disableBootDeploy, "no-bootdeploy", false, "Disable running 'boot-deploy' after generating archives.")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
kernVer := *kernVerArg
|
||||||
|
|
||||||
if showVersion {
|
if showVersion {
|
||||||
fmt.Printf("%s - %s\n", filepath.Base(os.Args[0]), Version)
|
fmt.Printf("%s - %s\n", filepath.Base(os.Args[0]), Version)
|
||||||
return
|
return
|
||||||
@@ -68,12 +71,15 @@ func main() {
|
|||||||
|
|
||||||
defer misc.TimeFunc(time.Now(), "mkinitfs")
|
defer misc.TimeFunc(time.Now(), "mkinitfs")
|
||||||
|
|
||||||
kernVer, err := osutil.GetKernelVersion()
|
if kernVer == "guess" {
|
||||||
|
_kernVer, err := osutil.GetKernelVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
retCode = 1
|
retCode = 1
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
kernVer = _kernVer
|
||||||
|
}
|
||||||
|
|
||||||
// temporary working dir
|
// temporary working dir
|
||||||
workDir, err := os.MkdirTemp("", "mkinitfs")
|
workDir, err := os.MkdirTemp("", "mkinitfs")
|
||||||
@@ -111,16 +117,16 @@ func main() {
|
|||||||
hookfiles.New("/etc/mkinitfs/files"),
|
hookfiles.New("/etc/mkinitfs/files"),
|
||||||
hookscripts.New("/usr/share/mkinitfs/hooks", "/hooks"),
|
hookscripts.New("/usr/share/mkinitfs/hooks", "/hooks"),
|
||||||
hookscripts.New("/etc/mkinitfs/hooks", "/hooks"),
|
hookscripts.New("/etc/mkinitfs/hooks", "/hooks"),
|
||||||
modules.New("/usr/share/mkinitfs/modules"),
|
modules.New("/usr/share/mkinitfs/modules", kernVer),
|
||||||
modules.New("/etc/mkinitfs/modules"),
|
modules.New("/etc/mkinitfs/modules", kernVer),
|
||||||
})
|
})
|
||||||
initfsExtra := initramfs.New([]filelist.FileLister{
|
initfsExtra := initramfs.New([]filelist.FileLister{
|
||||||
hookfiles.New("/usr/share/mkinitfs/files-extra"),
|
hookfiles.New("/usr/share/mkinitfs/files-extra"),
|
||||||
hookfiles.New("/etc/mkinitfs/files-extra"),
|
hookfiles.New("/etc/mkinitfs/files-extra"),
|
||||||
hookscripts.New("/usr/share/mkinitfs/hooks-extra", "/hooks-extra"),
|
hookscripts.New("/usr/share/mkinitfs/hooks-extra", "/hooks-extra"),
|
||||||
hookscripts.New("/etc/mkinitfs/hooks-extra", "/hooks-extra"),
|
hookscripts.New("/etc/mkinitfs/hooks-extra", "/hooks-extra"),
|
||||||
modules.New("/usr/share/mkinitfs/modules-extra"),
|
modules.New("/usr/share/mkinitfs/modules-extra", kernVer),
|
||||||
modules.New("/etc/mkinitfs/modules-extra"),
|
modules.New("/etc/mkinitfs/modules-extra", kernVer),
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := initramfsAr.AddItems(initfs); err != nil {
|
if err := initramfsAr.AddItems(initfs); err != nil {
|
||||||
@@ -141,7 +147,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := initramfsAr.Write(filepath.Join(workDir, "initramfs"), os.FileMode(0644)); err != nil {
|
if err := initramfsAr.Write(filepath.Join(workDir, fmt.Sprintf("initramfs-%s", kernVer)), os.FileMode(0644)); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
log.Println("failed to generate: ", "initramfs")
|
log.Println("failed to generate: ", "initramfs")
|
||||||
retCode = 1
|
retCode = 1
|
||||||
@@ -177,7 +183,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); err != nil {
|
if err := bootDeploy(workDir, *outDir, devinfo, kernVer); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
log.Println("boot-deploy failed")
|
log.Println("boot-deploy failed")
|
||||||
retCode = 1
|
retCode = 1
|
||||||
@@ -186,10 +192,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func bootDeploy(workDir string, outDir string, devinfo deviceinfo.DeviceInfo) error {
|
func bootDeploy(workDir string, outDir string, devinfo deviceinfo.DeviceInfo, kernVer string) 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, devinfo)
|
bd := bootdeploy.New(workDir, outDir, devinfo, kernVer)
|
||||||
return bd.Run()
|
return bd.Run()
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,7 @@ type BootDeploy struct {
|
|||||||
inDir string
|
inDir string
|
||||||
outDir string
|
outDir string
|
||||||
devinfo deviceinfo.DeviceInfo
|
devinfo deviceinfo.DeviceInfo
|
||||||
|
kernVer string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new BootDeploy, which then runs:
|
// New returns a new BootDeploy, which then runs:
|
||||||
@@ -26,11 +27,12 @@ type BootDeploy struct {
|
|||||||
//
|
//
|
||||||
// devinfo is used to access some deviceinfo values, such as UbootBoardname
|
// devinfo is used to access some deviceinfo values, such as UbootBoardname
|
||||||
// and GenerateSystemdBoot
|
// and GenerateSystemdBoot
|
||||||
func New(inDir string, outDir string, devinfo deviceinfo.DeviceInfo) *BootDeploy {
|
func New(inDir string, outDir string, devinfo deviceinfo.DeviceInfo, kernVer string) *BootDeploy {
|
||||||
return &BootDeploy{
|
return &BootDeploy{
|
||||||
inDir: inDir,
|
inDir: inDir,
|
||||||
outDir: outDir,
|
outDir: outDir,
|
||||||
devinfo: devinfo,
|
devinfo: devinfo,
|
||||||
|
kernVer: kernVer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,10 +45,11 @@ func (b *BootDeploy) Run() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
kernels, err := getKernelPath(b.outDir, b.devinfo.GenerateSystemdBoot == "true")
|
kernels, err := getKernelPath(b.outDir, b.kernVer, b.devinfo.GenerateSystemdBoot == "true")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
println(fmt.Sprintf("kernels: %v\n", kernels))
|
||||||
|
|
||||||
// Pick a kernel that does not have suffixes added by boot-deploy
|
// Pick a kernel that does not have suffixes added by boot-deploy
|
||||||
var kernFile string
|
var kernFile string
|
||||||
@@ -79,8 +82,9 @@ func (b *BootDeploy) Run() error {
|
|||||||
|
|
||||||
// boot-deploy -i initramfs -k vmlinuz-postmarketos-rockchip -d /tmp/cpio -o /tmp/foo initramfs-extra
|
// boot-deploy -i initramfs -k vmlinuz-postmarketos-rockchip -d /tmp/cpio -o /tmp/foo initramfs-extra
|
||||||
args := []string{
|
args := []string{
|
||||||
"-i", "initramfs",
|
"-i", fmt.Sprintf("initramfs-%s", b.kernVer),
|
||||||
"-k", kernFilename,
|
"-k", kernFilename,
|
||||||
|
"-v", b.kernVer,
|
||||||
"-d", b.inDir,
|
"-d", b.inDir,
|
||||||
"-o", b.outDir,
|
"-o", b.outDir,
|
||||||
}
|
}
|
||||||
@@ -88,6 +92,7 @@ func (b *BootDeploy) Run() error {
|
|||||||
if b.devinfo.CreateInitfsExtra {
|
if b.devinfo.CreateInitfsExtra {
|
||||||
args = append(args, "initramfs-extra")
|
args = append(args, "initramfs-extra")
|
||||||
}
|
}
|
||||||
|
println(fmt.Sprintf("Calling boot-deply with args: %v\n", args))
|
||||||
cmd := exec.Command("boot-deploy", args...)
|
cmd := exec.Command("boot-deploy", args...)
|
||||||
|
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
@@ -99,20 +104,20 @@ func (b *BootDeploy) Run() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getKernelPath(outDir string, zboot bool) ([]string, error) {
|
func getKernelPath(outDir string, kernVer string, zboot bool) ([]string, error) {
|
||||||
var kernels []string
|
var kernels []string
|
||||||
if zboot {
|
if zboot {
|
||||||
kernels, _ = filepath.Glob(filepath.Join(outDir, "linux.efi"))
|
kernels, _ = filepath.Glob(filepath.Join(outDir, fmt.Sprintf("linux-%s.efi", kernVer)))
|
||||||
if len(kernels) > 0 {
|
if len(kernels) > 0 {
|
||||||
return kernels, nil
|
return kernels, nil
|
||||||
}
|
}
|
||||||
// else fallback to vmlinuz* below
|
// else fallback to vmlinuz* below
|
||||||
}
|
}
|
||||||
|
|
||||||
kernFile := "vmlinuz*"
|
kernFile := fmt.Sprintf("vmlinuz-%s", kernVer)
|
||||||
kernels, _ = filepath.Glob(filepath.Join(outDir, kernFile))
|
kernels, _ = filepath.Glob(filepath.Join(outDir, kernFile))
|
||||||
if len(kernels) == 0 {
|
if len(kernels) == 0 {
|
||||||
return nil, errors.New("Unable to find any kernels at " + filepath.Join(outDir, kernFile))
|
return nil, errors.New("Unable to find any kernels at " + filepath.Join(outDir, kernFile) + " or " + filepath.Join(outDir, fmt.Sprintf("linux-%s.efi", kernVer)))
|
||||||
}
|
}
|
||||||
|
|
||||||
return kernels, nil
|
return kernels, nil
|
||||||
|
@@ -12,26 +12,22 @@ import (
|
|||||||
|
|
||||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist"
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist"
|
||||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/misc"
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/misc"
|
||||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/osutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Modules struct {
|
type Modules struct {
|
||||||
modulesListPath string
|
modulesListPath string
|
||||||
|
kernVer string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new Modules that will read in lists of kernel modules in the given path.
|
// New returns a new Modules that will read in lists of kernel modules in the given path.
|
||||||
func New(modulesListPath string) *Modules {
|
func New(modulesListPath string, kernVer string) *Modules {
|
||||||
return &Modules{
|
return &Modules{
|
||||||
modulesListPath: modulesListPath,
|
modulesListPath: modulesListPath,
|
||||||
|
kernVer: kernVer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Modules) List() (*filelist.FileList, error) {
|
func (m *Modules) List() (*filelist.FileList, error) {
|
||||||
kernVer, err := osutil.GetKernelVersion()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
files := filelist.NewFileList()
|
files := filelist.NewFileList()
|
||||||
libDir := "/usr/lib/modules"
|
libDir := "/usr/lib/modules"
|
||||||
if exists, err := misc.Exists(libDir); !exists {
|
if exists, err := misc.Exists(libDir); !exists {
|
||||||
@@ -40,7 +36,7 @@ func (m *Modules) List() (*filelist.FileList, error) {
|
|||||||
return nil, fmt.Errorf("received unexpected error when getting status for %q: %w", libDir, err)
|
return nil, fmt.Errorf("received unexpected error when getting status for %q: %w", libDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
modDir := filepath.Join(libDir, kernVer)
|
modDir := filepath.Join(libDir, m.kernVer)
|
||||||
if exists, err := misc.Exists(modDir); !exists {
|
if exists, err := misc.Exists(modDir); !exists {
|
||||||
// dir /lib/modules/<kernel> if kernel built without module support, so just print a message
|
// dir /lib/modules/<kernel> if kernel built without module support, so just print a message
|
||||||
log.Printf("-- kernel module directory not found: %q, not including modules", modDir)
|
log.Printf("-- kernel module directory not found: %q, not including modules", modDir)
|
||||||
|
Reference in New Issue
Block a user