Commit Graph

206 Commits

Author SHA1 Message Date
Clayton Craft
dceef20121 cmd/mkinitfs: unroll generateArchive (MR 34)
There's some repetition that's added by unrolling this, but it will
allow passing the main initramfs archive's filelister to
archive.AddItemsExclude when generating the initramfs-extra.

I looked at several ways to implement this, this seems like least
terrible thing to do... The runner-up was to return a FileList from
archive.AddItems, and pass that around... Eww.
2023-04-06 22:21:27 -07:00
Clayton Craft
25017f3a3b archive: add AddItemsExclude method (MR 34)
This allows passing a filelister of things to exclude from the archive
2023-04-06 22:21:27 -07:00
Clayton Craft
67ce1a9c2e filelist/initramfs: cache list of files (MR 34)
Allows subsequent calls to List() to return quickly
2023-04-06 22:21:25 -07:00
Clayton Craft
8fac3004a6 archive: fix up documentation for AddItems 2023-03-19 23:14:18 -07:00
Clayton Craft
a15a3ad781 filelist/modules: don't print "skipping..." when dir not found
I think this was still causing some confusion, since it *might* look
like a failure when in reality it's not. I think it's important that
mkinitfs prints when it is adding something, and doesn't print when it
is *not* adding something, so that it should be clear if something
expected is missing and when something unexpected is included... without
having to sort out which is which every time the output is read.
2023-03-19 23:06:09 -07:00
Clayton Craft
1e8580a0a1 archive: New() can't fail, so don't return an error type
It could fail if the system can't allocate memory or something
undeterministic like that, but in that case it's best to just let the
runtime panic.
2023-03-19 22:05:55 -07:00
Clayton Craft
e6ee43826d doc/mkinitfs: add section on boot-deploy 2023-03-19 16:36:11 -07:00
Clayton Craft
7bdd68800d doc/mkinitfs.1: add design goals 2023-03-19 16:35:51 -07:00
Clayton Craft
80098d29c6 misc:TimeFunc: reduce printed time precision
Now:
        10:57:41.737665 initramfs-extra completed in: 0.33s
        ...
        10:57:42.008587 boot-deploy completed in: 0.27s
        10:57:42.012973 mkinitfs completed in: 0.90s

Times is just truncated, not rounding, since it's simpler (no dependency
on the math module), and I'm not sure if anyone cares for what this
function prints. If there is a desire to return to higher precision
later, it could be enabled by a new flag.

fixes https://gitlab.com/postmarketOS/postmarketos-mkinitfs/-/issues/25
2.1.1
2023-03-13 11:03:48 -07:00
Clayton Craft
67f1839ddc filelist/modules: fix order of struct items to reduce memory
Another one found by fieldalignment:
        modules.go:18:14: struct with 32 pointer bytes could be 24

Probably not going to matter much... but let's just get rid of the
warning.
2023-03-12 20:39:01 -07:00
Clayton Craft
baf76ed614 archive: fix order of struct items to reduce memory usage
Found by fieldalignment:
        archive.go:46:14: struct with 88 pointer bytes could be 56
        archive.go:66:18: struct with 24 pointer bytes could be 16

