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