Compare commits
8 Commits
2.5.0
...
caleb/mult
Author | SHA1 | Date | |
---|---|---|---|
|
2e37a7c645 | ||
|
4e771ab96f | ||
|
4d7dd79bcf | ||
|
d63e600614 | ||
|
741c0553d5 | ||
|
cd97df108a | ||
|
1fed057a82 | ||
|
5efdb9f170 |
5
Makefile
5
Makefile
@@ -13,6 +13,11 @@ GOFLAGS?=
|
|||||||
LDFLAGS+=-s -w -X main.Version=$(VERSION)
|
LDFLAGS+=-s -w -X main.Version=$(VERSION)
|
||||||
RM?=rm -f
|
RM?=rm -f
|
||||||
GOTEST=go test -count=1 -race
|
GOTEST=go test -count=1 -race
|
||||||
|
DISABLE_GOGC?=
|
||||||
|
|
||||||
|
ifeq ($(DISABLE_GOGC),1)
|
||||||
|
LDFLAGS+=-X main.DisableGC=true
|
||||||
|
endif
|
||||||
|
|
||||||
GOSRC!=find * -name '*.go'
|
GOSRC!=find * -name '*.go'
|
||||||
GOSRC+=go.mod go.sum
|
GOSRC+=go.mod go.sum
|
||||||
|
@@ -9,6 +9,8 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime/debug"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/archive"
|
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/archive"
|
||||||
@@ -26,12 +28,19 @@ import (
|
|||||||
|
|
||||||
// set at build time
|
// set at build time
|
||||||
var Version string
|
var Version string
|
||||||
|
var DisableGC string
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// To allow working around silly GC-related issues, like https://gitlab.com/qemu-project/qemu/-/issues/2560
|
||||||
|
if strings.ToLower(DisableGC) == "true" {
|
||||||
|
debug.SetGCPercent(-1)
|
||||||
|
}
|
||||||
|
|
||||||
retCode := 0
|
retCode := 0
|
||||||
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.")
|
||||||
@@ -40,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
|
||||||
@@ -60,11 +71,14 @@ func main() {
|
|||||||
|
|
||||||
defer misc.TimeFunc(time.Now(), "mkinitfs")
|
defer misc.TimeFunc(time.Now(), "mkinitfs")
|
||||||
|
|
||||||
kernVer, err := osutil.GetKernelVersion()
|
if kernVer == "guess" {
|
||||||
if err != nil {
|
_kernVer, err := osutil.GetKernelVersion()
|
||||||
log.Println(err)
|
if err != nil {
|
||||||
retCode = 1
|
log.Println(err)
|
||||||
return
|
retCode = 1
|
||||||
|
return
|
||||||
|
}
|
||||||
|
kernVer = _kernVer
|
||||||
}
|
}
|
||||||
|
|
||||||
// temporary working dir
|
// temporary working dir
|
||||||
@@ -103,16 +117,37 @@ 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{
|
||||||
|
hookfiles.New("/usr/share/mkinitfs/files-extra"),
|
||||||
|
hookfiles.New("/etc/mkinitfs/files-extra"),
|
||||||
|
hookscripts.New("/usr/share/mkinitfs/hooks-extra", "/hooks-extra"),
|
||||||
|
hookscripts.New("/etc/mkinitfs/hooks-extra", "/hooks-extra"),
|
||||||
|
modules.New("/usr/share/mkinitfs/modules-extra", kernVer),
|
||||||
|
modules.New("/etc/mkinitfs/modules-extra", kernVer),
|
||||||
|
})
|
||||||
|
|
||||||
if err := initramfsAr.AddItems(initfs); err != nil {
|
if err := initramfsAr.AddItems(initfs); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
log.Println("failed to generate: ", "initramfs")
|
log.Println("failed to generate: ", "initramfs")
|
||||||
retCode = 1
|
retCode = 1
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := initramfsAr.Write(filepath.Join(workDir, "initramfs"), os.FileMode(0644)); err != nil {
|
|
||||||
|
// Include initramfs-extra files in the initramfs if not making a separate
|
||||||
|
// archive
|
||||||
|
if !devinfo.CreateInitfsExtra {
|
||||||
|
if err := initramfsAr.AddItems(initfsExtra); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
log.Println("failed to generate: ", "initramfs")
|
||||||
|
retCode = 1
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
@@ -120,41 +155,35 @@ func main() {
|
|||||||
}
|
}
|
||||||
misc.TimeFunc(start, "initramfs")
|
misc.TimeFunc(start, "initramfs")
|
||||||
|
|
||||||
//
|
if devinfo.CreateInitfsExtra {
|
||||||
// initramfs-extra
|
//
|
||||||
//
|
// initramfs-extra
|
||||||
// deviceinfo.InitfsExtraCompression needs a little more post-processing
|
//
|
||||||
compressionFormat, compressionLevel = archive.ExtractFormatLevel(devinfo.InitfsExtraCompression)
|
// deviceinfo.InitfsExtraCompression needs a little more post-processing
|
||||||
log.Printf("== Generating %s ==\n", "initramfs-extra")
|
compressionFormat, compressionLevel = archive.ExtractFormatLevel(devinfo.InitfsExtraCompression)
|
||||||
log.Printf("- Using compression format %s with level %q\n", compressionFormat, compressionLevel)
|
log.Printf("== Generating %s ==\n", "initramfs-extra")
|
||||||
|
log.Printf("- Using compression format %s with level %q\n", compressionFormat, compressionLevel)
|
||||||
|
|
||||||
start = time.Now()
|
start = time.Now()
|
||||||
initramfsExtraAr := archive.New(compressionFormat, compressionLevel)
|
initramfsExtraAr := archive.New(compressionFormat, compressionLevel)
|
||||||
initfsExtra := initramfs.New([]filelist.FileLister{
|
if err := initramfsExtraAr.AddItemsExclude(initfsExtra, initfs); err != nil {
|
||||||
hookfiles.New("/usr/share/mkinitfs/files-extra"),
|
log.Println(err)
|
||||||
hookfiles.New("/etc/mkinitfs/files-extra"),
|
log.Println("failed to generate: ", "initramfs-extra")
|
||||||
hookscripts.New("/usr/share/mkinitfs/hooks-extra", "/hooks-extra"),
|
retCode = 1
|
||||||
hookscripts.New("/etc/mkinitfs/hooks-extra", "/hooks-extra"),
|
return
|
||||||
modules.New("/usr/share/mkinitfs/modules-extra"),
|
}
|
||||||
modules.New("/etc/mkinitfs/modules-extra"),
|
if err := initramfsExtraAr.Write(filepath.Join(workDir, "initramfs-extra"), os.FileMode(0644)); err != nil {
|
||||||
})
|
log.Println(err)
|
||||||
if err := initramfsExtraAr.AddItemsExclude(initfsExtra, initfs); err != nil {
|
log.Println("failed to generate: ", "initramfs-extra")
|
||||||
log.Println(err)
|
retCode = 1
|
||||||
log.Println("failed to generate: ", "initramfs-extra")
|
return
|
||||||
retCode = 1
|
}
|
||||||
return
|
misc.TimeFunc(start, "initramfs-extra")
|
||||||
}
|
}
|
||||||
if err := initramfsExtraAr.Write(filepath.Join(workDir, "initramfs-extra"), os.FileMode(0644)); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
log.Println("failed to generate: ", "initramfs-extra")
|
|
||||||
retCode = 1
|
|
||||||
return
|
|
||||||
}
|
|
||||||
misc.TimeFunc(start, "initramfs-extra")
|
|
||||||
|
|
||||||
// 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
|
||||||
@@ -163,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()
|
||||||
}
|
}
|
||||||
|
@@ -42,6 +42,7 @@ mkinitfs reads deviceinfo values from */usr/share/deviceinfo/deviceinfo* and
|
|||||||
*/etc/deviceinfo*, in that order. The following variables
|
*/etc/deviceinfo*, in that order. The following variables
|
||||||
are *required* by mkinitfs:
|
are *required* by mkinitfs:
|
||||||
|
|
||||||
|
- deviceinfo_create_initfs_extra
|
||||||
- deviceinfo_generate_systemd_boot
|
- deviceinfo_generate_systemd_boot
|
||||||
- deviceinfo_initfs_compression
|
- deviceinfo_initfs_compression
|
||||||
- deviceinfo_initfs_extra_compression
|
- deviceinfo_initfs_extra_compression
|
||||||
@@ -146,7 +147,7 @@ create/manage. mkinitfs reads configuration from */usr/share/mkinitfs* first, an
|
|||||||
## /usr/share/mkinitfs/modules, /etc/mkinitfs/modules
|
## /usr/share/mkinitfs/modules, /etc/mkinitfs/modules
|
||||||
## /usr/share/mkinitfs/modules-extra, /etc/mkinitfs/modules-extra
|
## /usr/share/mkinitfs/modules-extra, /etc/mkinitfs/modules-extra
|
||||||
|
|
||||||
Files with the *.modules* extention in these directories are lists of
|
Files with the *.modules* extension in these directories are lists of
|
||||||
kernel modules to include in the initramfs. Individual modules and
|
kernel modules to include in the initramfs. Individual modules and
|
||||||
directories can be listed in the files here. Globbing is also supported.
|
directories can be listed in the files here. Globbing is also supported.
|
||||||
|
|
||||||
|
@@ -421,6 +421,7 @@ func (archive *Archive) writeCpio() error {
|
|||||||
archive.addSymlink("/bin", "/bin")
|
archive.addSymlink("/bin", "/bin")
|
||||||
archive.addSymlink("/sbin", "/sbin")
|
archive.addSymlink("/sbin", "/sbin")
|
||||||
archive.addSymlink("/lib", "/lib")
|
archive.addSymlink("/lib", "/lib")
|
||||||
|
archive.addSymlink("/usr/sbin", "/usr/sbin")
|
||||||
}
|
}
|
||||||
// having a transient function for actually adding files to the archive
|
// having a transient function for actually adding files to the archive
|
||||||
// allows the deferred fd.close to run after every copy and prevent having
|
// allows the deferred fd.close to run after every copy and prevent having
|
||||||
|
@@ -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
|
||||||
@@ -78,12 +81,19 @@ 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
|
||||||
cmd := exec.Command("boot-deploy",
|
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,
|
||||||
"initramfs-extra")
|
}
|
||||||
|
|
||||||
|
if b.devinfo.CreateInitfsExtra {
|
||||||
|
args = append(args, "initramfs-extra")
|
||||||
|
}
|
||||||
|
println(fmt.Sprintf("Calling boot-deply with args: %v\n", args))
|
||||||
|
cmd := exec.Command("boot-deploy", args...)
|
||||||
|
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
@@ -94,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
|
||||||
|
@@ -44,7 +44,7 @@ func (h *HookDirs) List() (*filelist.FileList, error) {
|
|||||||
|
|
||||||
s := bufio.NewScanner(f)
|
s := bufio.NewScanner(f)
|
||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
dir := s.Text()
|
dir := strings.TrimSpace(s.Text())
|
||||||
if len(dir) == 0 || strings.HasPrefix(dir, "#") {
|
if len(dir) == 0 || strings.HasPrefix(dir, "#") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@@ -59,7 +59,7 @@ func slurpFiles(fd io.Reader) (*filelist.FileList, error) {
|
|||||||
|
|
||||||
s := bufio.NewScanner(fd)
|
s := bufio.NewScanner(fd)
|
||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
line := s.Text()
|
line := strings.TrimSpace(s.Text())
|
||||||
if len(line) == 0 || strings.HasPrefix(line, "#") {
|
if len(line) == 0 || strings.HasPrefix(line, "#") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@@ -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)
|
||||||
@@ -83,7 +79,7 @@ func slurpModules(fd io.Reader, modDir string) (*filelist.FileList, error) {
|
|||||||
files := filelist.NewFileList()
|
files := filelist.NewFileList()
|
||||||
s := bufio.NewScanner(fd)
|
s := bufio.NewScanner(fd)
|
||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
line := s.Text()
|
line := strings.TrimSpace(s.Text())
|
||||||
if len(line) == 0 || strings.HasPrefix(line, "#") {
|
if len(line) == 0 || strings.HasPrefix(line, "#") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -103,8 +99,8 @@ func slurpModules(fd io.Reader, modDir string) (*filelist.FileList, error) {
|
|||||||
}
|
}
|
||||||
} else if dir == "" {
|
} else if dir == "" {
|
||||||
// item is a module name
|
// item is a module name
|
||||||
if modFilelist, err := getModule(s.Text(), modDir); err != nil {
|
if modFilelist, err := getModule(line, modDir); err != nil {
|
||||||
return nil, fmt.Errorf("unable to get module file %q: %w", s.Text(), err)
|
return nil, fmt.Errorf("unable to get module file %q: %w", line, err)
|
||||||
} else {
|
} else {
|
||||||
for _, file := range modFilelist {
|
for _, file := range modFilelist {
|
||||||
files.Add(file, file)
|
files.Add(file, file)
|
||||||
@@ -188,7 +184,7 @@ func getModuleDeps(modName string, modulesDep io.Reader) ([]string, error) {
|
|||||||
|
|
||||||
s := bufio.NewScanner(modulesDep)
|
s := bufio.NewScanner(modulesDep)
|
||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
line := s.Text()
|
line := strings.TrimSpace(s.Text())
|
||||||
if len(line) == 0 || strings.HasPrefix(line, "#") {
|
if len(line) == 0 || strings.HasPrefix(line, "#") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,7 @@ func TestStripExts(t *testing.T) {
|
|||||||
{"another_file", "another_file"},
|
{"another_file", "another_file"},
|
||||||
{"a.b.c.d.e.f.g.h.i", "a"},
|
{"a.b.c.d.e.f.g.h.i", "a"},
|
||||||
{"virtio_blk.ko", "virtio_blk"},
|
{"virtio_blk.ko", "virtio_blk"},
|
||||||
|
{"virtio_blk.ko ", "virtio_blk"},
|
||||||
}
|
}
|
||||||
for _, table := range tables {
|
for _, table := range tables {
|
||||||
out := stripExts(table.in)
|
out := stripExts(table.in)
|
||||||
|
@@ -40,11 +40,6 @@ func MergeUsr(file string) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert /usr/sbin --> /usr/bin
|
|
||||||
if part, found := strings.CutPrefix(file, "/usr/sbin"); found {
|
|
||||||
file = filepath.Join("/usr/bin/", part)
|
|
||||||
}
|
|
||||||
|
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,11 +18,11 @@ func TestMergeUsr(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
in: "/sbin/foo",
|
in: "/sbin/foo",
|
||||||
expected: "/usr/bin/foo",
|
expected: "/usr/sbin/foo",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
in: "/usr/sbin/foo",
|
in: "/usr/sbin/foo",
|
||||||
expected: "/usr/bin/foo",
|
expected: "/usr/sbin/foo",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
in: "/usr/bin/foo",
|
in: "/usr/bin/foo",
|
||||||
|
@@ -21,6 +21,7 @@ type DeviceInfo struct {
|
|||||||
UbootBoardname string
|
UbootBoardname string
|
||||||
GenerateSystemdBoot string
|
GenerateSystemdBoot string
|
||||||
FormatVersion string
|
FormatVersion string
|
||||||
|
CreateInitfsExtra bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads the relevant entries from "file" into DeviceInfo struct
|
// Reads the relevant entries from "file" into DeviceInfo struct
|
||||||
@@ -112,6 +113,7 @@ func (d DeviceInfo) String() string {
|
|||||||
%s: %v
|
%s: %v
|
||||||
%s: %v
|
%s: %v
|
||||||
%s: %v
|
%s: %v
|
||||||
|
%s: %v
|
||||||
}`,
|
}`,
|
||||||
"deviceinfo_format_version", d.FormatVersion,
|
"deviceinfo_format_version", d.FormatVersion,
|
||||||
"deviceinfo_", d.FormatVersion,
|
"deviceinfo_", d.FormatVersion,
|
||||||
@@ -120,5 +122,6 @@ func (d DeviceInfo) String() string {
|
|||||||
"deviceinfo_ubootBoardname", d.UbootBoardname,
|
"deviceinfo_ubootBoardname", d.UbootBoardname,
|
||||||
"deviceinfo_generateSystemdBoot", d.GenerateSystemdBoot,
|
"deviceinfo_generateSystemdBoot", d.GenerateSystemdBoot,
|
||||||
"deviceinfo_formatVersion", d.FormatVersion,
|
"deviceinfo_formatVersion", d.FormatVersion,
|
||||||
|
"deviceinfo_createInitfsExtra", d.CreateInitfsExtra,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -42,6 +42,7 @@ func TestNameToField(t *testing.T) {
|
|||||||
{"modules_initfs", "ModulesInitfs"},
|
{"modules_initfs", "ModulesInitfs"},
|
||||||
{"deviceinfo_initfs_compression___", "InitfsCompression"},
|
{"deviceinfo_initfs_compression___", "InitfsCompression"},
|
||||||
{"deviceinfo_initfs_extra_compression", "InitfsExtraCompression"},
|
{"deviceinfo_initfs_extra_compression", "InitfsExtraCompression"},
|
||||||
|
{"deviceinfo_create_initfs_extra", "CreateInitfsExtra"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, table := range tables {
|
for _, table := range tables {
|
||||||
@@ -65,6 +66,7 @@ func TestUnmarshal(t *testing.T) {
|
|||||||
UbootBoardname: "foobar-bazz",
|
UbootBoardname: "foobar-bazz",
|
||||||
InitfsCompression: "zstd:--foo=1 -T0 --bar=bazz",
|
InitfsCompression: "zstd:--foo=1 -T0 --bar=bazz",
|
||||||
InitfsExtraCompression: "",
|
InitfsExtraCompression: "",
|
||||||
|
CreateInitfsExtra: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -4,3 +4,4 @@ deviceinfo_uboot_boardname="foobar-bazz"
|
|||||||
deviceinfo_initfs_compression="zstd:--foo=1 -T0 --bar=bazz"
|
deviceinfo_initfs_compression="zstd:--foo=1 -T0 --bar=bazz"
|
||||||
# empty option
|
# empty option
|
||||||
deviceinfo_initfs_extra_compression=""
|
deviceinfo_initfs_extra_compression=""
|
||||||
|
deviceinfo_create_initfs_extra="true" # in-line comment that should be ignored
|
||||||
|
Reference in New Issue
Block a user