Skip to content

Commit

Permalink
[oem] add bootsplash for all nitropads
Browse files Browse the repository at this point in the history
  • Loading branch information
daringer committed Sep 26, 2023
1 parent 73caddb commit 92c2ba2
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 12 deletions.
2 changes: 2 additions & 0 deletions boards/t430-hotp-maximized/t430-hotp-maximized.config
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export CONFIG_LINUX_VERSION=5.10.5
CONFIG_COREBOOT_CONFIG=config/coreboot-t430-maximized.config
CONFIG_LINUX_CONFIG=config/linux-x230-maximized.config

CONFIG_NITROKEY_BLOBS=y

#Additional hardware support
CONFIG_LINUX_USB=y
CONFIG_LINUX_E1000E=y
Expand Down
2 changes: 2 additions & 0 deletions boards/x230-hotp-maximized/x230-hotp-maximized.config
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export CONFIG_LINUX_VERSION=5.10.5
CONFIG_COREBOOT_CONFIG=config/coreboot-x230-maximized.config
CONFIG_LINUX_CONFIG=config/linux-x230-maximized.config

CONFIG_NITROKEY_BLOBS=y

#Additional hardware support
CONFIG_LINUX_USB=y
CONFIG_LINUX_E1000E=y
Expand Down
10 changes: 8 additions & 2 deletions config/coreboot-nitropad-ns50.config
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ CONFIG_HAVE_ASAN_IN_RAMSTAGE=y
# CONFIG_NO_STAGE_CACHE is not set
CONFIG_TSEG_STAGE_CACHE=y
# CONFIG_UPDATE_IMAGE is not set
# CONFIG_BOOTSPLASH_IMAGE is not set
CONFIG_BOOTSPLASH_IMAGE=y
CONFIG_BOOTSPLASH_FILE="@BLOB_DIR@/../build/x86/nitrokey-blobs/common/bootsplash-1920-swapped.jpg"
CONFIG_BOOTSPLASH_CONVERT=y
CONFIG_BOOTSPLASH_CONVERT_QUALITY=90
CONFIG_BOOTSPLASH_CONVERT_RESIZE=y
CONFIG_BOOTSPLASH_CONVERT_RESOLUTION="1920x1080"
# CONFIG_BOOTSPLASH_CONVERT_COLORSWAP is not set
# CONFIG_FW_CONFIG is not set
# end of General setup

Expand Down Expand Up @@ -519,7 +525,7 @@ CONFIG_RUN_FSP_GOP=y
#
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
# CONFIG_BOOTSPLASH is not set
CONFIG_BOOTSPLASH=y
# end of Display

CONFIG_PCI=y
Expand Down
10 changes: 8 additions & 2 deletions config/coreboot-nitropad-nv41.config
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ CONFIG_HAVE_ASAN_IN_RAMSTAGE=y
# CONFIG_NO_STAGE_CACHE is not set
CONFIG_TSEG_STAGE_CACHE=y
# CONFIG_UPDATE_IMAGE is not set
# CONFIG_BOOTSPLASH_IMAGE is not set
CONFIG_BOOTSPLASH_IMAGE=y
CONFIG_BOOTSPLASH_FILE="@BLOB_DIR@/../build/x86/nitrokey-blobs/common/bootsplash-1920-swapped.jpg"
CONFIG_BOOTSPLASH_CONVERT=y
CONFIG_BOOTSPLASH_CONVERT_QUALITY=90
CONFIG_BOOTSPLASH_CONVERT_RESIZE=y
CONFIG_BOOTSPLASH_CONVERT_RESOLUTION="1920x1080"
# CONFIG_BOOTSPLASH_CONVERT_COLORSWAP is not set
# CONFIG_FW_CONFIG is not set
# end of General setup

Expand Down Expand Up @@ -519,7 +525,7 @@ CONFIG_RUN_FSP_GOP=y
#
CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y
CONFIG_LINEAR_FRAMEBUFFER=y
# CONFIG_BOOTSPLASH is not set
CONFIG_BOOTSPLASH=y
# end of Display

