xref: /openbmc/u-boot/tools/rkcommon.h (revision c5330ae8)
1 /*
2  * (C) Copyright 2015 Google,  Inc
3  * Written by Simon Glass <sjg@chromium.org>
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #ifndef _RKCOMMON_H
9 #define _RKCOMMON_H
10 
11 enum {
12 	RK_BLK_SIZE		= 512,
13 	RK_INIT_OFFSET		= 4,
14 	RK_MAX_BOOT_SIZE	= 512 << 10,
15 	RK_SPL_HDR_START	= RK_INIT_OFFSET * RK_BLK_SIZE,
16 	RK_SPL_HDR_SIZE		= 4,
17 	RK_SPL_START		= RK_SPL_HDR_START + RK_SPL_HDR_SIZE,
18 	RK_IMAGE_HEADER_LEN	= RK_SPL_START,
19 };
20 
21 /**
22  * rkcommon_check_params() - check params
23  *
24  * @return 0 if OK, -1 if ERROR.
25  */
26 int rkcommon_check_params(struct image_tool_params *params);
27 
28 /**
29  * rkcommon_get_spl_hdr() - get 4-bytes spl hdr for a Rockchip boot image
30  *
31  * Rockchip's bootrom requires the spl loader to start with a 4-bytes
32  * header. The content of this header depends on the chip type.
33  */
34 const char *rkcommon_get_spl_hdr(struct image_tool_params *params);
35 
36 /**
37  * rkcommon_get_spl_size() - get spl size for a Rockchip boot image
38  *
39  * Different chip may have different sram size. And if we want to jump
40  * back to the bootrom after spl, we may need to reserve some sram space
41  * for the bootrom.
42  * The spl loader size should be sram size minus reserved size(if needed)
43  */
44 int rkcommon_get_spl_size(struct image_tool_params *params);
45 
46 /**
47  * rkcommon_set_header() - set up the header for a Rockchip boot image
48  *
49  * This sets up a 2KB header which can be interpreted by the Rockchip boot ROM.
50  *
51  * @buf:	Pointer to header place (must be at least 2KB in size)
52  * @file_size:	Size of the file we want the boot ROM to load, in bytes
53  * @return 0 if OK, -ENOSPC if too large
54  */
55 int rkcommon_set_header(void *buf, uint file_size,
56 			struct image_tool_params *params);
57 
58 /**
59  * rkcommon_need_rc4_spl() - check if rc4 encoded spl is required
60  *
61  * Some socs cannot disable the rc4-encryption of the spl binary.
62  * rc4 encryption is disabled normally except on socs that cannot
63  * handle unencrypted binaries.
64  * @return true or false depending on rc4 being required.
65  */
66 bool rkcommon_need_rc4_spl(struct image_tool_params *params);
67 
68 /**
69  * rkcommon_rc4_encode_spl() - encode the spl binary
70  *
71  * Encrypts the SPL binary using the generic rc4 key as required
72  * by some socs.
73  *
74  * @buf:	Pointer to the SPL data (header and SPL binary)
75  * @offset:	offset inside buf to start at
76  * @size:	number of bytes to encode
77  */
78 void rkcommon_rc4_encode_spl(void *buf, unsigned int offset, unsigned int size);
79 
80 #endif
81