blob: 47f47a52aaf2208cca1cbf91bc1b547cd6f85af8 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glassc9c74032015-08-30 16:55:24 -06002/*
3 * (C) Copyright 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glassc9c74032015-08-30 16:55:24 -06005 */
6
7#ifndef _RKCOMMON_H
8#define _RKCOMMON_H
9
10enum {
11 RK_BLK_SIZE = 512,
Philipp Tomsiche3b84dd2017-05-30 23:32:09 +020012 RK_INIT_SIZE_ALIGN = 2048,
Jeffy Chen0e7c90a2015-11-17 14:20:30 +080013 RK_INIT_OFFSET = 4,
14 RK_MAX_BOOT_SIZE = 512 << 10,
Jeffy Chen06cdc342015-11-27 12:07:17 +080015 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,
Simon Glassc9c74032015-08-30 16:55:24 -060019};
20
21/**
Jeffy Chen06cdc342015-11-27 12:07:17 +080022 * rkcommon_check_params() - check params
23 *
24 * @return 0 if OK, -1 if ERROR.
25 */
26int 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 */
34const 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 */
44int rkcommon_get_spl_size(struct image_tool_params *params);
45
46/**
Simon Glassc9c74032015-08-30 16:55:24 -060047 * 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 */
Jeffy Chen06cdc342015-11-27 12:07:17 +080055int rkcommon_set_header(void *buf, uint file_size,
56 struct image_tool_params *params);
Simon Glassc9c74032015-08-30 16:55:24 -060057
Heiko Stübner3b404d42017-02-18 19:46:27 +010058/**
Philipp Tomsichf0d09fb2017-05-30 23:32:08 +020059 * rkcommon_verify_header() - verify the header for a Rockchip boot image
60 *
61 * @buf: Pointer to the image file
62 * @file_size: Size of entire bootable image file (incl. all padding)
63 * @return 0 if OK
64 */
65int rkcommon_verify_header(unsigned char *buf, int size,
66 struct image_tool_params *params);
67
68/**
69 * rkcommon_print_header() - print the header for a Rockchip boot image
70 *
71 * This prints the header, spl_name and whether this is a SD/MMC or SPI image.
72 *
73 * @buf: Pointer to the image (can be a read-only file-mapping)
74 */
75void rkcommon_print_header(const void *buf);
76
77/**
Heiko Stübner3b404d42017-02-18 19:46:27 +010078 * rkcommon_need_rc4_spl() - check if rc4 encoded spl is required
79 *
80 * Some socs cannot disable the rc4-encryption of the spl binary.
81 * rc4 encryption is disabled normally except on socs that cannot
82 * handle unencrypted binaries.
83 * @return true or false depending on rc4 being required.
84 */
85bool rkcommon_need_rc4_spl(struct image_tool_params *params);
86
87/**
88 * rkcommon_rc4_encode_spl() - encode the spl binary
89 *
90 * Encrypts the SPL binary using the generic rc4 key as required
91 * by some socs.
92 *
93 * @buf: Pointer to the SPL data (header and SPL binary)
94 * @offset: offset inside buf to start at
95 * @size: number of bytes to encode
96 */
97void rkcommon_rc4_encode_spl(void *buf, unsigned int offset, unsigned int size);
98
Philipp Tomsich087ce822017-03-15 12:08:43 +010099/**
100 * rkcommon_vrec_header() - allocate memory for the header
101 *
102 * @params: Pointer to the tool params structure
103 * @tparams: Pointer tot the image type structure (for setting
104 * the header and header_size)
Philipp Tomsichd2eaf412017-04-17 17:48:01 +0200105 * @alignment: Alignment (a power of two) that the image should be
106 * padded to (e.g. 512 if we want to align with SD/MMC
107 * blocksizes or 2048 for the SPI format)
108 *
109 * @return bytes of padding required/added (does not include the header_size)
Philipp Tomsich087ce822017-03-15 12:08:43 +0100110 */
Philipp Tomsichd2eaf412017-04-17 17:48:01 +0200111int rkcommon_vrec_header(struct image_tool_params *params,
112 struct image_type_params *tparams,
113 unsigned int alignment);
Philipp Tomsich087ce822017-03-15 12:08:43 +0100114
Simon Glassc9c74032015-08-30 16:55:24 -0600115#endif