summaryrefslogtreecommitdiff
path: root/include/boot.h
blob: 34bfa88d244895501257db2eead255dfbbe374ce (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
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __BOOT_H
#define __BOOT_H

#include <sys/types.h>
#include <stdint.h>

/*
 * payload loading and the arm64 boot protocol. See Documentation/
 * arch/arm64/booting.rst in the kernel tree for the register contract
 * we honour when jumping.
 */

#define LINUX_ARM64_IMAGE_MAGIC	0x644d5241

/* the 64 byte header every arm64 kernel Image starts with */
struct Image_header {
	uint32_t	code0;		/* Executable code */
	uint32_t	code1;		/* Executable code */
	uint64_t	text_offset;	/* Image load offset, LE */
	uint64_t	image_size;	/* Effective Image size, LE */
	uint64_t	flags;		/* Kernel flags, LE */
	uint64_t	res2;		/* reserved */
	uint64_t	res3;		/* reserved */
	uint64_t	res4;		/* reserved */
	uint32_t	magic;		/* Magic number */
	uint32_t	res5;
};

struct tb_image {
	uintptr_t	ep;		/* entry point to jump to */
	uint64_t	size;		/* image size in bytes */
	uintptr_t	load;		/* address the image was placed at */
};

/*
 * validate the header at image and work out where it wants to live.
 * returns 0 and fills img on success, negative on a bad image.
 */
int tb_image_setup(uintptr_t image, uintptr_t mem_base, uint32 mem_size,
		   struct tb_image *img);

/*
 * load the payload from semihosting into mem_base. returns 0 and fills
 * img, negative when there is no debugger or no file.
 */
int tb_load_semihosting(const char *fname, uintptr_t load_addr,
			uintptr_t mem_base, uint32 mem_size,
			struct tb_image *img);

/*
 * jump to the kernel: x0 = dtb, x1 = x2 = x3 = 0. never returns.
 */
void __NO_RETURN tb_boot_linux(uintptr_t ep, const void *dtb);

#endif