blob: 24411d863a0aa7ec161bf12d19d1d0374567f344 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass3b1e5072015-08-30 16:55:25 -06002/*
3 * (C) Copyright 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
5 *
Simon Glass3b1e5072015-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 Glass3b1e5072015-08-30 16:55:25 -060015static void rksd_set_header(void *buf, struct stat *sbuf, int ifd,
Philipp Tomsichf0d09fb2017-05-30 23:32:08 +020016 struct image_tool_params *params)
Simon Glass3b1e5072015-08-30 16:55:25 -060017{
18 unsigned int size;
19 int ret;
20
Philipp Tomsichd2eaf412017-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 Tomsichf0d09fb2017-05-30 23:32:08 +020024 * 'is_boot0' is true counts towards the payload (and not towards the
25 * header).
Philipp Tomsichd2eaf412017-04-17 17:48:01 +020026 */
Jeffy Chen06cdc342015-11-27 12:07:17 +080027 size = params->file_size - RK_SPL_HDR_START;
28 ret = rkcommon_set_header(buf, size, params);
Simon Glass3b1e5072015-08-30 16:55:25 -060029 if (ret) {
30 /* TODO(sjg@chromium.org): This method should return an error */
Philipp Tomsichd2eaf412017-04-17 17:48:01 +020031 printf("Warning: SPL image is too large (size %#x) and will "
32 "not boot\n", size);
Simon Glass3b1e5072015-08-30 16:55:25 -060033 }
Simon Glass3b1e5072015-08-30 16:55:25 -060034}
35
Simon Glass3b1e5072015-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 Glass3b1e5072015-08-30 16:55:25 -060044static int rksd_vrec_header(struct image_tool_params *params,
45 struct image_type_params *tparams)
46{
Philipp Tomsich0e28d032017-04-17 17:48:03 +020047 /*
Philipp Tomsiche3b84dd2017-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 Tomsich0e28d032017-04-17 17:48:03 +020050 */
Philipp Tomsiche3b84dd2017-05-30 23:32:09 +020051 return rkcommon_vrec_header(params, tparams, RK_INIT_SIZE_ALIGN);
Simon Glass3b1e5072015-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 Tomsich087ce822017-03-15 12:08:43 +010060 0,
61 NULL,
Jeffy Chen06cdc342015-11-27 12:07:17 +080062 rkcommon_check_params,
Philipp Tomsichf0d09fb2017-05-30 23:32:08 +020063 rkcommon_verify_header,
64 rkcommon_print_header,
Simon Glass3b1e5072015-08-30 16:55:25 -060065 rksd_set_header,
Philipp Tomsichf0d09fb2017-05-30 23:32:08 +020066 NULL,
Simon Glass3b1e5072015-08-30 16:55:25 -060067 rksd_check_image_type,
68 NULL,
69 rksd_vrec_header
70);