Compare commits
3 Commits
2.3.1
...
jane400/ve
Author | SHA1 | Date | |
---|---|---|---|
|
20ba9e4131 | ||
|
e5f14d70a6 | ||
|
dd5cdeace5 |
@@ -54,6 +54,36 @@ a bare minimum, and to require only variables that don't hold lists of things.
|
||||
necessary tools to extract the configured archive format are in the initramfs
|
||||
archive.
|
||||
|
||||
# ARCHIVE COMPRESSION
|
||||
|
||||
Archive compression parameters are specified in the
|
||||
*deviceinfo_initfs_compression* and *deviceinfo_initfs_extra_compression*
|
||||
deviceinfo variables. Their values do not have to match, but special
|
||||
consideration should be taken since some formats may require additional kernel
|
||||
options or tools in the initramfs to support it.
|
||||
|
||||
Supported compression *formats* for mkinitfs are:
|
||||
|
||||
- gzip
|
||||
- lz4
|
||||
- lzma
|
||||
- none
|
||||
- zstd
|
||||
|
||||
Supported compression *levels* for mkinitfs:
|
||||
|
||||
- best
|
||||
- default
|
||||
- fast
|
||||
|
||||
The value of these variables follows this syntax: *<format>:<level>*. For
|
||||
example, *zstd* with the *fast* compression level would be:
|
||||
*deviceinfo_initfs_compression="zstd:fast"*
|
||||
|
||||
Defaults to *gzip* and *default* for both archives if format and/or level is
|
||||
unsupported or omitted.
|
||||
|
||||
|
||||
# DIRECTORIES
|
||||
|
||||
The following directories are used by mkinitfs to generate the initramfs and
|
||||
|
@@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"log"
|
||||
|
||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/osutil"
|
||||
)
|
||||
@@ -22,30 +24,54 @@ func GetFiles(list []string, required bool) (files []string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func getFile(file string, required bool) (files []string, err error) {
|
||||
// Expand glob expression
|
||||
expanded, err := filepath.Glob(file)
|
||||
// This function doesn't handle globs, use getFile() instead.
|
||||
func getFileNormalized(file string, required bool) (files []string, err error) {
|
||||
fileInfo, err := os.Stat(file)
|
||||
|
||||
// Trying some fallbacks...
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if len(expanded) > 0 && expanded[0] != file {
|
||||
for _, path := range expanded {
|
||||
if globFiles, err := getFile(path, required); err != nil {
|
||||
return files, err
|
||||
} else {
|
||||
files = append(files, globFiles...)
|
||||
}
|
||||
}
|
||||
return RemoveDuplicates(files), nil
|
||||
type triedResult struct {
|
||||
file string
|
||||
err error
|
||||
}
|
||||
|
||||
fileInfo, err := os.Stat(file)
|
||||
if err != nil {
|
||||
if required {
|
||||
return files, fmt.Errorf("getFile: failed to stat file %q: %w", file, err)
|
||||
triedFiles := make([]triedResult, 0, 1)
|
||||
|
||||
// Temporary fallback until alpine/pmOS usr-merge happened
|
||||
// If a path starts with /bin or /sbin, also try /usr equivalent before giving up
|
||||
if strings.HasPrefix(file, "/bin/") || strings.HasPrefix(file, "/sbin/") {
|
||||
fileUsr := filepath.Join("/usr", file)
|
||||
_, err := os.Stat(fileUsr);
|
||||
if err == nil {
|
||||
log.Printf("getFile: failed to find %q, but found it in %q. Please adjust the path.", file, fileUsr)
|
||||
return getFileNormalized(fileUsr, required)
|
||||
} else {
|
||||
triedFiles = append(triedFiles, triedResult{fileUsr, err})
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Check if there is a Zstd-compressed version of the file
|
||||
fileZstd := file + ".zst" // .zst is the extension used by linux-firmware
|
||||
_, err := os.Stat(fileZstd);
|
||||
if err == nil {
|
||||
return getFileNormalized(fileZstd, required)
|
||||
} else {
|
||||
triedFiles = append(triedFiles, triedResult{fileZstd, err})
|
||||
}
|
||||
}
|
||||
|
||||
// Failed to find anything
|
||||
if required {
|
||||
failStrings := make([]string, 0, 2)
|
||||
for _, result := range triedFiles {
|
||||
failStrings = append(failStrings, fmt.Sprintf("\n - also tried %q: %v", result.file, result.err))
|
||||
}
|
||||
return files, fmt.Errorf("getFile: failed to stat file %q: %v%q", file, err, strings.Join(failStrings, ""))
|
||||
} else {
|
||||
return files, nil
|
||||
}
|
||||
}
|
||||
|
||||
if fileInfo.IsDir() {
|
||||
// Recurse over directory contents
|
||||
@@ -83,6 +109,26 @@ func getFile(file string, required bool) (files []string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func getFile(file string, required bool) (files []string, err error) {
|
||||
// Expand glob expression
|
||||
expanded, err := filepath.Glob(file)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if len(expanded) > 0 && expanded[0] != file {
|
||||
for _, path := range expanded {
|
||||
if globFiles, err := getFile(path, required); err != nil {
|
||||
return files, err
|
||||
} else {
|
||||
files = append(files, globFiles...)
|
||||
}
|
||||
}
|
||||
return RemoveDuplicates(files), nil
|
||||
}
|
||||
|
||||
return getFileNormalized(file, required)
|
||||
}
|
||||
|
||||
func getDeps(file string, parents map[string]struct{}) (files []string, err error) {
|
||||
|
||||
if _, found := parents[file]; found {
|
||||
|
Reference in New Issue
Block a user