From 119cebc44f51b0d69069bf37e9817156b96df09c Mon Sep 17 00:00:00 2001 From: Thierry Laurion Date: Tue, 16 Jul 2024 09:44:38 -0400 Subject: [PATCH] coreboot 24.02.01: add upstream pending patches for heap allocation failure on bootsplash and defaulting to 4mb of heap when bootsplash Add upstreeam patches to downstream: git fetch https://review.coreboot.org/coreboot refs/changes/75/83475/1 && git format-patch -1 --stdout FETCH_HEAD > 0001-prevent_bootsplash_heap_allocation_failure_to_booting.patch git fetch https://review.coreboot.org/coreboot refs/changes/76/83476/2 && git format-patch -1 --stdout FETCH_HEAD > 0002-increase_heap_from1mb_to4mb_when_bootpslash_enabled.patch Rebuilding coreboot version with patches applied: docker run -e DISPLAY=$DISPLAY --network host --rm -ti -v $(pwd):$(pwd) -w $(pwd) tlaurion/heads-dev-env:v0.2.0 -- make BOARD=qemu-coreboot-whiptail-tpm1 real.remove_canary_files-extract_patch_rebuild_what_changed Remove file added by patch when patching fails: sudo rm build/x86/libgpg-error-1.46/src/syscfg/lock-obj-pub.powerpc64le-unknown-linux-musl.h Applying patches touching coreboot version 24.02.01 defiend in board config to all boards: grep -R 24.02.01 boards/ | awk -F "/" {'print $2'} | while read board; do sudo make BOARD=$board coreboot.save_in_oldconfig_format_in_place; done Adding added/modified files to git tracked files for commit: git status | grep -e modified -e added | awk -F ":" {'print $2'}| xargs git add Signed-off-by: Thierry Laurion --- config/coreboot-qemu-tpm1.config | 1 + config/coreboot-qemu-tpm2.config | 1 + config/coreboot-t420-maximized.config | 1 + config/coreboot-t430-maximized.config | 1 + config/coreboot-t440p.config | 1 + config/coreboot-t530-maximized.config | 1 + config/coreboot-w530-maximized.config | 1 + config/coreboot-w541.config | 1 + config/coreboot-x220-maximized.config | 1 + config/coreboot-x230-legacy-flash.config | 1 + config/coreboot-x230-legacy.config | 1 + config/coreboot-x230-maximized-fhd_edp.config | 1 + config/coreboot-x230-maximized.config | 1 + config/coreboot-z220-cmt.config | 1 + ...h_heap_allocation_failure_to_booting.patch | 80 +++++++++++++++++++ ...rom1mb_to4mb_when_bootpslash_enabled.patch | 44 ++++++++++ 16 files changed, 138 insertions(+) create mode 100644 patches/coreboot-24.02.01/0001-prevent_bootsplash_heap_allocation_failure_to_booting.patch create mode 100644 patches/coreboot-24.02.01/0002-increase_heap_from1mb_to4mb_when_bootpslash_enabled.patch diff --git a/config/coreboot-qemu-tpm1.config b/config/coreboot-qemu-tpm1.config index 214ff7f2..5493f1be 100644 --- a/config/coreboot-qemu-tpm1.config +++ b/config/coreboot-qemu-tpm1.config @@ -326,6 +326,7 @@ CONFIG_NO_EARLY_GFX_INIT=y CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y CONFIG_LINEAR_FRAMEBUFFER=y CONFIG_BOOTSPLASH=y +CONFIG_HEAP_SIZE=0x400000 # end of Display CONFIG_PCI=y diff --git a/config/coreboot-qemu-tpm2.config b/config/coreboot-qemu-tpm2.config index 5ffd0d9b..8f56f70b 100644 --- a/config/coreboot-qemu-tpm2.config +++ b/config/coreboot-qemu-tpm2.config @@ -323,6 +323,7 @@ CONFIG_NO_EARLY_GFX_INIT=y CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y CONFIG_LINEAR_FRAMEBUFFER=y CONFIG_BOOTSPLASH=y +CONFIG_HEAP_SIZE=0x400000 # end of Display CONFIG_PCI=y diff --git a/config/coreboot-t420-maximized.config b/config/coreboot-t420-maximized.config index 63f061ef..eea62bcc 100644 --- a/config/coreboot-t420-maximized.config +++ b/config/coreboot-t420-maximized.config @@ -423,6 +423,7 @@ CONFIG_NO_EARLY_GFX_INIT=y CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y CONFIG_LINEAR_FRAMEBUFFER=y CONFIG_BOOTSPLASH=y +CONFIG_HEAP_SIZE=0x400000 # end of Display CONFIG_PCI=y diff --git a/config/coreboot-t430-maximized.config b/config/coreboot-t430-maximized.config index 10807621..265d1197 100644 --- a/config/coreboot-t430-maximized.config +++ b/config/coreboot-t430-maximized.config @@ -423,6 +423,7 @@ CONFIG_NO_EARLY_GFX_INIT=y CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y CONFIG_LINEAR_FRAMEBUFFER=y CONFIG_BOOTSPLASH=y +CONFIG_HEAP_SIZE=0x400000 # end of Display CONFIG_PCI=y diff --git a/config/coreboot-t440p.config b/config/coreboot-t440p.config index 702701e7..13fef27f 100644 --- a/config/coreboot-t440p.config +++ b/config/coreboot-t440p.config @@ -420,6 +420,7 @@ CONFIG_NO_EARLY_GFX_INIT=y CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y CONFIG_LINEAR_FRAMEBUFFER=y CONFIG_BOOTSPLASH=y +CONFIG_HEAP_SIZE=0x400000 # end of Display CONFIG_PCI=y diff --git a/config/coreboot-t530-maximized.config b/config/coreboot-t530-maximized.config index 095b847e..9fa62387 100644 --- a/config/coreboot-t530-maximized.config +++ b/config/coreboot-t530-maximized.config @@ -426,6 +426,7 @@ CONFIG_NO_EARLY_GFX_INIT=y CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y CONFIG_LINEAR_FRAMEBUFFER=y CONFIG_BOOTSPLASH=y +CONFIG_HEAP_SIZE=0x400000 # end of Display CONFIG_PCI=y diff --git a/config/coreboot-w530-maximized.config b/config/coreboot-w530-maximized.config index 1780e2e9..a1804e04 100644 --- a/config/coreboot-w530-maximized.config +++ b/config/coreboot-w530-maximized.config @@ -426,6 +426,7 @@ CONFIG_NO_EARLY_GFX_INIT=y CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y CONFIG_LINEAR_FRAMEBUFFER=y CONFIG_BOOTSPLASH=y +CONFIG_HEAP_SIZE=0x400000 # end of Display CONFIG_PCI=y diff --git a/config/coreboot-w541.config b/config/coreboot-w541.config index d40ccd68..230d8106 100644 --- a/config/coreboot-w541.config +++ b/config/coreboot-w541.config @@ -420,6 +420,7 @@ CONFIG_NO_EARLY_GFX_INIT=y CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y CONFIG_LINEAR_FRAMEBUFFER=y CONFIG_BOOTSPLASH=y +CONFIG_HEAP_SIZE=0x400000 # end of Display CONFIG_PCI=y diff --git a/config/coreboot-x220-maximized.config b/config/coreboot-x220-maximized.config index 4434611d..00e5216a 100644 --- a/config/coreboot-x220-maximized.config +++ b/config/coreboot-x220-maximized.config @@ -423,6 +423,7 @@ CONFIG_NO_EARLY_GFX_INIT=y CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y CONFIG_LINEAR_FRAMEBUFFER=y CONFIG_BOOTSPLASH=y +CONFIG_HEAP_SIZE=0x400000 # end of Display CONFIG_PCI=y diff --git a/config/coreboot-x230-legacy-flash.config b/config/coreboot-x230-legacy-flash.config index 89afa4a7..8eec8671 100644 --- a/config/coreboot-x230-legacy-flash.config +++ b/config/coreboot-x230-legacy-flash.config @@ -412,6 +412,7 @@ CONFIG_NO_EARLY_GFX_INIT=y CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y CONFIG_LINEAR_FRAMEBUFFER=y CONFIG_BOOTSPLASH=y +CONFIG_HEAP_SIZE=0x400000 # end of Display CONFIG_PCI=y diff --git a/config/coreboot-x230-legacy.config b/config/coreboot-x230-legacy.config index d0e9ab0b..82c815eb 100644 --- a/config/coreboot-x230-legacy.config +++ b/config/coreboot-x230-legacy.config @@ -412,6 +412,7 @@ CONFIG_NO_EARLY_GFX_INIT=y CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y CONFIG_LINEAR_FRAMEBUFFER=y CONFIG_BOOTSPLASH=y +CONFIG_HEAP_SIZE=0x400000 # end of Display CONFIG_PCI=y diff --git a/config/coreboot-x230-maximized-fhd_edp.config b/config/coreboot-x230-maximized-fhd_edp.config index d17f7962..708f7f22 100644 --- a/config/coreboot-x230-maximized-fhd_edp.config +++ b/config/coreboot-x230-maximized-fhd_edp.config @@ -424,6 +424,7 @@ CONFIG_NO_EARLY_GFX_INIT=y CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y CONFIG_LINEAR_FRAMEBUFFER=y CONFIG_BOOTSPLASH=y +CONFIG_HEAP_SIZE=0x400000 # end of Display CONFIG_PCI=y diff --git a/config/coreboot-x230-maximized.config b/config/coreboot-x230-maximized.config index 16e396c0..d62a078d 100644 --- a/config/coreboot-x230-maximized.config +++ b/config/coreboot-x230-maximized.config @@ -423,6 +423,7 @@ CONFIG_NO_EARLY_GFX_INIT=y CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y CONFIG_LINEAR_FRAMEBUFFER=y CONFIG_BOOTSPLASH=y +CONFIG_HEAP_SIZE=0x400000 # end of Display CONFIG_PCI=y diff --git a/config/coreboot-z220-cmt.config b/config/coreboot-z220-cmt.config index a57660b0..3c98e58e 100644 --- a/config/coreboot-z220-cmt.config +++ b/config/coreboot-z220-cmt.config @@ -402,6 +402,7 @@ CONFIG_NO_EARLY_GFX_INIT=y CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y CONFIG_LINEAR_FRAMEBUFFER=y CONFIG_BOOTSPLASH=y +CONFIG_HEAP_SIZE=0x400000 # end of Display CONFIG_PCI=y diff --git a/patches/coreboot-24.02.01/0001-prevent_bootsplash_heap_allocation_failure_to_booting.patch b/patches/coreboot-24.02.01/0001-prevent_bootsplash_heap_allocation_failure_to_booting.patch new file mode 100644 index 00000000..3913ba10 --- /dev/null +++ b/patches/coreboot-24.02.01/0001-prevent_bootsplash_heap_allocation_failure_to_booting.patch @@ -0,0 +1,80 @@ +From 8b6fc3a877d8169091d034ea6ac6d15593cc69a0 Mon Sep 17 00:00:00 2001 +From: Jonathon Hall +Date: Mon, 15 Jul 2024 15:01:52 -0400 +Subject: [PATCH] src/lib/malloc.c: If allocation fails, leave the heap + unchanged + +If an allocation fails because it is too large for the rest of the heap, +don't consume the rest of the heap needlessly. + +This started occurring with the Heads bootsplash image in 24.02.01, +following the switch to the Wuffs JPEG decoder. The work area needed +was too large for the heap. The bootsplash failed to show, but worse, +the boot failed entirely because we were then out of heap space, even +though we did not actually use the large allocation that failed. + +With this change, that failure no longer prevents boot. + +The error message is improved slightly also: +* missing line break is added +* "Tried to round up" now shows the beginning of the allocation before + and after rounding instead of the unrounded beginning and rounded end + (misleading, looked like it was trying to align by 1 MB when it + was actually allocating 1 MB) + +Change-Id: Ie72814027d9daa517c0794f3ea7abec2b9a9d596 +Signed-off-by: Jonathon Hall +--- + src/lib/malloc.c | 25 ++++++++++++------------- + 1 file changed, 12 insertions(+), 13 deletions(-) + +diff --git a/src/lib/malloc.c b/src/lib/malloc.c +index 30298064d9..281792c3d5 100644 +--- a/src/lib/malloc.c ++++ b/src/lib/malloc.c +@@ -26,30 +26,29 @@ void *memalign(size_t boundary, size_t size) + MALLOCDBG("%s Enter, boundary %zu, size %zu, free_mem_ptr %p\n", + __func__, boundary, size, free_mem_ptr); + +- free_mem_ptr = (void *)ALIGN_UP((unsigned long)free_mem_ptr, boundary); ++ p = (void *)ALIGN_UP((unsigned long)free_mem_ptr, boundary); + +- p = free_mem_ptr; +- free_mem_ptr += size; +- /* +- * Store last allocation pointer after ALIGN, as malloc() will +- * return it. This may cause n bytes of gap between allocations +- * where n < boundary. +- */ +- free_last_alloc_ptr = p; +- +- if (free_mem_ptr >= free_mem_end_ptr) { ++ if (p + size >= free_mem_end_ptr) { + printk(BIOS_ERR, "%s(boundary=%zu, size=%zu): failed: ", + __func__, boundary, size); + printk(BIOS_ERR, "Tried to round up free_mem_ptr %p to %p\n", +- p, free_mem_ptr); ++ free_mem_ptr, p); + printk(BIOS_ERR, "but free_mem_end_ptr is %p\n", + free_mem_end_ptr); + printk(BIOS_ERR, "Error! %s: Out of memory " +- "(free_mem_ptr >= free_mem_end_ptr)", ++ "(free_mem_ptr >= free_mem_end_ptr)\n", + __func__); + return NULL; + } + ++ free_mem_ptr = p + size; ++ /* ++ * Store last allocation pointer after ALIGN, as malloc() will ++ * return it. This may cause n bytes of gap between allocations ++ * where n < boundary. ++ */ ++ free_last_alloc_ptr = p; ++ + MALLOCDBG("%s %p\n", __func__, p); + + return p; +-- +2.39.2 + diff --git a/patches/coreboot-24.02.01/0002-increase_heap_from1mb_to4mb_when_bootpslash_enabled.patch b/patches/coreboot-24.02.01/0002-increase_heap_from1mb_to4mb_when_bootpslash_enabled.patch new file mode 100644 index 00000000..a31118c1 --- /dev/null +++ b/patches/coreboot-24.02.01/0002-increase_heap_from1mb_to4mb_when_bootpslash_enabled.patch @@ -0,0 +1,44 @@ +From 00d695849a5fb503d87203e3515f761fa8dac850 Mon Sep 17 00:00:00 2001 +From: Jonathon Hall +Date: Mon, 15 Jul 2024 16:37:40 -0400 +Subject: [PATCH] bootsplash: Increase heap from 1 MB to 4 MB when bootsplash + is enabled + +Since commit 1d029b40c9de ("lib/jpeg: Replace decoder with Wuffs' +implementation"), a relatively large heap allocation is needed to +decode many JPEGs for use as work area. The prior decoder did not need +this, but also had many limitations in the JPEGs it could decode. + +A 1024x768 non-progressive JPEG used in Heads needs 1179648 bytes of +work area; about 1.2 MB. While the work area will also depend on the +subsampling of each channel, it's generally proportional to the image +size. + +Increasing the heap size to 4 MB when bootsplash is enabled should be +enough to decode bootsplashes up to 1920x1080 with some headroom. + +Change-Id: Ia4348d39effbc16c1b42ab01bcf1e4ec5d652fa9 +Signed-off-by: Jonathon Hall +--- + src/device/Kconfig | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/src/device/Kconfig b/src/device/Kconfig +index 243e23e52a..4dd03eba21 100644 +--- a/src/device/Kconfig ++++ b/src/device/Kconfig +@@ -501,6 +501,11 @@ config BOOTSPLASH + image in the 'General' section or add it manually to CBFS, using, + for example, cbfstool. + ++# The bootsplash JPEG decoder requires heap space approximately proportional to ++# the image size. This usually needs a larger heap. ++config HEAP_SIZE ++ default 0x400000 if BOOTSPLASH ++ + config LINEAR_FRAMEBUFFER_MAX_WIDTH + int "Maximum width in pixels" + depends on LINEAR_FRAMEBUFFER && MAINBOARD_USE_LIBGFXINIT +-- +2.39.2 +