From e47d202c701ede02ea5de405589534b11d5486f0 Mon Sep 17 00:00:00 2001 From: Dale Whinham Date: Sun, 5 Mar 2023 18:44:09 +0000 Subject: [PATCH] Compress kernels with gzip --- CHANGELOG.md | 1 + Config.mk | 3 +++ Makefile | 2 ++ patches/circle-45-gzip-kernel.patch | 42 +++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 patches/circle-45-gzip-kernel.patch diff --git a/CHANGELOG.md b/CHANGELOG.md index e1c792d..12ab60b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Replaced rotary encoder routines with a much more robust algorithm borrowed from [FlashFloppy](https://github.com/keirf/flashfloppy). +- Kernels are now gzip-compressed, which saves some SD card space and may slightly reduce loading times. ### Fixed diff --git a/Config.mk b/Config.mk index 57c0049..143f76a 100644 --- a/Config.mk +++ b/Config.mk @@ -14,6 +14,9 @@ USERBAUD?=115200 # Enable section garbage collection GC_SECTIONS?=1 +# Compress the kernel +GZIP_KERNEL?=1 + # Toolchain setup ifeq ($(BOARD), pi2) RASPBERRYPI=2 diff --git a/Makefile b/Makefile index 6fe5656..ed73928 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,7 @@ $(CIRCLE_STDLIB_CONFIG) $(CIRCLE_CONFIG)&: # Apply patches @${APPLY_PATCH} $(CIRCLEHOME) patches/circle-45-minimal-usb-drivers.patch @${APPLY_PATCH} $(CIRCLEHOME) patches/circle-45-cp210x-remove-partnum-check.patch + @${APPLY_PATCH} $(CIRCLEHOME) patches/circle-45-gzip-kernel.patch ifeq ($(strip $(GC_SECTIONS)),1) # Enable function/data sections for circle-stdlib @@ -148,6 +149,7 @@ clean: # mrproper: clean # Reverse patches + @${REVERSE_PATCH} $(CIRCLEHOME) patches/circle-45-gzip-kernel.patch @${REVERSE_PATCH} $(CIRCLEHOME) patches/circle-45-cp210x-remove-partnum-check.patch @${REVERSE_PATCH} $(CIRCLEHOME) patches/circle-45-minimal-usb-drivers.patch @${REVERSE_PATCH} $(FLUIDSYNTHHOME) patches/fluidsynth-2.3.1-circle.patch diff --git a/patches/circle-45-gzip-kernel.patch b/patches/circle-45-gzip-kernel.patch new file mode 100644 index 0000000..2a10a87 --- /dev/null +++ b/patches/circle-45-gzip-kernel.patch @@ -0,0 +1,42 @@ +From 596544ca81def86971281594720f22524e7b563d Mon Sep 17 00:00:00 2001 +From: Dale Whinham +Date: Sun, 5 Mar 2023 18:22:55 +0000 +Subject: [PATCH] Rules.mk: Add option to gzip-compress the kernel + +The Raspberry Pi bootloader is capable of booting kernels compressed +with gzip. This can help improve startup times with larger kernels +containing static data. + +Allow the user to define GZIP_KERNEL = 1 so that the final kernel image +is replaced with a gzip-compressed file. +--- + Rules.mk | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/Rules.mk b/Rules.mk +index 9f23e7f0..9880488f 100644 +--- a/Rules.mk ++++ b/Rules.mk +@@ -50,6 +50,9 @@ FLOAT_ABI ?= hard + # set this to 1 to enable garbage collection on sections, may cause side effects + GC_SECTIONS ?= 0 + ++# set this to 1 to gzip-compress the kernel ++GZIP_KERNEL ?= 0 ++ + ifneq ($(strip $(CLANG)),1) + CC = $(PREFIX)gcc + CPP = $(PREFIX)g++ +@@ -215,6 +218,12 @@ endif + @$(OBJCOPY) $(TARGET).elf -O binary $(TARGET).img + @echo -n " WC $(TARGET).img => " + @wc -c < $(TARGET).img ++ifeq ($(strip $(GZIP_KERNEL)),1) ++ @gzip -9 -f -n $(TARGET).img ++ @mv $(TARGET).img.gz $(TARGET).img ++ @echo -n " GZIP $(TARGET).img => " ++ @wc -c < $(TARGET).img ++endif + + clean: + @echo " CLEAN " `pwd`