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