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 * See README.rockchip for details of the rksd format 8 */ 9 10 #include "imagetool.h" 11 #include <image.h> 12 #include <rc4.h> 13 #include "mkimage.h" 14 #include "rkcommon.h" 15 16 enum { 17 RKSD_HEADER0_START = 64 * RK_BLK_SIZE, 18 RKSD_SPL_HDR_START = RKSD_HEADER0_START + 19 RK_CODE1_OFFSET * RK_BLK_SIZE, 20 RKSD_SPL_START = RKSD_SPL_HDR_START + 4, 21 RKSD_HEADER_LEN = RKSD_SPL_START, 22 }; 23 24 static char dummy_hdr[RKSD_HEADER_LEN]; 25 26 static int rksd_check_params(struct image_tool_params *params) 27 { 28 return 0; 29 } 30 31 static int rksd_verify_header(unsigned char *buf, int size, 32 struct image_tool_params *params) 33 { 34 return 0; 35 } 36 37 static void rksd_print_header(const void *buf) 38 { 39 } 40 41 static void rksd_set_header(void *buf, struct stat *sbuf, int ifd, 42 struct image_tool_params *params) 43 { 44 unsigned int size; 45 int ret; 46 47 /* Zero the whole header. The first 32KB is empty */ 48 memset(buf, '\0', RKSD_HEADER0_START); 49 50 size = params->file_size - RKSD_SPL_HDR_START; 51 ret = rkcommon_set_header(buf + RKSD_HEADER0_START, size); 52 if (ret) { 53 /* TODO(sjg@chromium.org): This method should return an error */ 54 printf("Warning: SPL image is too large (size %#x) and will not boot\n", 55 size); 56 } 57 58 memcpy(buf + RKSD_SPL_HDR_START, "RK32", 4); 59 } 60 61 static int rksd_extract_subimage(void *buf, struct image_tool_params *params) 62 { 63 return 0; 64 } 65 66 static int rksd_check_image_type(uint8_t type) 67 { 68 if (type == IH_TYPE_RKSD) 69 return EXIT_SUCCESS; 70 else 71 return EXIT_FAILURE; 72 } 73 74 /* We pad the file out to a fixed size - this method returns that size */ 75 static int rksd_vrec_header(struct image_tool_params *params, 76 struct image_type_params *tparams) 77 { 78 int pad_size; 79 80 pad_size = RKSD_SPL_HDR_START + RK_MAX_CODE1_SIZE; 81 debug("pad_size %x\n", pad_size); 82 83 return pad_size - params->file_size; 84 } 85 86 /* 87 * rk_sd parameters 88 */ 89 U_BOOT_IMAGE_TYPE( 90 rksd, 91 "Rockchip SD Boot Image support", 92 RKSD_HEADER_LEN, 93 dummy_hdr, 94 rksd_check_params, 95 rksd_verify_header, 96 rksd_print_header, 97 rksd_set_header, 98 rksd_extract_subimage, 99 rksd_check_image_type, 100 NULL, 101 rksd_vrec_header 102 ); 103