Skip to content

Commit 5291d5c

Browse files
jannausvenpeter42
authored andcommitted
fb: Add custom boot logo support
Some distributions wish to customize m1n1's boot logo. Instead having overwrite the existing logo files add build system support for this. `make LOGO=custom` will create m1n1.bin with a custom logo created from 'data/custom_{128,256}.png'. In addition m1n1-asahi.bin is created which carries only the built-in asahi logo. This is implemented via a logo payload which used by m1n1 when it's the first payload. Closes: #238 Signed-off-by: Janne Grunau <j@jannau.net>
1 parent bd65c41 commit 5291d5c

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,21 @@ build/$(NAME).macho: build/$(NAME).elf
234234
$(QUIET)echo " MACHO $@"
235235
$(QUIET)$(OBJCOPY) -O binary --strip-debug $< $@
236236

237+
ifeq ($(LOGO),)
237238
build/$(NAME).bin: build/$(NAME)-raw.elf
238239
$(QUIET)echo " RAW $@"
239240
$(QUIET)$(OBJCOPY) -O binary --strip-debug $< $@
240241

242+
else
243+
build/$(NAME)-asahi.bin: build/$(NAME)-raw.elf
244+
$(QUIET)echo " RAW $@"
245+
$(QUIET)$(OBJCOPY) -O binary --strip-debug $< $@
246+
247+
build/$(NAME).bin: build/$(NAME)-asahi.bin build/$(LOGO).logo
248+
$(QUIET)echo " RAW $@"
249+
$(QUIET)cat $^ > $@
250+
endif
251+
241252
.INTERMEDIATE: build-tag build-cfg
242253
build-tag src/../build/build_tag.h &:
243254
$(QUIET)mkdir -p build
@@ -266,4 +277,16 @@ build/%.bin: font/%.bin
266277
$(QUIET)mkdir -p "$(dir $@)"
267278
$(QUIET)cp $< $@
268279

280+
build/%.rgba: data/%.png
281+
$(eval SIZE := $(lastword $(subst _, ,$*)))
282+
$(QUIET)echo " MAGIC $@"
283+
$(QUIET)mkdir -p "$(dir $@)"
284+
$(QUIET)magick $< -background black -flatten -depth 8 -crop $(SIZE)x$(SIZE) -resize $(SIZE)x$(SIZE) rgba:$@
285+
286+
build/%.logo: build/%_256.rgba build/%_128.rgba
287+
$(QUIET)echo " PAYLOAD $@"
288+
$(QUIET)mkdir -p "$(dir $@)"
289+
$(QUIET)echo -n "m1n1_logo_256128" > $@
290+
$(QUIET)cat $^ >> $@
291+
269292
-include $(DEPDIR)/*

src/fb.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "iodev.h"
66
#include "malloc.h"
77
#include "memory.h"
8+
#include "payload.h"
89
#include "string.h"
910
#include "types.h"
1011
#include "utils.h"
@@ -69,6 +70,8 @@ const struct image logo_256 = {
6970
.height = 256,
7071
};
7172

73+
struct image custom_logo = {};
74+
7275
const struct image *logo;
7376
struct image orig_logo;
7477

@@ -402,6 +405,7 @@ void fb_clear_direct(void)
402405

403406
void fb_init(bool clear)
404407
{
408+
void *custom_128, *custom_256;
405409
fb.hwptr = (void *)cur_boot_args.video.base;
406410
fb.stride = cur_boot_args.video.stride / 4;
407411
fb.width = cur_boot_args.video.width;
@@ -460,6 +464,19 @@ void fb_init(bool clear)
460464
&orig_logo);
461465
}
462466

467+
if (payload_logo(&custom_128, &custom_256)) {
468+
custom_logo = *logo;
469+
if (custom_logo.width == 256) {
470+
custom_logo.ptr = custom_256;
471+
logo = &custom_logo;
472+
} else if (custom_logo.width == 128) {
473+
custom_logo.ptr = custom_128;
474+
logo = &custom_logo;
475+
} else {
476+
printf("fb: unexpected logo dimensions %ux%u\n", custom_logo.width, custom_logo.height);
477+
}
478+
}
479+
463480
if (clear) {
464481
memset32(fb.ptr, 0, fb.size);
465482
} else {

src/payload.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ static const u8 initramfs_magic[] = {
3434
'i', 't', 'r', 'a', 'm', 'f', 's'}; // followed by size as little endian uint32_t
3535
static const u8 empty[] = {0, 0, 0, 0};
3636

37+
// custom logo is RGBA with 256x256 retina logo followed by half resolution
38+
static const u8 custom_logo_magic[] = {'m', '1', 'n', '1', '_', 'l', 'o', 'g',
39+
'o', '_', '2', '5', '6', '1', '2', '8'};
40+
#define CUSTOM_LOGO_SIZE (4 * ((256 * 256) + (128 * 128)))
41+
3742
static char expect_compatible[256];
3843
static struct kernel_header *kernel = NULL;
3944
static void *fdt = NULL;
@@ -241,6 +246,10 @@ static void *load_one_payload(void *start, size_t size)
241246
printf("Found a m1n1 initramfs payload at %p, 0x%x bytes\n", p, size);
242247
p += sizeof(initramfs_magic) + 4;
243248
return load_cpio(p, size);
249+
} else if (!memcmp(p, custom_logo_magic, sizeof(custom_logo_magic))) {
250+
printf("Found a m1n1 custom logo payload at %p, skipping 0x%lx bytes\n", p,
251+
sizeof(custom_logo_magic) + CUSTOM_LOGO_SIZE);
252+
return p + sizeof(custom_logo_magic) + CUSTOM_LOGO_SIZE;
244253
} else if (check_var(&p)) {
245254
return p;
246255
} else if (!memcmp(p, empty, sizeof empty) ||
@@ -260,6 +269,25 @@ void do_enable_tso(void)
260269
msr(ACTLR_EL1, actlr);
261270
}
262271

272+
bool payload_logo(void **custom_128, void **custom_256)
273+
{
274+
void *p = _payload_start;
275+
276+
*custom_128 = NULL;
277+
*custom_256 = NULL;
278+
279+
if (!memcmp(p, custom_logo_magic, sizeof(custom_logo_magic))) {
280+
void *data = p + sizeof(custom_logo_magic);
281+
printf("Found a m1n1 custom logo payload at %p\n", p);
282+
*custom_256 = data;
283+
*custom_128 = data + 4 * 256 * 256;
284+
285+
return true;
286+
}
287+
288+
return false;
289+
}
290+
263291
int payload_run(void)
264292
{
265293
const char *target = adt_getprop(adt, 0, "target-type", NULL);

src/payload.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#ifndef __PAYLOAD_H__
44
#define __PAYLOAD_H__
55

6+
#include "types.h"
7+
8+
bool payload_logo(void **custom_128, void **custom_256);
9+
610
int payload_run(void);
711

812
#endif

0 commit comments

Comments
 (0)