Skip to content

Commit

Permalink
Add ability to have sub-path globs and include overlays (#63)
Browse files Browse the repository at this point in the history
Add ability to have sub-path globs and include overlays/*.dtbo from kernel package
  • Loading branch information
Doridian authored Oct 20, 2023
1 parent 84c24f7 commit c6f9ca1
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions internal/packer/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,33 @@ var (
"boot.scr", // u-boot script file
"vmlinuz",
"*.dtb",
"overlays/*.dtbo",
}
)

func (p *Pack) copyGlobsToBoot(fw *fat.Writer, srcDir string, globs []string) error {
for _, pattern := range globs {
matches, err := filepath.Glob(filepath.Join(srcDir, pattern))
if err != nil {
return err
}
for _, m := range matches {
src, err := os.Open(m)
if err != nil {
return err
}
relPath, err := filepath.Rel(srcDir, m)
if err != nil {
return err
}
if err := copyFile(fw, "/"+relPath, src); err != nil {
return err
}
}
}
return nil
}

func (p *Pack) writeBoot(f io.Writer, mbrfilename string) error {
fmt.Printf("\n")
fmt.Printf("Creating boot file system\n")
Expand All @@ -171,15 +195,13 @@ func (p *Pack) writeBoot(f io.Writer, mbrfilename string) error {
done(fragment)
}()

globs := make([]string, 0, len(firmwareGlobs)+len(kernelGlobs))
var firmwareDir string
if fw := p.Cfg.FirmwarePackageOrDefault(); fw != "" {
firmwareDir, err := packer.PackageDir(fw)
var err error
firmwareDir, err = packer.PackageDir(fw)
if err != nil {
return err
}
for _, glob := range firmwareGlobs {
globs = append(globs, filepath.Join(firmwareDir, glob))
}
}
var eepromDir string
if eeprom := p.Cfg.EEPROMPackageOrDefault(); eeprom != "" {
Expand All @@ -195,29 +217,23 @@ func (p *Pack) writeBoot(f io.Writer, mbrfilename string) error {
}

fmt.Printf("\nKernel directory: %s\n", kernelDir)
for _, glob := range kernelGlobs {
globs = append(globs, filepath.Join(kernelDir, glob))
}

bufw := bufio.NewWriter(f)
fw, err := fat.NewWriter(bufw)
if err != nil {
return err
}
for _, pattern := range globs {
matches, err := filepath.Glob(pattern)

err = p.copyGlobsToBoot(fw, kernelDir, kernelGlobs)
if err != nil {
return err
}

if firmwareDir != "" {
err = p.copyGlobsToBoot(fw, firmwareDir, firmwareGlobs)
if err != nil {
return err
}
for _, m := range matches {
src, err := os.Open(m)
if err != nil {
return err
}
if err := copyFile(fw, "/"+filepath.Base(m), src); err != nil {
return err
}
}
}

// EEPROM update procedure. See also:
Expand Down

0 comments on commit c6f9ca1

Please sign in to comment.