summaryrefslogtreecommitdiffstats
path: root/lib/logo/logo.c
blob: 614d8c09081efbdfc4ca9623605da6e31cbf014a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * Copyright (c) 2015 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
#include <common.h>
#include <init.h>
#include <fs.h>
#include <libfile.h>
#include <malloc.h>

#define DEFINE_LOGO(width)							\
	extern char __bblogo_barebox_logo_w##width##_start[];			\
	extern char __bblogo_barebox_logo_w##width##_end[];			\
										\
	static void load_logo_##width(void)					\
	{									\
		if (!IS_ENABLED(CONFIG_BAREBOX_LOGO_##width))			\
			return;							\
		load_logo(width, __bblogo_barebox_logo_w##width##_start,	\
				__bblogo_barebox_logo_w##width##_end);		\
	}

static void load_logo(int width, void *start, void *end)
{
	char *filename;
	size_t size = end - start;

	filename = asprintf("/logo/barebox-logo-%d.png", width);
	write_file(filename, start, size);
	free(filename);
}

DEFINE_LOGO(64);
DEFINE_LOGO(240);
DEFINE_LOGO(320);
DEFINE_LOGO(400);
DEFINE_LOGO(640);

static int logo_init(void)
{
	int ret;

	ret = make_directory("/logo");
	if (ret)
		return ret;

	load_logo_64();
	load_logo_240();
	load_logo_320();
	load_logo_400();
	load_logo_640();

	return 0;
}
postenvironment_initcall(logo_init);