blob: 49b6df31850152420ad3c75898a7ab69bb32f666 [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,
Jeffy Chenec0d2ea2019-12-27 11:24:41 +080012 RK_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,
Simon Glassc9c74032015-08-30 16:55:24 -060017};
18
19/**
Jeffy Chen06cdc342015-11-27 12:07:17 +080020 * rkcommon_check_params() - check params
21 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010022 * Return: 0 if OK, -1 if ERROR.
Jeffy Chen06cdc342015-11-27 12:07:17 +080023 */
24int rkcommon_check_params(struct image_tool_params *params);
25
26/**
27 * rkcommon_get_spl_hdr() - get 4-bytes spl hdr for a Rockchip boot image
28 *
29 * Rockchip's bootrom requires the spl loader to start with a 4-bytes
30 * header. The content of this header depends on the chip type.
31 */
32const char *rkcommon_get_spl_hdr(struct image_tool_params *params);
33
34/**
35 * rkcommon_get_spl_size() - get spl size for a Rockchip boot image
36 *
37 * Different chip may have different sram size. And if we want to jump
38 * back to the bootrom after spl, we may need to reserve some sram space
39 * for the bootrom.
40 * The spl loader size should be sram size minus reserved size(if needed)
41 */
42int rkcommon_get_spl_size(struct image_tool_params *params);
43
44/**
Simon Glassc9c74032015-08-30 16:55:24 -060045 * rkcommon_set_header() - set up the header for a Rockchip boot image
46 *
47 * This sets up a 2KB header which can be interpreted by the Rockchip boot ROM.
48 *
49 * @buf: Pointer to header place (must be at least 2KB in size)
Simon Glassc9c74032015-08-30 16:55:24 -060050 */
Jeffy Chenec0d2ea2019-12-27 11:24:41 +080051void rkcommon_set_header(void *buf, struct stat *sbuf, int ifd,
52 struct image_tool_params *params);
Simon Glassc9c74032015-08-30 16:55:24 -060053
Heiko Stübner3b404d42017-02-18 19:46:27 +010054/**
Philipp Tomsichf0d09fb2017-05-30 23:32:08 +020055 * rkcommon_verify_header() - verify the header for a Rockchip boot image
56 *
57 * @buf: Pointer to the image file
58 * @file_size: Size of entire bootable image file (incl. all padding)
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010059 * Return: 0 if OK
Philipp Tomsichf0d09fb2017-05-30 23:32:08 +020060 */
61int rkcommon_verify_header(unsigned char *buf, int size,
62 struct image_tool_params *params);
63
64/**
65 * rkcommon_print_header() - print the header for a Rockchip boot image
66 *
67 * This prints the header, spl_name and whether this is a SD/MMC or SPI image.
68 *
69 * @buf: Pointer to the image (can be a read-only file-mapping)
70 */
71void rkcommon_print_header(const void *buf);
72
73/**
Heiko Stübner3b404d42017-02-18 19:46:27 +010074 * rkcommon_need_rc4_spl() - check if rc4 encoded spl is required
75 *
76 * Some socs cannot disable the rc4-encryption of the spl binary.
77 * rc4 encryption is disabled normally except on socs that cannot
78 * handle unencrypted binaries.
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010079 * Return: true or false depending on rc4 being required.
Heiko Stübner3b404d42017-02-18 19:46:27 +010080 */
81bool rkcommon_need_rc4_spl(struct image_tool_params *params);
82
83/**
84 * rkcommon_rc4_encode_spl() - encode the spl binary
85 *
86 * Encrypts the SPL binary using the generic rc4 key as required
87 * by some socs.
88 *
89 * @buf: Pointer to the SPL data (header and SPL binary)
90 * @offset: offset inside buf to start at
91 * @size: number of bytes to encode
92 */
93void rkcommon_rc4_encode_spl(void *buf, unsigned int offset, unsigned int size);
94
Philipp Tomsich087ce822017-03-15 12:08:43 +010095/**
96 * rkcommon_vrec_header() - allocate memory for the header
97 *
98 * @params: Pointer to the tool params structure
99 * @tparams: Pointer tot the image type structure (for setting
100 * the header and header_size)
Philipp Tomsichd2eaf412017-04-17 17:48:01 +0200101 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100102 * Return: 0 (always)
Philipp Tomsich087ce822017-03-15 12:08:43 +0100103 */
Philipp Tomsichd2eaf412017-04-17 17:48:01 +0200104int rkcommon_vrec_header(struct image_tool_params *params,
Jeffy Chenec0d2ea2019-12-27 11:24:41 +0800105 struct image_type_params *tparams);
Philipp Tomsich087ce822017-03-15 12:08:43 +0100106
Simon Glassc9c74032015-08-30 16:55:24 -0600107#endif