Skip to content

Commit

Permalink
coreboot 24.02.01: add upstream pending patches for heap allocation f…
Browse files Browse the repository at this point in the history
…ailure 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 <[email protected]>
  • Loading branch information
tlaurion committed Jul 17, 2024
1 parent 61e8ef4 commit bd69fb5
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 14 deletions.
2 changes: 1 addition & 1 deletion config/coreboot-qemu-tpm1.config
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,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
Expand Down Expand Up @@ -451,7 +452,6 @@ CONFIG_ACPI_COMMON_MADT_IOAPIC=y
CONFIG_HAVE_ACPI_TABLES=y
CONFIG_BOOT_DEVICE_NOT_SPI_FLASH=y
CONFIG_BOOT_DEVICE_MEMORY_MAPPED=y
CONFIG_HEAP_SIZE=0x100000

#
# Console
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-qemu-tpm2.config
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,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
Expand Down Expand Up @@ -444,7 +445,6 @@ CONFIG_ACPI_COMMON_MADT_IOAPIC=y
CONFIG_HAVE_ACPI_TABLES=y
CONFIG_BOOT_DEVICE_NOT_SPI_FLASH=y
CONFIG_BOOT_DEVICE_MEMORY_MAPPED=y
CONFIG_HEAP_SIZE=0x100000

#
# Console
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-t420-maximized.config
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -583,7 +584,6 @@ CONFIG_BOOT_DEVICE_SPI_FLASH=y
CONFIG_BOOT_DEVICE_MEMORY_MAPPED=y
CONFIG_BOOT_DEVICE_SUPPORTS_WRITES=y
CONFIG_RTC=y
CONFIG_HEAP_SIZE=0x100000

#
# Console
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-t430-maximized.config
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -583,7 +584,6 @@ CONFIG_BOOT_DEVICE_SPI_FLASH=y
CONFIG_BOOT_DEVICE_MEMORY_MAPPED=y
CONFIG_BOOT_DEVICE_SUPPORTS_WRITES=y
CONFIG_RTC=y
CONFIG_HEAP_SIZE=0x100000

#
# Console
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-t440p.config
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,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
Expand Down Expand Up @@ -578,7 +579,6 @@ CONFIG_BOOT_DEVICE_SPI_FLASH=y
CONFIG_BOOT_DEVICE_MEMORY_MAPPED=y
CONFIG_BOOT_DEVICE_SUPPORTS_WRITES=y
CONFIG_RTC=y
CONFIG_HEAP_SIZE=0x100000

#
# Console
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-t530-maximized.config
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,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
Expand Down Expand Up @@ -585,7 +586,6 @@ CONFIG_BOOT_DEVICE_SPI_FLASH=y
CONFIG_BOOT_DEVICE_MEMORY_MAPPED=y
CONFIG_BOOT_DEVICE_SUPPORTS_WRITES=y
CONFIG_RTC=y
CONFIG_HEAP_SIZE=0x100000

#
# Console
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-w530-maximized.config
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,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
Expand Down Expand Up @@ -586,7 +587,6 @@ CONFIG_BOOT_DEVICE_SPI_FLASH=y
CONFIG_BOOT_DEVICE_MEMORY_MAPPED=y
CONFIG_BOOT_DEVICE_SUPPORTS_WRITES=y
CONFIG_RTC=y
CONFIG_HEAP_SIZE=0x100000

#
# Console
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-w541.config
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,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
Expand Down Expand Up @@ -577,7 +578,6 @@ CONFIG_BOOT_DEVICE_SPI_FLASH=y
CONFIG_BOOT_DEVICE_MEMORY_MAPPED=y
CONFIG_BOOT_DEVICE_SUPPORTS_WRITES=y
CONFIG_RTC=y
CONFIG_HEAP_SIZE=0x100000

#
# Console
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-x220-maximized.config
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -582,7 +583,6 @@ CONFIG_BOOT_DEVICE_SPI_FLASH=y
CONFIG_BOOT_DEVICE_MEMORY_MAPPED=y
CONFIG_BOOT_DEVICE_SUPPORTS_WRITES=y
CONFIG_RTC=y
CONFIG_HEAP_SIZE=0x100000

#
# Console
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-x230-legacy-flash.config
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,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
Expand Down Expand Up @@ -566,7 +567,6 @@ CONFIG_BOOT_DEVICE_SPI_FLASH=y
CONFIG_BOOT_DEVICE_MEMORY_MAPPED=y
CONFIG_BOOT_DEVICE_SUPPORTS_WRITES=y
CONFIG_RTC=y
CONFIG_HEAP_SIZE=0x100000

#
# Console
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-x230-legacy.config
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,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
Expand Down Expand Up @@ -567,7 +568,6 @@ CONFIG_BOOT_DEVICE_SPI_FLASH=y
CONFIG_BOOT_DEVICE_MEMORY_MAPPED=y
CONFIG_BOOT_DEVICE_SUPPORTS_WRITES=y
CONFIG_RTC=y
CONFIG_HEAP_SIZE=0x100000

#
# Console
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-x230-maximized-fhd_edp.config
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,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
Expand Down Expand Up @@ -582,7 +583,6 @@ CONFIG_BOOT_DEVICE_SPI_FLASH=y
CONFIG_BOOT_DEVICE_MEMORY_MAPPED=y
CONFIG_BOOT_DEVICE_SUPPORTS_WRITES=y
CONFIG_RTC=y
CONFIG_HEAP_SIZE=0x100000

#
# Console
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-x230-maximized.config
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -580,7 +581,6 @@ CONFIG_BOOT_DEVICE_SPI_FLASH=y
CONFIG_BOOT_DEVICE_MEMORY_MAPPED=y
CONFIG_BOOT_DEVICE_SUPPORTS_WRITES=y
CONFIG_RTC=y
CONFIG_HEAP_SIZE=0x100000

#
# Console
Expand Down
2 changes: 1 addition & 1 deletion config/coreboot-z220-cmt.config
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,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
Expand Down Expand Up @@ -560,7 +561,6 @@ CONFIG_BOOT_DEVICE_SPI_FLASH=y
CONFIG_BOOT_DEVICE_MEMORY_MAPPED=y
CONFIG_BOOT_DEVICE_SUPPORTS_WRITES=y
CONFIG_RTC=y
CONFIG_HEAP_SIZE=0x100000

#
# Console
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
From 8b6fc3a877d8169091d034ea6ac6d15593cc69a0 Mon Sep 17 00:00:00 2001
From: Jonathon Hall <[email protected]>
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 <[email protected]>
---
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

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
From 00d695849a5fb503d87203e3515f761fa8dac850 Mon Sep 17 00:00:00 2001
From: Jonathon Hall <[email protected]>
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 <[email protected]>
---
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

0 comments on commit bd69fb5

Please sign in to comment.