xref: /rk3399_rockchip-uboot/include/spl_rkfw.h (revision f36ea2f6e17621c4d9dd97c4dbfab62d03d061df)
1 /* SPDX-License-Identifier:     GPL-2.0+ */
2 /*
3  * (C) Copyright 2019 Rockchip Electronics Co., Ltd
4  */
5 
6 #ifndef _SPL_RKFW_H_
7 #define _SPL_RKFW_H_
8 
9 #include <spl.h>
10 
11 #define LOADER_HARD_STR			"LOADER"
12 #ifdef CONFIG_SPL_ATF
13 #define TBOOT_HEAD_TAG			0x58334c42 /* 'B', 'L', '3', 'X' */
14 #else
15 #define TBOOT_HEAD_TAG			"TOS   "
16 #endif
17 
18 #define BL30_IMAGE_NAME			"bl30.bin" /* SCP Firmware BL3-0 */
19 #define BL31_IMAGE_NAME			"bl31.bin" /* EL3 Runtime Firmware BL31 */
20 #define BL32_IMAGE_NAME			"bl32.bin" /* Secure Payload BL32 (Trusted OS) */
21 
22 #define UUID_SCP_FIRMWARE_BL30		0x30334c42 /* "BL30" */
23 #define UUID_EL3_RUNTIME_FIRMWARE_BL31	0x31334c42 /* "BL31" */
24 #define UUID_SECURE_PAYLOAD_BL32	0x32334c42 /* "BL32" */
25 
26 /* Signature size, unit is byte */
27 #define SIGNATURE_SIZE			256
28 #define MAX_BL_CODE_NUM			6
29 #define LOADER_MAGIC_SIZE		8
30 #define LOADER_HASH_SIZE		32
31 
32 /* Special value used to verify platform parameters from BL2 to BL3-1 */
33 #define RK_BL31_PLAT_PARAM_VAL		0x0f1e2d3c4b5a6978ULL
34 
35 #define RKFW_RETRY_SECTOR_SIZE		1024
36 #define RKFW_RETRY_SECTOR_TIMES		8
37 
38 struct s_fip_name_id {
39 	const char *name;
40 	const u32 id;
41 };
42 
43 typedef struct tag_tboot_header_2k {
44 	u32 tag;
45 	u32 version;
46 	u32 flags;
47 	u32 size;
48 	u32 reserved1[4];
49 	u32 rsa_n[64];
50 	u32 rsa_e[64];
51 	u32 rsa_c[64];
52 	u32 reserved2[312];
53 } tboot_header_2k, *ptboot_header_2k;
54 
55 typedef struct tag_tboot_header {
56 	u32 tag;
57 	u32 version;
58 	u32 flags;
59 	u32 size;
60 	u32 reserved[4];
61 	u32 rsa_n[64];
62 	u32 rsa_e[64];
63 	u32 rsa_c[64];
64 } tboot_header, *ptboot_header;
65 
66 typedef struct tag_boot_component {
67 	u32 component_id;
68 	u32 storage_addr;
69 	u32 image_size;
70 	u32 reserved;
71 } boot_component, *pboot_component;
72 
73 typedef struct tag_component_data {
74 	u32 hash_data[8];
75 	u32 load_addr;
76 	u32 reserved[3];
77 } component_data, *pcomponent_data;
78 
79 typedef struct tag_tboot_entry {
80 	boot_component component;
81 	component_data compdata;
82 } tboot_entry, *ptboot_entry;
83 
84 typedef struct tag_second_loader_hdr {
85 	unsigned char magic[LOADER_MAGIC_SIZE];
86 	unsigned int version;
87 	unsigned int reserved0;
88 	unsigned int loader_load_addr;		/* physical load addr ,default is 0x60000000 */
89 	unsigned int loader_load_size;		/* size in bytes */
90 	unsigned int crc32;			/* crc32 */
91 	unsigned int hash_len;			/* 20 or 32 , 0 is no hash */
92 	unsigned char hash[LOADER_HASH_SIZE];	/* sha */
93 	unsigned int js_hash;			/* js hsah */
94 	unsigned char reserved[1024-32-32-4];
95 	unsigned int sign_tag;			/* 0x4E474953, 'N' 'G' 'I' 'S' */
96 	unsigned int sign_len;			/* 256 */
97 	unsigned char rsa_hash[256];
98 	unsigned char reserved2[2048-1024-256-8];
99 } second_loader_hdr;				/* Size:2K */
100 
101 /**
102  * spl_load_rkfw_image - Load rockchip image(trust and U-Boot) and jump to bl31.
103  */
104 int spl_load_rkfw_image(struct spl_image_info *spl_image,
105 			struct spl_load_info *info);
106 #endif
107