CONFIG_PCI=y
Expand Down
7 changes: 4 additions & 3 deletions config/coreboot-t430-maximized.config
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ CONFIG_HAVE_ASAN_IN_RAMSTAGE=y
CONFIG_TSEG_STAGE_CACHE=y
# CONFIG_UPDATE_IMAGE is not set
CONFIG_BOOTSPLASH_IMAGE=y
CONFIG_BOOTSPLASH_FILE="@BLOB_DIR@/bootsplash-1024x768.jpg"
CONFIG_BOOTSPLASH_FILE="@BLOB_DIR@/../build/x86/nitrokey-blobs/common/bootsplash-1024-swapped.jpg"
CONFIG_BOOTSPLASH_CONVERT=y
CONFIG_BOOTSPLASH_CONVERT_QUALITY=70
# CONFIG_BOOTSPLASH_CONVERT_RESIZE is not set
CONFIG_BOOTSPLASH_CONVERT_QUALITY=90
CONFIG_BOOTSPLASH_CONVERT_RESIZE=y
CONFIG_BOOTSPLASH_CONVERT_RESOLUTION="1024x768"
# CONFIG_BOOTSPLASH_CONVERT_COLORSWAP is not set
# CONFIG_FW_CONFIG is not set

Expand Down
7 changes: 4 additions & 3 deletions config/coreboot-x230-maximized.config
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ CONFIG_HAVE_ASAN_IN_RAMSTAGE=y
CONFIG_TSEG_STAGE_CACHE=y
# CONFIG_UPDATE_IMAGE is not set
CONFIG_BOOTSPLASH_IMAGE=y
CONFIG_BOOTSPLASH_FILE="@BLOB_DIR@/bootsplash-1024x768.jpg"
CONFIG_BOOTSPLASH_FILE="@BLOB_DIR@/../build/x86/nitrokey-blobs/common/bootsplash-1024-swapped.jpg"
CONFIG_BOOTSPLASH_CONVERT=y
CONFIG_BOOTSPLASH_CONVERT_QUALITY=70
# CONFIG_BOOTSPLASH_CONVERT_RESIZE is not set
CONFIG_BOOTSPLASH_CONVERT_QUALITY=90
CONFIG_BOOTSPLASH_CONVERT_RESIZE=y
CONFIG_BOOTSPLASH_CONVERT_RESOLUTION="1024x768"
# CONFIG_BOOTSPLASH_CONVERT_COLORSWAP is not set
# CONFIG_FW_CONFIG is not set

Expand Down
4 changes: 2 additions & 2 deletions modules/nitrokey-blobs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
modules-$(CONFIG_NITROKEY_BLOBS) += nitrokey-blobs

nitrokey-blobs_base_dir := nitrokey-blobs
nitrokey-blobs_version := c9e2a556508518d54cd57f8c7a440cb370f69de1
nitrokey-blobs_version := b629bad31046ff2f5f363656326646fe2081d033
nitrokey-blobs_tar := nitrokey-blobs-${nitrokey-blobs_version}.tar.gz
nitrokey-blobs_tar_opt := --strip 1
nitrokey-blobs_url := https://github.com/Nitrokey/firmware-blobs/archive/${nitrokey-blobs_version}.tar.gz
nitrokey-blobs_hash := 1458798fa774e43ab2e6cf5cff875f4b3628c5dc1926bf9ec65051964b1a4854
nitrokey-blobs_hash := 73daf2180e3ffd070e9dc80c84ccd2573a24f636dc273e3d9fe81aefc7c5d425

## there is nothing to be built
nitrokey-blobs_output := .built
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
From 4fafe82b67dfe6919fe7be93459083549aac9f25 Mon Sep 17 00:00:00 2001
From: Nico Huber <[email protected]>
Date: Fri, 14 Jul 2023 00:09:00 +0200
Subject: [PATCH] Center bootsplash on bigger framebuffers

In the JPEG decoder, use `bytes_per_line` instead of `width` for
address calculations, to allow for bigger framebuffers. When
calling jpeg_decode(), add an offset to the framebuffer address
so the picture gets centered.

