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