xref: /openbmc/u-boot/tools/rkimage.c (revision 83d290c5)
1*83d290c5STom 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 
15a131c1f4SSimon Glass static void rkimage_set_header(void *buf, struct stat *sbuf, int ifd,
16a131c1f4SSimon Glass 			       struct image_tool_params *params)
17a131c1f4SSimon Glass {
187bf274b9SJeffy Chen 	memcpy(buf + RK_SPL_HDR_START, rkcommon_get_spl_hdr(params),
197bf274b9SJeffy Chen 	       RK_SPL_HDR_SIZE);
20cfbcdadeSHeiko Stübner 
21cfbcdadeSHeiko Stübner 	if (rkcommon_need_rc4_spl(params))
22cfbcdadeSHeiko Stübner 		rkcommon_rc4_encode_spl(buf, 4, params->file_size);
23a131c1f4SSimon Glass }
24a131c1f4SSimon Glass 
25a131c1f4SSimon Glass static int rkimage_check_image_type(uint8_t type)
26a131c1f4SSimon Glass {
27a131c1f4SSimon Glass 	if (type == IH_TYPE_RKIMAGE)
28a131c1f4SSimon Glass 		return EXIT_SUCCESS;
29a131c1f4SSimon Glass 	else
30a131c1f4SSimon Glass 		return EXIT_FAILURE;
31a131c1f4SSimon Glass }
32a131c1f4SSimon Glass 
33a131c1f4SSimon Glass /*
34a131c1f4SSimon Glass  * rk_image parameters
35a131c1f4SSimon Glass  */
36a131c1f4SSimon Glass U_BOOT_IMAGE_TYPE(
37a131c1f4SSimon Glass 	rkimage,
38a131c1f4SSimon Glass 	"Rockchip Boot Image support",
39a131c1f4SSimon Glass 	4,
40a131c1f4SSimon Glass 	&header,
419217d93bSSimon Glass 	rkcommon_check_params,
42253c60a5SPhilipp Tomsich 	NULL,
43253c60a5SPhilipp Tomsich 	NULL,
44a131c1f4SSimon Glass 	rkimage_set_header,
45253c60a5SPhilipp Tomsich 	NULL,
46a131c1f4SSimon Glass 	rkimage_check_image_type,
47a131c1f4SSimon Glass 	NULL,
48a131c1f4SSimon Glass 	NULL
49a131c1f4SSimon Glass );
50