LineageOS boot image is 8MB and I can flash it but my pmOS boot image is 12MB, of which 8MB is the kernel.
We need to find some way to make the kernel smaller. I had to disable CONFIG_KERNEL_XZ otherwise the kernel would not boot. With CONFIG_KERNEL_LZMA it won't boot either.
How much we can achieve without the gzip wrapper (code)
CONFIG_CC_OPTIMIZE_FOR_SIZE=y
Add a gzip layer around the already compressed vmlinuz (and repack boot.img) (*)
Only compress initrd with XZ
Load modules instead
How can we know that is the size limit beforehand?
Can we change this limit? Is it safe?
Is this limit the same for all the devices?
(*) MartijnBraam said on IRC:
you can try compressing the xz kernel image with gzip so the bootloader unpacks only one layerYour bootloader might be patched to always gunzipLittlekernel should detect the gzip header and unpack before booting
pmbootstrap uses a hack to make gzip always use the fastest compression method, instead of the best compressing one (trading speed for file size). That hack gets installed to /usr/local/bin/gzip and it impacts both the size of the initramfs, and the kernel (when the kernel gets compressed with gzip). These are side-effects, the original idea of the hack is to reduce the size of the apk packages, and therefore the build time.
What you could do now:
Remove /usr/local/bin/gzip in all your chroots, and build the kernel image and initramfs again, it should be smaller. When this is all, that's needed to fix this issue for you, I think we should provide this as an option (or even better, upstream a compression parameter to apk, so we don't need the hack at all)
Choose another compression algorithm in the kernel config (example)
Let me quote @drebrez, who made a very relevant comment in #127 (which is about including new programs in the initramfs to make automatic resizing of the system partition possible).
Another good solution would be to save all the additional tools (cryptsetup, parted, resize2fs, ...) that we need, inside the boot partition (or a dedicated one) of the pmos system image.
In this way we will reduce the initramfs size and it might help solving the #126 (closed).
/ # du -h -c /sbin/kpartx /lib/libdevmapper.so.1.02 /lib/ld-musl-armhf.so.1 /bin/busybox40.0K /sbin/kpartx288.0K /lib/libdevmapper.so.1.02536.0K /lib/ld-musl-armhf.so.1920.0K /bin/busybox1.7M total
Remarks:
that size is uncompressed
we could make it even smaller by compiling only what we need from busybox to find/mount the boot partition and extract the big initramfs image. The busybox-extras binary (which contains telnetd among very few others) is 88kb in size for example (!) (we could have our own busybox-initfs package or something like that)
we could make it smaller by compiling statically against musl. that way only the parts of musl, that are actually used, are kept.
Enabling CONFIG_KERNEL_LZMA now the boot.img is 8MB and I can flash it \o/.
However I'm still having the same problem of not being able to boot with XZ compression (I forgot that it also happened with LZMA). But at least it is flashable :)
If you don't mind I'd like to keep the issue opened so that I don't forget about investigating and documenting some of the findings
The size will be reduce, i have same issue in ubuntu touch, i got big kernel size and i can't flash it, but after this change, boot.img work well and ubuntu touch also
So finally I found the issue with XZ compression in my kernel
It turns out that the kernel makefile is broken because it uses a very weak method to detect if you are using the non-gnu version fo the stat command and it fails if you are using busybox's stat, which is the case in Alpine by default. The message in the log is cryptic and hard to spot because it doesn't fail hardly and the zImage probably remains corrupt somehow:
LD vmlinux.o MODPOST vmlinux.o GEN .version CHK include/generated/compile.h LD .tmp_vmlinux1 KSYM .tmp_kallsyms1.S AS .tmp_kallsyms1.o LD .tmp_vmlinux2 KSYM .tmp_kallsyms2.S AS .tmp_kallsyms2.o LD vmlinux SYSMAP System.map SYSMAP .tmp_System.map OBJCOPY arch/arm/boot/Image Kernel: arch/arm/boot/Image is ready AS arch/arm/boot/compressed/head.ostat: can't read file system information for '%z': No such file or directoryexpr: non-numeric argumentsh: invalid number ''stat: can't read file system information for '%z': No such file or directoryexpr: non-numeric argumentsh: invalid number ''stat: can't read file system information for '%z': No such file or directoryexpr: non-numeric argumentsh: invalid number ''stat: can't read file system information for '%z': No such file or directoryexpr: non-numeric argumentsh: invalid number '' XZKERN arch/arm/boot/compressed/piggy.xzkern CC arch/arm/boot/compressed/misc.o CC arch/arm/boot/compressed/decompress.o CC arch/arm/boot/compressed/string.o SHIPPED arch/arm/boot/compressed/lib1funcs.S SHIPPED arch/arm/boot/compressed/ashldi3.S AS arch/arm/boot/compressed/lib1funcs.o AS arch/arm/boot/compressed/ashldi3.o AS arch/arm/boot/compressed/piggy.xzkern.o LD arch/arm/boot/compressed/vmlinux OBJCOPY arch/arm/boot/zImage Kernel: arch/arm/boot/zImage is ready CAT arch/arm/boot/zImage-dtb Kernel: arch/arm/boot/zImage-dtb is ready
I solved it by adding coreutils to makedepends= in the kernel and now I am also able to flash the kernel.
As a last note, I suspect that my device admits both appended dtb to zImage and to the boot image.
It might be enough to depend on the xz packages though, I guess coreutils pulls that in (altough I couldn't see it directly), because xz is only provided by xz (and busybox, but that isn't listed as it installs the links dynamically).