summaryrefslogtreecommitdiffstats
path: root/arch/riscv/lib/bootm.c
blob: 6984f282be4d8dfd0a76d63c0b41293de4f01368 (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
// SPDX-License-Identifier: GPL-2.0-only
// SPDX-FileCopyrightText: 2018 Sascha Hauer <s.hauer@pengutronix.de>

#include <common.h>
#include <bootm.h>
#include <asm/system.h>

static int do_bootm_linux(struct image_data *data)
{
	void (*fn)(unsigned long a0, unsigned long dtb, unsigned long a2);
	phys_addr_t devicetree;
	long hartid = riscv_hartid();
	int ret;

	fn = booti_load_image(data, &devicetree);
	if (IS_ERR(fn))
		return PTR_ERR(fn);

	if (data->dryrun)
		return 0;

	ret = of_overlay_load_firmware();
	if (ret)
		return ret;

	shutdown_barebox();

	fn(hartid >= 0 ? hartid : 0, devicetree, 0);

	return -EINVAL;
}

static struct image_handler riscv_linux_handler = {
        .name = "RISC-V Linux image",
        .bootm = do_bootm_linux,
        .filetype = filetype_riscv_linux_image,
};

static struct image_handler riscv_fit_handler = {
	.name = "FIT image",
	.bootm = do_bootm_linux,
	.filetype = filetype_oftree,
};

static struct image_handler riscv_barebox_handler = {
        .name = "RISC-V barebox image",
        .bootm = do_bootm_linux,
        .filetype = filetype_riscv_barebox_image,
};

static int riscv_register_image_handler(void)
{
	register_image_handler(&riscv_linux_handler);
	register_image_handler(&riscv_barebox_handler);

	if (IS_ENABLED(CONFIG_FITIMAGE))
		register_image_handler(&riscv_fit_handler);

	return 0;
}
late_initcall(riscv_register_image_handler);