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