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_INIT_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 RK_SPL_START = RK_SPL_HDR_START + RK_SPL_HDR_SIZE, 19 RK_IMAGE_HEADER_LEN = RK_SPL_START, 20 }; 21 22 /** 23 * rkcommon_check_params() - check params 24 * 25 * @return 0 if OK, -1 if ERROR. 26 */ 27 int rkcommon_check_params(struct image_tool_params *params); 28 29 /** 30 * rkcommon_get_spl_hdr() - get 4-bytes spl hdr for a Rockchip boot image 31 * 32 * Rockchip's bootrom requires the spl loader to start with a 4-bytes 33 * header. The content of this header depends on the chip type. 34 */ 35 const char *rkcommon_get_spl_hdr(struct image_tool_params *params); 36 37 /** 38 * rkcommon_get_spl_size() - get spl size for a Rockchip boot image 39 * 40 * Different chip may have different sram size. And if we want to jump 41 * back to the bootrom after spl, we may need to reserve some sram space 42 * for the bootrom. 43 * The spl loader size should be sram size minus reserved size(if needed) 44 */ 45 int rkcommon_get_spl_size(struct image_tool_params *params); 46 47 /** 48 * rkcommon_spl_is_boot0() - is magic included in spl 49 * 50 * Returns true if magic (for example RK30) is included in spl 51 */ 52 53 bool rkcommon_spl_is_boot0(struct image_tool_params *params); 54 55 /** 56 * rkcommon_set_header() - set up the header for a Rockchip boot image 57 * 58 * This sets up a 2KB header which can be interpreted by the Rockchip boot ROM. 59 * 60 * @buf: Pointer to header place (must be at least 2KB in size) 61 * @file_size: Size of the file we want the boot ROM to load, in bytes 62 * @return 0 if OK, -ENOSPC if too large 63 */ 64 int rkcommon_set_header(void *buf, uint file_size, uint max_size, 65 struct image_tool_params *params); 66 67 /** 68 * rkcommon_verify_header() - verify the header for a Rockchip boot image 69 * 70 * @buf: Pointer to the image file 71 * @file_size: Size of entire bootable image file (incl. all padding) 72 * @return 0 if OK 73 */ 74 int rkcommon_verify_header(unsigned char *buf, int size, 75 struct image_tool_params *params); 76 77 /** 78 * rkcommon_print_header() - print the header for a Rockchip boot image 79 * 80 * This prints the header, spl_name and whether this is a SD/MMC or SPI image. 81 * 82 * @buf: Pointer to the image (can be a read-only file-mapping) 83 */ 84 void rkcommon_print_header(const void *buf); 85 86 /** 87 * rkcommon_need_rc4_spl() - check if rc4 encoded spl is required 88 * 89 * Some socs cannot disable the rc4-encryption of the spl binary. 90 * rc4 encryption is disabled normally except on socs that cannot 91 * handle unencrypted binaries. 92 * @return true or false depending on rc4 being required. 93 */ 94 bool rkcommon_need_rc4_spl(struct image_tool_params *params); 95 96 /** 97 * rkcommon_rc4_encode_spl() - encode the spl binary 98 * 99 * Encrypts the SPL binary using the generic rc4 key as required 100 * by some socs. 101 * 102 * @buf: Pointer to the SPL data (header and SPL binary) 103 * @offset: offset inside buf to start at 104 * @size: number of bytes to encode 105 */ 106 void rkcommon_rc4_encode_spl(void *buf, unsigned int offset, unsigned int size); 107 108 /** 109 * rkcommon_vrec_header() - allocate memory for the header 110 * 111 * @params: Pointer to the tool params structure 112 * @tparams: Pointer tot the image type structure (for setting 113 * the header and header_size) 114 * @alignment: Alignment (a power of two) that the image should be 115 * padded to (e.g. 512 if we want to align with SD/MMC 116 * blocksizes or 2048 for the SPI format) 117 * 118 * @return bytes of padding required/added (does not include the header_size) 119 */ 120 int rkcommon_vrec_header(struct image_tool_params *params, 121 struct image_type_params *tparams, 122 unsigned int alignment); 123 124 #endif 125