Change-Id: I0174bdccfaad425e708a5fa50bcb28a1b98a23f7
Signed-off-by: Nico Huber <[email protected]>
---

diff --git a/src/include/bootsplash.h b/src/include/bootsplash.h
index 10da5aa..9d1bae3 100644
--- a/src/include/bootsplash.h
+++ b/src/include/bootsplash.h
@@ -12,7 +12,8 @@
* and >0 on jpeg errors.
*/
void set_bootsplash(unsigned char *framebuffer, unsigned int x_resolution,
- unsigned int y_resolution, unsigned int fb_resolution);
+ unsigned int y_resolution, unsigned int bytes_per_line,
+ unsigned int fb_resolution);


void bmp_load_logo(uint32_t *logo_ptr, uint32_t *logo_size);
diff --git a/src/lib/bootsplash.c b/src/lib/bootsplash.c
index 0eb94dc..3ab11ac 100644
--- a/src/lib/bootsplash.c
+++ b/src/lib/bootsplash.c
@@ -11,7 +11,8 @@


void set_bootsplash(unsigned char *framebuffer, unsigned int x_resolution,
- unsigned int y_resolution, unsigned int fb_resolution)
+ unsigned int y_resolution, unsigned int bytes_per_line,
+ unsigned int fb_resolution)
{
printk(BIOS_INFO, "Setting up bootsplash in %dx%d@%d\n", x_resolution, y_resolution,
fb_resolution);
@@ -27,9 +28,20 @@

printk(BIOS_DEBUG, "Bootsplash image resolution: %dx%d\n", image_width, image_height);

+ if (image_width > x_resolution || image_height > y_resolution) {
+ printk(BIOS_NOTICE, "Bootsplash image can't fit framebuffer.\n");
+ cbfs_unmap(jpeg);
+ return;
+ }
+
+ /* center image: */
+ framebuffer += (y_resolution - image_height) / 2 * bytes_per_line +
+ (x_resolution - image_width) / 2 * (fb_resolution / 8);
+
decdata = malloc(sizeof(*decdata));
- int ret = jpeg_decode(jpeg, framebuffer, x_resolution, y_resolution, fb_resolution,
- decdata);
+ int ret = jpeg_decode(jpeg, framebuffer, image_width, image_height,
+ bytes_per_line, fb_resolution, decdata);
+ free(decdata);
cbfs_unmap(jpeg);
if (ret != 0) {
printk(BIOS_ERR, "Bootsplash could not be decoded. jpeg_decode returned %d.\n",
diff --git a/src/lib/coreboot_table.c b/src/lib/coreboot_table.c
index bee389d..800d2d4 100644
--- a/src/lib/coreboot_table.c
+++ b/src/lib/coreboot_table.c
@@ -155,8 +155,9 @@
uint8_t *fb_ptr = (uint8_t *)(uintptr_t)framebuffer->physical_address;
unsigned int width = framebuffer->x_resolution;
unsigned int height = framebuffer->y_resolution;
+ unsigned int bytes_per_line = framebuffer->bytes_per_line;
unsigned int depth = framebuffer->bits_per_pixel;
- set_bootsplash(fb_ptr, width, height, depth);
+ set_bootsplash(fb_ptr, width, height, bytes_per_line, depth);
}
}

diff --git a/src/lib/jpeg.c b/src/lib/jpeg.c
index b3d4c89..ed4377f 100644
--- a/src/lib/jpeg.c
+++ b/src/lib/jpeg.c
@@ -267,7 +267,8 @@
}