The first one probably doesn't matter that much, there's only like 2 of
those objects that are instantiated at runtime. However, there are many
ArchiveItems (hundreds or more depending on the archives compositions)
2023-03-12 20:37:10 -07:00
Clayton Craft
27e271b904 filelist/modules: print a message when including modules from deviceinfo
fixes https://gitlab.com/postmarketOS/postmarketos-mkinitfs/-/issues/24
2023-03-12 20:36:29 -07:00
Clayton Craft
1ac85b12fe filelist/modules: print search dir before searching dir
This will allow printing status for deviceinfo modules earlier in the
function, in a way that makes more sense.
2023-03-12 20:36:24 -07:00
Clayton Craft
f7f42bc2d4 filelist/modules: handle errors from filepath.Walk 2023-03-12 20:18:51 -07:00
Clayton Craft
c62a1f9ddb filelist/modules: remove outdated reference in error message 2023-03-12 20:05:55 -07:00
Clayton Craft
c9de619f98 filelist/hookscripts: use the correct path for scripts 2.1 2023-03-10 23:23:53 -08:00
Clayton Craft
a519769979 filelist/*: use "searching" instead of "including" in top-level msg
When this is printed, it's about to search the given path for stuff to
slurp up, but it hasn't actually included anything yet. Using
"Including" here was kinda confusing, so this changes it to use
"Searching for." Hopefully that's better!
2023-03-10 22:33:32 -08:00
Clayton Craft
128a48dd24 cmd/mkinitfs: re-add support for setting initramfs-extra compression 2023-03-10 22:22:51 -08:00
Clayton Craft
499136e83a cmd/mkinitfs: move printing compression info to generateArchive 2023-03-10 22:22:51 -08:00
Clayton Craft
78f8fa32fb deviceinfo: add initfs_extra_compression
For configuring the archive compression parameters for the
initramfs-extra archive.
2023-03-10 22:22:50 -08:00
Clayton Craft
d03257981f bootdeploy: add context to kernel copy fd close error (MR 33) 2023-03-06 22:20:11 -08:00
Clayton Craft
307fb1889f bootdeploy: use original kernel filename when calling boot-deploy (MR 33)
fixes #21
2023-03-06 22:20:07 -08:00
Clayton Craft
fa3d3268d7 bootdeploy: catch any errors when closing kernel file copy fd 2023-03-05 23:56:58 -08:00
Clayton Craft
8b67848d5c filelist/modules: print search path for modules
By doing so, it adds more useful context to this:

         - Including kernel modules
         -- Unable to find dir, skipping...
         - Including kernel modules
         -- Unable to find dir, skipping...
2023-03-05 23:54:15 -08:00
Clayton Craft
31ab72edbc cmd/mkinitfs: configure log to print milliseconds
Useful for timing each step of generating the initramfs without having
to add a bunch of calls to the "time func" function
2023-03-01 22:57:53 -08:00
Clayton Craft
bd239c0365 ci: build vendor tarball and create new release when new tag is pushed
This adds two new CI jobs that run when a new tag is pushed to this
repo: one to tar up the vendored dependencies and another one to push
the tarball as an asset in a new gitlab "release" for the tag.

fixes: #5
2.0
2023-03-01 12:56:21 -08:00
Clayton Craft
a4c3b9ff96 Makefile: add target to build vendored dependencies 2023-03-01 12:56:21 -08:00
Clayton Craft
8f505ffdc8 go.mod: set min version to 1.20
Fixes some build issues when using vendored dependencies.
2023-03-01 12:56:21 -08:00
Clayton Craft
fb00e9e94b cmd/mkinitfs: don't compress initramfs-extra (MR 25)
There is little(?) reason to compress the -extra archive, but some
there are some good reasons why it should be left uncompressed:

        1) decompression increases boot time
        2) selecting exotic formats (e.g. lzma or zstd) can actually
           increase the initramfs size since you now have to include
           support for those archive formats

In the future this could be made configurable...
2023-02-26 12:18:27 -08:00
Clayton Craft
7c2377d0c8 archive: add "none" compression format (MR 25) 2023-02-26 12:18:27 -08:00
Clayton Craft
f24d0139c9 archive.writeCompressed: bubble up error when closing archive file (MR 25)
This also prevents a double Close() if the compressor is ever set to 'fd'
2023-02-26 12:17:58 -08:00
Clayton Craft
5e2f975bd3 cmd/mkinitfs: print info about compression format and level used (MR 25) 2023-02-24 09:21:24 -08:00
Clayton Craft
786e09d855 archive: support using lzma (MR 25)
fixes: https://gitlab.com/postmarketOS/postmarketos-mkinitfs/-/issues/2
2023-02-24 09:21:24 -08:00
Clayton Craft
ba1e1a77db archive: Use compression level when generating archive (MR 25) 2023-02-24 09:21:24 -08:00
Clayton Craft
fd11f4a627 archive.New: accept compression level (MR 25)
I went with a simpler implementation that uses Go compression packages
to do the work. The downside of this is that the compression Level is a
bit weird to set, since most libraries discourage setting the numeric
compression level directly.

This is configured by setting `deviceinfo_initfs_compression`, the value
it expects is a string in the form: `FORMAT[:LEVEL]`, where `[:LEVEL]`
is optional. Actually setting the variable at all is optional... if
nothing is specified, or it can't parse the format/level from the string
value, it defaults to using gzip with the "default" level for the
package (which tries to mirror gzip's default, or something).

The level can be one of `default`, `fast`, `best`.

To configure gzip with the fastest compression (so, bigger size): deviceinfo_initfs_compression="gzip:fast"`

To configure zstd with the most compression: `deviceinfo_initfs_compression="zstd:best"`

To configure zstd with default compression: `deviceinfo_initfs_compression="zstd"` (or `deviceinfo_initfs_compression="zstd:default"`)

In this case, `gzip:default` is assumed: deviceinfo_initfs_compression="bananas:mmmm"`
2023-02-24 09:21:23 -08:00
Clayton Craft
322d6bb754 archive: add ExtractFormatLevel function (MR 25)
Extracts the format and level from a string in the form "format:level"
2023-02-24 09:21:23 -08:00
Clayton Craft
1f4d8737e8 archive: add CompressLevel type and consts (MR 25)
There's really not a great way to map individual levels to each
compression library, so this just adds a new type that will invoke the
three relevant levels for each library used. This could be improved in
the future.
2023-02-24 09:21:23 -08:00
Clayton Craft
52fc741ba8 archive: support using zstd (MR 25)
This external module was chosen because it's a native Go implementation
of zstd, and not a wrapper around some external utility or some CGO
thing.
2023-02-24 09:21:23 -08:00
Clayton Craft
31b7eb34ee archive: allow selecting different formats when writing compressed file (MR 25) 2023-02-24 09:21:23 -08:00
Clayton Craft
4e97990804 archive: accept compression format parameter during instantiation (MR 25) 2023-02-24 09:21:23 -08:00
Clayton Craft
c01b48ad25 archive: add CompressFormat type with initial constants (MR 25) 2023-02-24 09:21:22 -08:00
Clayton Craft
6aec4d564c archive: remove pgzip, use gzip from go std lib (MR 25)
This replaces the parallel gzip with the boring gzip from Go's standard
lib. The main motivations for doing this are:

1) Reduce runtime memory requirements

2) shed some external dependencies

There's obviously a trade-off with compression speed/time (as seen
below), but I feel like it's a worthwhile trade-off.

Note that there's likely very little impact to boot performance wrt
extracting these archives, the compression levels are similar.

Measured on a Shift 6mq, which is a very fast phone...

** compress/gzip:

User time (seconds): 1.81
System time (seconds): 0.38
Percent of CPU this job got: 104%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:02.09
Maximum resident set size (kbytes): 62024

-rw-r--r-- 1 clayton clayton 6.1M Sep 20 17:20 initramfs
-rw-r--r-- 1 clayton clayton 2.5M Sep 20 17:20 initramfs-extra

** pgzip:

User time (seconds): 1.19
System time (seconds): 0.48
Percent of CPU this job got: 159%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:01.05
Maximum resident set size (kbytes): 109952

-rw-r--r-- 1 clayton clayton 6.8M Sep 20 17:20 initramfs
-rw-r--r-- 1 clayton clayton 2.8M Sep 20 17:20 initramfs-extra

inspired by: https://gitlab.com/postmarketOS/pmaports/-/issues/1704
2023-02-24 09:21:22 -08:00
Clayton Craft
6eb01e91e6 cmd/mkinitfs: actually read modules from /etc/mkinitfs/modules (MR 32)
Missed earlier. Note that the list of modules from deviceinfo isn't
passed again...
2023-02-24 09:06:40 -08:00
Clayton Craft
790cf47060 cmd/mkinitfs: allow installing modules in the initramfs-extra archive (MR 32)
fixes: https://gitlab.com/postmarketOS/postmarketos-mkinitfs/-/issues/20
2023-02-24 09:06:29 -08:00
Clayton Craft
4074eada55 modules: remove TODOs
The builtin one was moved to a new issue:
https://gitlab.com/postmarketOS/postmarketos-mkinitfs/-/issues/18

The "more extensions" one was not moved to a new issue, it should be
obvious if we do need to support more extensions.
2023-02-21 12:41:18 -08:00
Clayton Craft
a7c4fe83ce archive: remove TODO about adding debug mode
moved to an issue: https://gitlab.com/postmarketOS/postmarketos-mkinitfs/-/issues/17
2023-02-21 12:41:18 -08:00
Clayton Craft
06f86aadc9 misc.Exists: bubble up any unexpected errors
Fixes https://gitlab.com/postmarketOS/postmarketos-mkinitfs/-/issues/6
2023-02-21 12:41:18 -08:00
Clayton Craft
d87a33a751 bootdeploy: remove dependency on misc.Exists
Checking for the app is unnecessary, since the cmd.Run later will fail
if it doesn't exist. This allows dropping the dependency on misc.Exists.

There's also no reason to print that the command failed, just return the
error.
2023-02-21 12:41:18 -08:00
Clayton Craft
d1e150242d cmd/mkinitfs: fix boot-deploy error message
naming the app is more useful than some internal function/object
2023-02-21 12:41:18 -08:00
Clayton Craft
5968622f60 cmd/mkinitfs: simplify the "deviceinfo not found" message
The old message is too specific to pmOS.
2023-02-21 12:41:18 -08:00