blob: f660d562a8ee5e466cc2fd3808c5a61eeebe0d8b [file] [log] [blame]
Simon Glassf9a3c272015-08-30 16:55:25 -06001/*
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
16enum {
Jeffy Chen36413392015-11-17 14:20:30 +080017 RKSD_SPL_HDR_START = RK_INIT_OFFSET * RK_BLK_SIZE,
Simon Glassf9a3c272015-08-30 16:55:25 -060018 RKSD_SPL_START = RKSD_SPL_HDR_START + 4,
19 RKSD_HEADER_LEN = RKSD_SPL_START,
20};
21
22static char dummy_hdr[RKSD_HEADER_LEN];
23
24static int rksd_check_params(struct image_tool_params *params)
25{
26 return 0;
27}
28
29static int rksd_verify_header(unsigned char *buf, int size,
30 struct image_tool_params *params)
31{
32 return 0;
33}
34
35static void rksd_print_header(const void *buf)
36{
37}
38
39static 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
Simon Glassf9a3c272015-08-30 16:55:25 -060045 size = params->file_size - RKSD_SPL_HDR_START;
Sjoerd Simonsdd39bca2015-08-30 16:55:50 -060046 ret = rkcommon_set_header(buf, size);
Simon Glassf9a3c272015-08-30 16:55:25 -060047 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
Jeffy Chen6ae58602015-11-17 14:20:29 +080053 memcpy(buf + RKSD_SPL_HDR_START, CONFIG_ROCKCHIP_SPL_HDR, 4);
Simon Glassf9a3c272015-08-30 16:55:25 -060054}
55
56static int rksd_extract_subimage(void *buf, struct image_tool_params *params)
57{
58 return 0;
59}
60
61static 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 */
70static int rksd_vrec_header(struct image_tool_params *params,
71 struct image_type_params *tparams)
72{
73 int pad_size;
74
Jeffy Chen6ae58602015-11-17 14:20:29 +080075 pad_size = RKSD_SPL_HDR_START + CONFIG_ROCKCHIP_MAX_SPL_SIZE;
Simon Glassf9a3c272015-08-30 16:55:25 -060076 debug("pad_size %x\n", pad_size);
77
78 return pad_size - params->file_size;
79}
80
81/*
82 * rk_sd parameters
83 */
84U_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);