int jpeg_decode(unsigned char *buf, unsigned char *pic,
- int width, int height, int depth, struct jpeg_decdata *decdata)
+ int width, int height, int bytes_per_line, int depth,
+ struct jpeg_decdata *decdata)
{
int i, j, m, tac, tdc;
int mcusx, mcusy, mx, my;
@@ -382,19 +383,19 @@

switch (depth) {
case 32:
- col221111_32(decdata->out, pic
- + (my * 16 * mcusx + mx) * 16 * 4,
- mcusx * 16 * 4);
+ col221111_32(decdata->out,
+ pic + my * 16 * bytes_per_line + mx * 16 * 4,
+ bytes_per_line);
break;
case 24:
- col221111(decdata->out, pic
- + (my * 16 * mcusx + mx) * 16 * 3,
- mcusx * 16 * 3);
+ col221111(decdata->out,
+ pic + my * 16 * bytes_per_line + mx * 16 * 3,
+ bytes_per_line);
break;
case 16:
- col221111_16(decdata->out, pic
- + (my * 16 * mcusx + mx) * (16 * 2),
- mcusx * (16 * 2));
+ col221111_16(decdata->out,
+ pic + my * 16 * bytes_per_line + mx * 16 * 2,
+ bytes_per_line);
break;
default:
return ERR_DEPTH_MISMATCH;
diff --git a/src/lib/jpeg.h b/src/lib/jpeg.h
index 237da9f..fdb2def 100644
--- a/src/lib/jpeg.h
+++ b/src/lib/jpeg.h
@@ -31,8 +31,7 @@
int dquant[3][64];
};

-int jpeg_decode(unsigned char *, unsigned char *, int, int, int,
- struct jpeg_decdata *);
+int jpeg_decode(unsigned char *, unsigned char *, int, int, int, int, struct jpeg_decdata *);
void jpeg_fetch_size(unsigned char *buf, int *width, int *height);
int jpeg_check_size(unsigned char *, int, int);

diff --git a/util/fuzz-tests/jpeg-test.c b/util/fuzz-tests/jpeg-test.c
index 69e6c8d..da21824 100644
--- a/util/fuzz-tests/jpeg-test.c
+++ b/util/fuzz-tests/jpeg-test.c
@@ -30,7 +30,7 @@
jpeg_fetch_size(buf, &width, &height);
//printf("width: %d, height: %d\n", width, height);
char *pic = malloc(depth / 8 * width * height);
- int ret = jpeg_decode(buf, pic, width, height, depth, decdata);
+ int ret = jpeg_decode(buf, pic, width, height, width * depth / 8, depth, decdata);
//printf("ret: %x\n", ret);
return ret;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
From 0c9e832ea1fe321737b1980588407f283ec92ef2 Mon Sep 17 00:00:00 2001
From: Nico Huber <[email protected]>
Date: Sun, 16 Jul 2023 19:24:13 +0200
Subject: [PATCH] bootsplash: Add ImageMagick voodoo

Ta-da!

(commit message tbd)

Change-Id: I564e0d89fb46503ff4c11e095726616700009968
Signed-off-by: Nico Huber <[email protected]>
---

diff --git a/Makefile.inc b/Makefile.inc
index 0d38ea3..5e1dcee 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -357,6 +357,24 @@
$(eval DEPENDENCIES += $(2).d)

#######################################################################
+# Convert image to YCC 4:2:0 JPEG
+# arg1: image input file
+# arg2: output jpg
+cbfs-files-processor-jpg420= \
+ $(eval $(2): $(1) $(KCONFIG_AUTOCONFIG); \
+ printf " CONVERT $$<\n"; \
+ convert $$< $(BOOTSPLASH_RESIZE-y) $(BOOTSPLASH_COLORSWAP-y) \
+ -quality $(CONFIG_BOOTSPLASH_CONVERT_QUALITY)% \
+ -interlace none -colorspace YCC -sampling-factor 4:2:0 \
+ jpg:$$@)
+BOOTSPLASH_RESOLUTION = $(shell res=$(CONFIG_BOOTSPLASH_CONVERT_RESOLUTION); \
+ echo $$(($${res%%x*}/16*16))x$$(($${res##*x}/16*16)) 2>/dev/null)
+BOOTSPLASH_RESIZE-$(CONFIG_BOOTSPLASH_CONVERT_RESIZE) = \
+ -resize $(BOOTSPLASH_RESOLUTION) -background black \
+ -gravity center -extent $(BOOTSPLASH_RESOLUTION)
+BOOTSPLASH_COLORSWAP-$(CONFIG_BOOTSPLASH_CONVERT_COLORSWAP) := -channel-fx 'red<=>blue'
+
+#######################################################################
# Add handler for arbitrary files in CBFS
$(call add-special-class,cbfs-files)
cbfs-files-handler= \
@@ -1281,10 +1299,16 @@
build_info-file := $(obj)/build_info
build_info-type := raw

+ifeq ($(CONFIG_BOOTSPLASH_CONVERT),y)
+cbfs-files-$(CONFIG_BOOTSPLASH_IMAGE) += bootsplash.jpg
+bootsplash.jpg-file := $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE)):jpg420
+bootsplash.jpg-type := bootsplash
+else
BOOTSPLASH_SUFFIX=$(suffix $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE)))
cbfs-files-$(CONFIG_BOOTSPLASH_IMAGE) += bootsplash$(BOOTSPLASH_SUFFIX)
bootsplash$(BOOTSPLASH_SUFFIX)-file := $(call strip_quotes,$(CONFIG_BOOTSPLASH_FILE))
bootsplash$(BOOTSPLASH_SUFFIX)-type := bootsplash
+endif

# Ensure that no payload segment overlaps with memory regions used by ramstage
# (not for x86 since it can relocate itself in that case)
diff --git a/src/Kconfig b/src/Kconfig
index f5ba4fc..e906130 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -447,7 +447,52 @@
# Default value set at the end of the file
help
The path and filename of the file to use as graphical bootsplash
- screen. The file format has to be jpg.
+ screen. The file format has to be JPEG with YCC 4:2:0 color sampling
+ unless converted with "Pre-process bootsplash file with ImageMagick".
+
+ The image can only be displayed by coreboot if it's smaller or has
+ the same size as the framebuffer resolution. Width and height have
+ to be a multiple of 16 pixels.
+
+ Setting these constraints allows a leaner implementation in coreboot.
+ The minimum necessary ImageMagick command line seems to be:
+ $ convert input.img -colorspace YCC -sampling-factor 4:2:0 bootsplash.jpg
+
+config BOOTSPLASH_CONVERT
+ bool "Pre-process bootsplash file with ImageMagick"
+ depends on BOOTSPLASH_IMAGE
+ # Default value set at the end of the file
+ help
+ Use ImageMagick (`convert` program) to convert a bootsplash image
+ to the supported JPEG format.
+
+config BOOTSPLASH_CONVERT_QUALITY
+ int "Bootsplash JPEG target quality (%)"
+ depends on BOOTSPLASH_CONVERT
+ range 1 100
+ # Default value set at the end of the file
+
+config BOOTSPLASH_CONVERT_RESIZE
+ bool "Resize bootsplash image"
+ depends on BOOTSPLASH_CONVERT
+ help
+ Resize the image to the given resolution. Aspect ratio will be kept,
+ adding black bars as necessary.
+
+config BOOTSPLASH_CONVERT_RESOLUTION
+ string "Bootsplash image target size"
+ depends on BOOTSPLASH_CONVERT_RESIZE
+ # Default value set at the end of the file
+ help
+ Target image resolution given as <width>x<height>, e.g. 1024x768.
+ Values not divisible by 16 will be rounded down.
+
+config BOOTSPLASH_CONVERT_COLORSWAP
+ bool "Swap red and blue color channels"
+ depends on BOOTSPLASH_CONVERT
+ help
+ The JPEG decoder currently ignores the framebuffer color order.
+ If your colors seem all wrong, try this option.

config FW_CONFIG
bool "Firmware Configuration Probing"
@@ -1444,6 +1489,18 @@
depends on BOOTSPLASH_IMAGE
default "bootsplash.jpg"

+config BOOTSPLASH_CONVERT
+ depends on BOOTSPLASH_IMAGE
+ default y
+
+config BOOTSPLASH_CONVERT_QUALITY
+ depends on BOOTSPLASH_CONVERT
+ default 70
+
+config BOOTSPLASH_CONVERT_RESOLUTION
+ depends on BOOTSPLASH_CONVERT_RESIZE
+ default "1024x768"
+
config CBFS_SIZE
default ROM_SIZE

0 comments on commit 92c2ba2

Please sign in to comment.