6 Commits
1.1 ... 1.3

Author SHA1 Message Date
Johannes Marbach
206e75c597 get(Hook)Files: Use getFile, handle globs and dirs (MR 14)
This commit includes three changes:

1. Use getFile in getHookFiles to add the contents of file hooks
2. Within getFile, first attempted a glob expansion on the specified
   file expression. This allows specifying e.g.
   /lib/udev/rules.d/*.rules.
3. Within getFile, next if the path points to a directory, add all
   files including those from subdirectories. This allows specifying
   e.g. /usr/share/X11/xkb.

Relates to: postmarketOS/pmaports#1309
2021-12-27 20:11:47 -08:00
Clayton Craft
7a61e5126c Add /usr/bin/unudhcpd to initfs (MR 13)
This will replace the busybox dhcp server.

With this change, mkinitfs depends on the 'unudhcpd' packge in Alpine to
provide the binary at /usr/bin/unudhcpd.
2021-11-21 12:56:56 -08:00
Clayton Craft
0925cbd8ac bootDeploy: ignore suffixes added by boot-deploy when copying kernel (MR 11)
The glob might result in a vmlinuz-* filename that causes mkinitfs to
copy a modified kernel file to the boot-deploy working directory. This
excludes files that boot-deploy has touched from being copied/used by
boot-deploy
2021-10-03 18:07:36 -07:00
Minecrell
866f17b86f getModuleDeps: replace Split() loop with ReplaceAllString() (MR 12)
This should do the same as far as I can tell :)
2021-09-20 15:14:19 -07:00
Minecrell
15e99c3658 getModulesDep: disallow regex submatches (MR 12)
At the moment modules in modules.dep are matched even on a submatch
e.g. looking up "msm" ends up matching "snd-soc-msm8916-digital.ko"
instead of "msm.ko". To fix this, disallow submatches using ^ and $.
2021-09-20 15:14:05 -07:00
bo41
6400871749 CI: rename ci folder to consistent naming (MR 10)
part of https://gitlab.com/postmarketOS/postmarketos/-/issues/26
2021-09-16 21:54:53 -07:00
4 changed files with 54 additions and 18 deletions

View File

@@ -31,7 +31,7 @@ gofmt linting:
- apk -q update --repository http://dl-4.alpinelinux.org/alpine/edge/testing - apk -q update --repository http://dl-4.alpinelinux.org/alpine/edge/testing
- apk -q add --repository http://dl-4.alpinelinux.org/alpine/edge/testing go staticcheck - apk -q add --repository http://dl-4.alpinelinux.org/alpine/edge/testing go staticcheck
script: script:
- .gitlab-ci/check_linting.sh - .ci/check_linting.sh
build: build:
stage: build stage: build

66
main.go
View File

@@ -86,18 +86,29 @@ func bootDeploy(workDir string, outDir string) error {
if len(kernels) == 0 { if len(kernels) == 0 {
return errors.New("Unable to find any kernels at " + filepath.Join(outDir, "vmlinuz*")) return errors.New("Unable to find any kernels at " + filepath.Join(outDir, "vmlinuz*"))
} }
kernFile, err := os.Open(kernels[0])
// Pick a kernel that does not have suffixes added by boot-deploy
var kernFile string
for _, f := range kernels {
if strings.HasSuffix(f, "-dtb") || strings.HasSuffix(f, "-mtk") {
continue
}
kernFile = f
break
}
kernFd, err := os.Open(kernFile)
if err != nil { if err != nil {
return err return err
} }
defer kernFile.Close() defer kernFd.Close()
kernFileCopy, err := os.Create(filepath.Join(workDir, "vmlinuz")) kernFileCopy, err := os.Create(filepath.Join(workDir, "vmlinuz"))
if err != nil { if err != nil {
return err return err
} }
if _, err = io.Copy(kernFileCopy, kernFile); err != nil { if _, err = io.Copy(kernFileCopy, kernFd); err != nil {
return err return err
} }
kernFileCopy.Close() kernFileCopy.Close()
@@ -145,10 +156,9 @@ func getHookFiles(filesdir string) misc.StringSet {
defer f.Close() defer f.Close()
s := bufio.NewScanner(f) s := bufio.NewScanner(f)
for s.Scan() { for s.Scan() {
if !exists(s.Text()) { if err := getFile(files, s.Text(), true); err != nil {
log.Fatalf("Unable to find file %q required by %q", s.Text(), path) log.Fatalf("Unable to find file %q required by %q", s.Text(), path)
} }
files[s.Text()] = false
} }
if err := s.Err(); err != nil { if err := s.Err(); err != nil {
log.Fatal(err) log.Fatal(err)
@@ -232,13 +242,42 @@ func getFiles(files misc.StringSet, newFiles misc.StringSet, required bool) erro
} }
func getFile(files misc.StringSet, file string, required bool) error { func getFile(files misc.StringSet, file string, required bool) error {
if !exists(file) { // Expand glob expression
expanded, _ := filepath.Glob(file)
if len(expanded) > 0 && expanded[0] != file {
for _, path := range expanded {
if err := getFile(files, path, required); err != nil {
return err
}
}
return nil
}
fileInfo, err := os.Stat(file)
if err != nil {
if required { if required {
return errors.New("getFile: File does not exist :" + file) return errors.New("getFile: File does not exist :" + file)
} }
return nil return nil
} }
if fileInfo.IsDir() {
// Recurse over directory contents
err := filepath.Walk(file, func(path string, f os.FileInfo, err error) error {
if err != nil {
return err
}
if f.IsDir() {
return nil
}
return getFile(files, path, required)
})
if err != nil {
return err
}
return nil
}
files[file] = false files[file] = false
// get dependencies for binaries // get dependencies for binaries
@@ -247,8 +286,7 @@ func getFile(files misc.StringSet, file string, required bool) error {
return nil return nil
} }
err := getBinaryDeps(files, file) if err := getBinaryDeps(files, file); err != nil {
if err != nil {
return err return err
} }
@@ -403,6 +441,7 @@ func getInitfsFiles(files misc.StringSet, devinfo deviceinfo.DeviceInfo) error {
"/usr/sbin/telnetd": false, "/usr/sbin/telnetd": false,
"/sbin/kpartx": false, "/sbin/kpartx": false,
"/etc/deviceinfo": false, "/etc/deviceinfo": false,
"/usr/bin/unudhcpd": false,
} }
// Hook files & scripts // Hook files & scripts
@@ -657,15 +696,8 @@ func getModuleDeps(modName string, modulesDep io.Reader) ([]string, error) {
// split the module name on - and/or _, build a regex for matching // split the module name on - and/or _, build a regex for matching
splitRe := regexp.MustCompile("[-_]+") splitRe := regexp.MustCompile("[-_]+")
var modNameReStr string modNameReStr := splitRe.ReplaceAllString(modName, "[-_]+")
for _, s := range splitRe.Split(modName, -1) { re := regexp.MustCompile("^" + modNameReStr + "$")
if modNameReStr != "" {
modNameReStr += "[-_]+" + s
} else {
modNameReStr = s
}
}
re := regexp.MustCompile(modNameReStr)
s := bufio.NewScanner(modulesDep) s := bufio.NewScanner(modulesDep)
for s.Scan() { for s.Scan() {

View File

@@ -40,6 +40,7 @@ func stringSlicesEqual(a []string, b []string) bool {
} }
var testModuleDep string = ` var testModuleDep string = `
kernel/sound/soc/codecs/snd-soc-msm8916-digital.ko:
kernel/net/sched/act_ipt.ko.xz: kernel/net/netfilter/x_tables.ko.xz kernel/net/sched/act_ipt.ko.xz: kernel/net/netfilter/x_tables.ko.xz
kernel/drivers/watchdog/watchdog.ko.xz: kernel/drivers/watchdog/watchdog.ko.xz:
kernel/drivers/usb/serial/ir-usb.ko.xz: kernel/drivers/usb/serial/usbserial.ko.xz kernel/drivers/usb/serial/ir-usb.ko.xz: kernel/drivers/usb/serial/usbserial.ko.xz
@@ -53,6 +54,7 @@ kernel/net/bluetooth/hidp/hidp.ko.xz: kernel/net/bluetooth/bluetooth.ko.xz kerne
kernel/fs/nls/nls_iso8859-1.ko.xz: kernel/fs/nls/nls_iso8859-1.ko.xz:
kernel/net/vmw_vsock/vmw_vsock_virtio_transport.ko.xz: kernel/net/vmw_vsock/vmw_vsock_virtio_transport_common.ko.xz kernel/drivers/virtio/virtio.ko.xz kernel/drivers/virtio/virtio_ring.ko.xz kernel/net/vmw_vsock/vsock.ko.xz kernel/net/vmw_vsock/vmw_vsock_virtio_transport.ko.xz: kernel/net/vmw_vsock/vmw_vsock_virtio_transport_common.ko.xz kernel/drivers/virtio/virtio.ko.xz kernel/drivers/virtio/virtio_ring.ko.xz kernel/net/vmw_vsock/vsock.ko.xz
kernel/drivers/gpu/drm/panfrost/panfrost.ko.xz: kernel/drivers/gpu/drm/scheduler/gpu-sched.ko.xz kernel/drivers/gpu/drm/panfrost/panfrost.ko.xz: kernel/drivers/gpu/drm/scheduler/gpu-sched.ko.xz
kernel/drivers/gpu/drm/msm/msm.ko: kernel/drivers/gpu/drm/drm_kms_helper.ko
` `
func TestGetModuleDeps(t *testing.T) { func TestGetModuleDeps(t *testing.T) {
@@ -65,6 +67,8 @@ func TestGetModuleDeps(t *testing.T) {
{"dw-wdt", []string{"kernel/drivers/watchdog/dw_wdt.ko.xz", {"dw-wdt", []string{"kernel/drivers/watchdog/dw_wdt.ko.xz",
"kernel/drivers/watchdog/watchdog.ko.xz"}}, "kernel/drivers/watchdog/watchdog.ko.xz"}},
{"gl518sm", []string{"kernel/drivers/hwmon/gl518sm.ko.xz"}}, {"gl518sm", []string{"kernel/drivers/hwmon/gl518sm.ko.xz"}},
{"msm", []string{"kernel/drivers/gpu/drm/msm/msm.ko",
"kernel/drivers/gpu/drm/drm_kms_helper.ko"}},
} }
for _, table := range tables { for _, table := range tables {
out, err := getModuleDeps(table.in, strings.NewReader(testModuleDep)) out, err := getModuleDeps(table.in, strings.NewReader(testModuleDep))