blob: 24411d863a0aa7ec161bf12d19d1d0374567f344 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassf9a3c272015-08-30 16:55:25 -06002/*
3 * (C) Copyright 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
5 *
Simon Glassf9a3c272015-08-30 16:55:25 -06006 * See README.rockchip for details of the rksd format
7 */
8
9#include "imagetool.h"
10#include <image.h>
11#include <rc4.h>
12#include "mkimage.h"
13#include "rkcommon.h"
14
Simon Glassf9a3c272015-08-30 16:55:25 -060015static void rksd_set_header(void *buf, struct stat *sbuf, int ifd,
Philipp Tomsich2fb371f2017-05-30 23:32:08 +020016 struct image_tool_params *params)
Simon Glassf9a3c272015-08-30 16:55:25 -060017{
18 unsigned int size;
19 int ret;
20
Philipp Tomsich366aad42017-04-17 17:48:01 +020021 /*
22 * We need to calculate this using 'RK_SPL_HDR_START' and not using
23 * 'tparams->header_size', as the additional byte inserted when
Philipp Tomsich2fb371f2017-05-30 23:32:08 +020024 * 'is_boot0' is true counts towards the payload (and not towards the
25 * header).
Philipp Tomsich366aad42017-04-17 17:48:01 +020026 */
Jeffy Chen7bf274b2015-11-27 12:07:17 +080027 size = params->file_size - RK_SPL_HDR_START;
28 ret = rkcommon_set_header(buf, size, params);
Simon Glassf9a3c272015-08-30 16:55:25 -060029 if (ret) {
30 /* TODO(sjg@chromium.org): This method should return an error */
Philipp Tomsich366aad42017-04-17 17:48:01 +020031 printf("Warning: SPL image is too large (size %#x) and will "
32 "not boot\n", size);
Simon Glassf9a3c272015-08-30 16:55:25 -060033 }
Simon Glassf9a3c272015-08-30 16:55:25 -060034}
35
Simon Glassf9a3c272015-08-30 16:55:25 -060036static int rksd_check_image_type(uint8_t type)
37{
38 if (type == IH_TYPE_RKSD)
39 return EXIT_SUCCESS;
40 else
41 return EXIT_FAILURE;
42}
43
Simon Glassf9a3c272015-08-30 16:55:25 -060044static int rksd_vrec_header(struct image_tool_params *params,
45 struct image_type_params *tparams)
46{
Philipp Tomsichc25b8c32017-04-17 17:48:03 +020047 /*
Philipp Tomsichad972ac2017-05-30 23:32:09 +020048 * Pad to a 2KB alignment, as required for init_size by the ROM
49 * (see https://lists.denx.de/pipermail/u-boot/2017-May/293268.html)
Philipp Tomsichc25b8c32017-04-17 17:48:03 +020050 */
Philipp Tomsichad972ac2017-05-30 23:32:09 +020051 return rkcommon_vrec_header(params, tparams, RK_INIT_SIZE_ALIGN);
Simon Glassf9a3c272015-08-30 16:55:25 -060052}
53
54/*
55 * rk_sd parameters
56 */
57U_BOOT_IMAGE_TYPE(
58 rksd,
59 "Rockchip SD Boot Image support",
Philipp Tomsich111bcc42017-03-15 12:08:43 +010060 0,
61 NULL,
Jeffy Chen7bf274b2015-11-27 12:07:17 +080062 rkcommon_check_params,
Philipp Tomsich2fb371f2017-05-30 23:32:08 +020063 rkcommon_verify_header,
64 rkcommon_print_header,
Simon Glassf9a3c272015-08-30 16:55:25 -060065 rksd_set_header,
Philipp Tomsich2fb371f2017-05-30 23:32:08 +020066 NULL,
Simon Glassf9a3c272015-08-30 16:55:25 -060067 rksd_check_image_type,
68 NULL,
69 rksd_vrec_header
70);