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 /** 37*111bcc4fSPhilipp Tomsich * rkcommon_get_spl_hdr_padto8() - check if we need to pad to 8 bytes 38*111bcc4fSPhilipp Tomsich * 39*111bcc4fSPhilipp Tomsich * Rockchip's bootrom starts execution right after the SPL header (i.e. 40*111bcc4fSPhilipp Tomsich * at offset 4), but we can not reasonably align the test section of 41*111bcc4fSPhilipp Tomsich * an AArch64 SPL at 4 bytes (as this would break natural alignment 42*111bcc4fSPhilipp Tomsich * and any embedded constants might cause an alignment exception, which 43*111bcc4fSPhilipp Tomsich * is illegal in privileged modes). 44*111bcc4fSPhilipp Tomsich * 45*111bcc4fSPhilipp Tomsich * Padding is (for now) assumed to occur with a single AArch64 'nop'. 46*111bcc4fSPhilipp Tomsich */ 47*111bcc4fSPhilipp Tomsich const bool rkcommon_get_spl_hdr_padto8(struct image_tool_params *params); 48*111bcc4fSPhilipp Tomsich 49*111bcc4fSPhilipp Tomsich /** 507bf274b9SJeffy Chen * rkcommon_get_spl_size() - get spl size for a Rockchip boot image 517bf274b9SJeffy Chen * 527bf274b9SJeffy Chen * Different chip may have different sram size. And if we want to jump 537bf274b9SJeffy Chen * back to the bootrom after spl, we may need to reserve some sram space 547bf274b9SJeffy Chen * for the bootrom. 557bf274b9SJeffy Chen * The spl loader size should be sram size minus reserved size(if needed) 567bf274b9SJeffy Chen */ 577bf274b9SJeffy Chen int rkcommon_get_spl_size(struct image_tool_params *params); 587bf274b9SJeffy Chen 597bf274b9SJeffy Chen /** 60a131c1f4SSimon Glass * rkcommon_set_header() - set up the header for a Rockchip boot image 61a131c1f4SSimon Glass * 62a131c1f4SSimon Glass * This sets up a 2KB header which can be interpreted by the Rockchip boot ROM. 63a131c1f4SSimon Glass * 64a131c1f4SSimon Glass * @buf: Pointer to header place (must be at least 2KB in size) 65a131c1f4SSimon Glass * @file_size: Size of the file we want the boot ROM to load, in bytes 66a131c1f4SSimon Glass * @return 0 if OK, -ENOSPC if too large 67a131c1f4SSimon Glass */ 687bf274b9SJeffy Chen int rkcommon_set_header(void *buf, uint file_size, 697bf274b9SJeffy Chen struct image_tool_params *params); 70a131c1f4SSimon Glass 71cfbcdadeSHeiko Stübner /** 72cfbcdadeSHeiko Stübner * rkcommon_need_rc4_spl() - check if rc4 encoded spl is required 73cfbcdadeSHeiko Stübner * 74cfbcdadeSHeiko Stübner * Some socs cannot disable the rc4-encryption of the spl binary. 75cfbcdadeSHeiko Stübner * rc4 encryption is disabled normally except on socs that cannot 76cfbcdadeSHeiko Stübner * handle unencrypted binaries. 77cfbcdadeSHeiko Stübner * @return true or false depending on rc4 being required. 78cfbcdadeSHeiko Stübner */ 79cfbcdadeSHeiko Stübner bool rkcommon_need_rc4_spl(struct image_tool_params *params); 80cfbcdadeSHeiko Stübner 81cfbcdadeSHeiko Stübner /** 82cfbcdadeSHeiko Stübner * rkcommon_rc4_encode_spl() - encode the spl binary 83cfbcdadeSHeiko Stübner * 84cfbcdadeSHeiko Stübner * Encrypts the SPL binary using the generic rc4 key as required 85cfbcdadeSHeiko Stübner * by some socs. 86cfbcdadeSHeiko Stübner * 87cfbcdadeSHeiko Stübner * @buf: Pointer to the SPL data (header and SPL binary) 88cfbcdadeSHeiko Stübner * @offset: offset inside buf to start at 89cfbcdadeSHeiko Stübner * @size: number of bytes to encode 90cfbcdadeSHeiko Stübner */ 91cfbcdadeSHeiko Stübner void rkcommon_rc4_encode_spl(void *buf, unsigned int offset, unsigned int size); 92cfbcdadeSHeiko Stübner 93*111bcc4fSPhilipp Tomsich /** 94*111bcc4fSPhilipp Tomsich * rkcommon_vrec_header() - allocate memory for the header 95*111bcc4fSPhilipp Tomsich * 96*111bcc4fSPhilipp Tomsich * @params: Pointer to the tool params structure 97*111bcc4fSPhilipp Tomsich * @tparams: Pointer tot the image type structure (for setting 98*111bcc4fSPhilipp Tomsich * the header and header_size) 99*111bcc4fSPhilipp Tomsich */ 100*111bcc4fSPhilipp Tomsich void rkcommon_vrec_header(struct image_tool_params *params, 101*111bcc4fSPhilipp Tomsich struct image_type_params *tparams); 102*111bcc4fSPhilipp Tomsich 103a131c1f4SSimon Glass #endif 104