blob: c56153d2ca607dddbeb9a5a8b6593b70b6717068 [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
Simon Glassf9a3c272015-08-30 16:55:25 -060016static void rksd_set_header(void *buf, struct stat *sbuf, int ifd,
Philipp Tomsich2fb371f2017-05-30 23:32:08 +020017 struct image_tool_params *params)
Simon Glassf9a3c272015-08-30 16:55:25 -060018{
19 unsigned int size;
20 int ret;
21
Philipp Tomsich366aad42017-04-17 17:48:01 +020022 /*
23 * We need to calculate this using 'RK_SPL_HDR_START' and not using
24 * 'tparams->header_size', as the additional byte inserted when
Philipp Tomsich2fb371f2017-05-30 23:32:08 +020025 * 'is_boot0' is true counts towards the payload (and not towards the
26 * header).
Philipp Tomsich366aad42017-04-17 17:48:01 +020027 */
Jeffy Chen7bf274b2015-11-27 12:07:17 +080028 size = params->file_size - RK_SPL_HDR_START;
29 ret = rkcommon_set_header(buf, size, params);
Simon Glassf9a3c272015-08-30 16:55:25 -060030 if (ret) {
31 /* TODO(sjg@chromium.org): This method should return an error */
Philipp Tomsich366aad42017-04-17 17:48:01 +020032 printf("Warning: SPL image is too large (size %#x) and will "
33 "not boot\n", size);
Simon Glassf9a3c272015-08-30 16:55:25 -060034 }
Simon Glassf9a3c272015-08-30 16:55:25 -060035}
36
Simon Glassf9a3c272015-08-30 16:55:25 -060037static int rksd_check_image_type(uint8_t type)
38{
39 if (type == IH_TYPE_RKSD)
40 return EXIT_SUCCESS;
41 else
42 return EXIT_FAILURE;
43}
44
Simon Glassf9a3c272015-08-30 16:55:25 -060045static int rksd_vrec_header(struct image_tool_params *params,
46 struct image_type_params *tparams)
47{
Philipp Tomsichc25b8c32017-04-17 17:48:03 +020048 /*
Philipp Tomsichad972ac2017-05-30 23:32:09 +020049 * Pad to a 2KB alignment, as required for init_size by the ROM
50 * (see https://lists.denx.de/pipermail/u-boot/2017-May/293268.html)
Philipp Tomsichc25b8c32017-04-17 17:48:03 +020051 */
Philipp Tomsichad972ac2017-05-30 23:32:09 +020052 return rkcommon_vrec_header(params, tparams, RK_INIT_SIZE_ALIGN);
Simon Glassf9a3c272015-08-30 16:55:25 -060053}
54
55/*
56 * rk_sd parameters
57 */
58U_BOOT_IMAGE_TYPE(
59 rksd,
60 "Rockchip SD Boot Image support",
Philipp Tomsich111bcc42017-03-15 12:08:43 +010061 0,
62 NULL,
Jeffy Chen7bf274b2015-11-27 12:07:17 +080063 rkcommon_check_params,
Philipp Tomsich2fb371f2017-05-30 23:32:08 +020064 rkcommon_verify_header,
65 rkcommon_print_header,
Simon Glassf9a3c272015-08-30 16:55:25 -060066 rksd_set_header,
Philipp Tomsich2fb371f2017-05-30 23:32:08 +020067 NULL,
Simon Glassf9a3c272015-08-30 16:55:25 -060068 rksd_check_image_type,
69 NULL,
70 rksd_vrec_header
71);