1a131c1f4SSimon Glass /* 2a131c1f4SSimon Glass * (C) Copyright 2015 Google, Inc 3a131c1f4SSimon Glass * Written by Simon Glass <sjg@chromium.org> 4a131c1f4SSimon Glass * 5a131c1f4SSimon Glass * SPDX-License-Identifier: GPL-2.0+ 6a131c1f4SSimon Glass */ 7a131c1f4SSimon Glass 8a131c1f4SSimon Glass #ifndef _RKCOMMON_H 9a131c1f4SSimon Glass #define _RKCOMMON_H 10a131c1f4SSimon Glass 11a131c1f4SSimon Glass enum { 12a131c1f4SSimon Glass RK_BLK_SIZE = 512, 133641339eSJeffy Chen RK_INIT_OFFSET = 4, 143641339eSJeffy Chen RK_MAX_BOOT_SIZE = 512 << 10, 157bf274b9SJeffy Chen RK_SPL_HDR_START = RK_INIT_OFFSET * RK_BLK_SIZE, 167bf274b9SJeffy Chen RK_SPL_HDR_SIZE = 4, 177bf274b9SJeffy Chen RK_SPL_START = RK_SPL_HDR_START + RK_SPL_HDR_SIZE, 187bf274b9SJeffy Chen RK_IMAGE_HEADER_LEN = RK_SPL_START, 19a131c1f4SSimon Glass }; 20a131c1f4SSimon Glass 21a131c1f4SSimon Glass /** 227bf274b9SJeffy Chen * rkcommon_check_params() - check params 237bf274b9SJeffy Chen * 247bf274b9SJeffy Chen * @return 0 if OK, -1 if ERROR. 257bf274b9SJeffy Chen */ 267bf274b9SJeffy Chen int rkcommon_check_params(struct image_tool_params *params); 277bf274b9SJeffy Chen 287bf274b9SJeffy Chen /** 297bf274b9SJeffy Chen * rkcommon_get_spl_hdr() - get 4-bytes spl hdr for a Rockchip boot image 307bf274b9SJeffy Chen * 317bf274b9SJeffy Chen * Rockchip's bootrom requires the spl loader to start with a 4-bytes 327bf274b9SJeffy Chen * header. The content of this header depends on the chip type. 337bf274b9SJeffy Chen */ 347bf274b9SJeffy Chen const char *rkcommon_get_spl_hdr(struct image_tool_params *params); 357bf274b9SJeffy Chen 367bf274b9SJeffy Chen /** 377bf274b9SJeffy Chen * rkcommon_get_spl_size() - get spl size for a Rockchip boot image 387bf274b9SJeffy Chen * 397bf274b9SJeffy Chen * Different chip may have different sram size. And if we want to jump 407bf274b9SJeffy Chen * back to the bootrom after spl, we may need to reserve some sram space 417bf274b9SJeffy Chen * for the bootrom. 427bf274b9SJeffy Chen * The spl loader size should be sram size minus reserved size(if needed) 437bf274b9SJeffy Chen */ 447bf274b9SJeffy Chen int rkcommon_get_spl_size(struct image_tool_params *params); 457bf274b9SJeffy Chen 467bf274b9SJeffy Chen /** 47a131c1f4SSimon Glass * rkcommon_set_header() - set up the header for a Rockchip boot image 48a131c1f4SSimon Glass * 49a131c1f4SSimon Glass * This sets up a 2KB header which can be interpreted by the Rockchip boot ROM. 50a131c1f4SSimon Glass * 51a131c1f4SSimon Glass * @buf: Pointer to header place (must be at least 2KB in size) 52a131c1f4SSimon Glass * @file_size: Size of the file we want the boot ROM to load, in bytes 53a131c1f4SSimon Glass * @return 0 if OK, -ENOSPC if too large 54a131c1f4SSimon Glass */ 557bf274b9SJeffy Chen int rkcommon_set_header(void *buf, uint file_size, 567bf274b9SJeffy Chen struct image_tool_params *params); 57a131c1f4SSimon Glass 58cfbcdadeSHeiko Stübner /** 59cfbcdadeSHeiko Stübner * rkcommon_need_rc4_spl() - check if rc4 encoded spl is required 60cfbcdadeSHeiko Stübner * 61cfbcdadeSHeiko Stübner * Some socs cannot disable the rc4-encryption of the spl binary. 62cfbcdadeSHeiko Stübner * rc4 encryption is disabled normally except on socs that cannot 63cfbcdadeSHeiko Stübner * handle unencrypted binaries. 64cfbcdadeSHeiko Stübner * @return true or false depending on rc4 being required. 65cfbcdadeSHeiko Stübner */ 66cfbcdadeSHeiko Stübner bool rkcommon_need_rc4_spl(struct image_tool_params *params); 67cfbcdadeSHeiko Stübner 68cfbcdadeSHeiko Stübner /** 69cfbcdadeSHeiko Stübner * rkcommon_rc4_encode_spl() - encode the spl binary 70cfbcdadeSHeiko Stübner * 71cfbcdadeSHeiko Stübner * Encrypts the SPL binary using the generic rc4 key as required 72cfbcdadeSHeiko Stübner * by some socs. 73cfbcdadeSHeiko Stübner * 74cfbcdadeSHeiko Stübner * @buf: Pointer to the SPL data (header and SPL binary) 75cfbcdadeSHeiko Stübner * @offset: offset inside buf to start at 76cfbcdadeSHeiko Stübner * @size: number of bytes to encode 77cfbcdadeSHeiko Stübner */ 78cfbcdadeSHeiko Stübner void rkcommon_rc4_encode_spl(void *buf, unsigned int offset, unsigned int size); 79cfbcdadeSHeiko Stübner 80111bcc4fSPhilipp Tomsich /** 81111bcc4fSPhilipp Tomsich * rkcommon_vrec_header() - allocate memory for the header 82111bcc4fSPhilipp Tomsich * 83111bcc4fSPhilipp Tomsich * @params: Pointer to the tool params structure 84111bcc4fSPhilipp Tomsich * @tparams: Pointer tot the image type structure (for setting 85111bcc4fSPhilipp Tomsich * the header and header_size) 86*366aad4dSPhilipp Tomsich * @alignment: Alignment (a power of two) that the image should be 87*366aad4dSPhilipp Tomsich * padded to (e.g. 512 if we want to align with SD/MMC 88*366aad4dSPhilipp Tomsich * blocksizes or 2048 for the SPI format) 89*366aad4dSPhilipp Tomsich * 90*366aad4dSPhilipp Tomsich * @return bytes of padding required/added (does not include the header_size) 91111bcc4fSPhilipp Tomsich */ 92*366aad4dSPhilipp Tomsich int rkcommon_vrec_header(struct image_tool_params *params, 93*366aad4dSPhilipp Tomsich struct image_type_params *tparams, 94*366aad4dSPhilipp Tomsich unsigned int alignment); 95111bcc4fSPhilipp Tomsich 96a131c1f4SSimon Glass #endif 97