1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * (C) Copyright 2015 Google, Inc 3*4882a593Smuzhiyun * Written by Simon Glass <sjg@chromium.org> 4*4882a593Smuzhiyun * 5*4882a593Smuzhiyun * SPDX-License-Identifier: GPL-2.0+ 6*4882a593Smuzhiyun */ 7*4882a593Smuzhiyun 8*4882a593Smuzhiyun #ifndef _RKCOMMON_H 9*4882a593Smuzhiyun #define _RKCOMMON_H 10*4882a593Smuzhiyun 11*4882a593Smuzhiyun enum { 12*4882a593Smuzhiyun RK_BLK_SIZE = 512, 13*4882a593Smuzhiyun RK_SIZE_ALIGN = 2048, 14*4882a593Smuzhiyun RK_INIT_OFFSET = 4, 15*4882a593Smuzhiyun RK_MAX_BOOT_SIZE = 512 << 10, 16*4882a593Smuzhiyun RK_SPL_HDR_START = RK_INIT_OFFSET * RK_BLK_SIZE, 17*4882a593Smuzhiyun RK_SPL_HDR_SIZE = 4, 18*4882a593Smuzhiyun }; 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun /** 21*4882a593Smuzhiyun * rkcommon_check_params() - check params 22*4882a593Smuzhiyun * 23*4882a593Smuzhiyun * @return 0 if OK, -1 if ERROR. 24*4882a593Smuzhiyun */ 25*4882a593Smuzhiyun int rkcommon_check_params(struct image_tool_params *params); 26*4882a593Smuzhiyun 27*4882a593Smuzhiyun /** 28*4882a593Smuzhiyun * rkcommon_get_spl_hdr() - get 4-bytes spl hdr for a Rockchip boot image 29*4882a593Smuzhiyun * 30*4882a593Smuzhiyun * Rockchip's bootrom requires the spl loader to start with a 4-bytes 31*4882a593Smuzhiyun * header. The content of this header depends on the chip type. 32*4882a593Smuzhiyun */ 33*4882a593Smuzhiyun const char *rkcommon_get_spl_hdr(struct image_tool_params *params); 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun /** 36*4882a593Smuzhiyun * rkcommon_get_spl_size() - get spl size for a Rockchip boot image 37*4882a593Smuzhiyun * 38*4882a593Smuzhiyun * Different chip may have different sram size. And if we want to jump 39*4882a593Smuzhiyun * back to the bootrom after spl, we may need to reserve some sram space 40*4882a593Smuzhiyun * for the bootrom. 41*4882a593Smuzhiyun * The spl loader size should be sram size minus reserved size(if needed) 42*4882a593Smuzhiyun */ 43*4882a593Smuzhiyun int rkcommon_get_spl_size(struct image_tool_params *params); 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun /** 46*4882a593Smuzhiyun * rkcommon_set_header() - set up the header for a Rockchip boot image 47*4882a593Smuzhiyun * 48*4882a593Smuzhiyun * This sets up a 2KB header which can be interpreted by the Rockchip boot ROM. 49*4882a593Smuzhiyun * 50*4882a593Smuzhiyun * @buf: Pointer to header place (must be at least 2KB in size) 51*4882a593Smuzhiyun */ 52*4882a593Smuzhiyun void rkcommon_set_header(void *buf, struct stat *sbuf, int ifd, 53*4882a593Smuzhiyun struct image_tool_params *params); 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun /** 56*4882a593Smuzhiyun * rkcommon_verify_header() - verify the header for a Rockchip boot image 57*4882a593Smuzhiyun * 58*4882a593Smuzhiyun * @buf: Pointer to the image file 59*4882a593Smuzhiyun * @file_size: Size of entire bootable image file (incl. all padding) 60*4882a593Smuzhiyun * @return 0 if OK 61*4882a593Smuzhiyun */ 62*4882a593Smuzhiyun int rkcommon_verify_header(unsigned char *buf, int size, 63*4882a593Smuzhiyun struct image_tool_params *params); 64*4882a593Smuzhiyun 65*4882a593Smuzhiyun /** 66*4882a593Smuzhiyun * rkcommon_print_header() - print the header for a Rockchip boot image 67*4882a593Smuzhiyun * 68*4882a593Smuzhiyun * This prints the header, spl_name and whether this is a SD/MMC or SPI image. 69*4882a593Smuzhiyun * 70*4882a593Smuzhiyun * @buf: Pointer to the image (can be a read-only file-mapping) 71*4882a593Smuzhiyun */ 72*4882a593Smuzhiyun void rkcommon_print_header(const void *buf); 73*4882a593Smuzhiyun 74*4882a593Smuzhiyun /** 75*4882a593Smuzhiyun * rkcommon_need_rc4_spl() - check if rc4 encoded spl is required 76*4882a593Smuzhiyun * 77*4882a593Smuzhiyun * Some socs cannot disable the rc4-encryption of the spl binary. 78*4882a593Smuzhiyun * rc4 encryption is disabled normally except on socs that cannot 79*4882a593Smuzhiyun * handle unencrypted binaries. 80*4882a593Smuzhiyun * @return true or false depending on rc4 being required. 81*4882a593Smuzhiyun */ 82*4882a593Smuzhiyun bool rkcommon_need_rc4_spl(struct image_tool_params *params); 83*4882a593Smuzhiyun 84*4882a593Smuzhiyun /** 85*4882a593Smuzhiyun * rkcommon_rc4_encode_spl() - encode the spl binary 86*4882a593Smuzhiyun * 87*4882a593Smuzhiyun * Encrypts the SPL binary using the generic rc4 key as required 88*4882a593Smuzhiyun * by some socs. 89*4882a593Smuzhiyun * 90*4882a593Smuzhiyun * @buf: Pointer to the SPL data (header and SPL binary) 91*4882a593Smuzhiyun * @offset: offset inside buf to start at 92*4882a593Smuzhiyun * @size: number of bytes to encode 93*4882a593Smuzhiyun */ 94*4882a593Smuzhiyun void rkcommon_rc4_encode_spl(void *buf, unsigned int offset, unsigned int size); 95*4882a593Smuzhiyun 96*4882a593Smuzhiyun /** 97*4882a593Smuzhiyun * rkcommon_vrec_header() - allocate memory for the header 98*4882a593Smuzhiyun * 99*4882a593Smuzhiyun * @params: Pointer to the tool params structure 100*4882a593Smuzhiyun * @tparams: Pointer tot the image type structure (for setting 101*4882a593Smuzhiyun * the header and header_size) 102*4882a593Smuzhiyun * 103*4882a593Smuzhiyun * @return 0 (always) 104*4882a593Smuzhiyun */ 105*4882a593Smuzhiyun int rkcommon_vrec_header(struct image_tool_params *params, 106*4882a593Smuzhiyun struct image_type_params *tparams); 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun #endif 109