xref: /openbmc/u-boot/tools/rkimage.c (revision 14573fb7)
183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2a131c1f4SSimon Glass /*
3a131c1f4SSimon Glass  * (C) Copyright 2015 Google, Inc
4a131c1f4SSimon Glass  * Written by Simon Glass <sjg@chromium.org>
5a131c1f4SSimon Glass  *
6a131c1f4SSimon Glass  * See README.rockchip for details of the rkimage format
7a131c1f4SSimon Glass  */
8a131c1f4SSimon Glass 
9a131c1f4SSimon Glass #include "imagetool.h"
10a131c1f4SSimon Glass #include <image.h>
117bf274b9SJeffy Chen #include "rkcommon.h"
12a131c1f4SSimon Glass 
13a131c1f4SSimon Glass static uint32_t header;
14a131c1f4SSimon Glass 
rkimage_set_header(void * buf,struct stat * sbuf,int ifd,struct image_tool_params * params)15a131c1f4SSimon Glass static void rkimage_set_header(void *buf, struct stat *sbuf, int ifd,
16a131c1f4SSimon Glass 			       struct image_tool_params *params)
17a131c1f4SSimon Glass {
18*f25c1755SDaniel Gröber 	memcpy(buf, rkcommon_get_spl_hdr(params), RK_SPL_HDR_SIZE);
19cfbcdadeSHeiko Stübner 
20cfbcdadeSHeiko Stübner 	if (rkcommon_need_rc4_spl(params))
21cfbcdadeSHeiko Stübner 		rkcommon_rc4_encode_spl(buf, 4, params->file_size);
22a131c1f4SSimon Glass }
23a131c1f4SSimon Glass 
rkimage_check_image_type(uint8_t type)24a131c1f4SSimon Glass static int rkimage_check_image_type(uint8_t type)
25a131c1f4SSimon Glass {
26a131c1f4SSimon Glass 	if (type == IH_TYPE_RKIMAGE)
27a131c1f4SSimon Glass 		return EXIT_SUCCESS;
28a131c1f4SSimon Glass 	else
29a131c1f4SSimon Glass 		return EXIT_FAILURE;
30a131c1f4SSimon Glass }
31a131c1f4SSimon Glass 
32a131c1f4SSimon Glass /*
33a131c1f4SSimon Glass  * rk_image parameters
34a131c1f4SSimon Glass  */
35a131c1f4SSimon Glass U_BOOT_IMAGE_TYPE(
36a131c1f4SSimon Glass 	rkimage,
37a131c1f4SSimon Glass 	"Rockchip Boot Image support",
38*f25c1755SDaniel Gröber 	0,
39a131c1f4SSimon Glass 	&header,
409217d93bSSimon Glass 	rkcommon_check_params,
41253c60a5SPhilipp Tomsich 	NULL,
42253c60a5SPhilipp Tomsich 	NULL,
43a131c1f4SSimon Glass 	rkimage_set_header,
44253c60a5SPhilipp Tomsich 	NULL,
45a131c1f4SSimon Glass 	rkimage_check_image_type,
46a131c1f4SSimon Glass 	NULL,
47a131c1f4SSimon Glass 	NULL
48a131c1f4SSimon Glass );
49