Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | f9a3c27 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2015 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
| 5 | * |
Simon Glass | f9a3c27 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 6 | * 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 Glass | f9a3c27 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 15 | static void rksd_set_header(void *buf, struct stat *sbuf, int ifd, |
Philipp Tomsich | 2fb371f | 2017-05-30 23:32:08 +0200 | [diff] [blame] | 16 | struct image_tool_params *params) |
Simon Glass | f9a3c27 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 17 | { |
| 18 | unsigned int size; |
| 19 | int ret; |
| 20 | |
Philipp Tomsich | 366aad4 | 2017-04-17 17:48:01 +0200 | [diff] [blame] | 21 | /* |
| 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 Tomsich | 2fb371f | 2017-05-30 23:32:08 +0200 | [diff] [blame] | 24 | * 'is_boot0' is true counts towards the payload (and not towards the |
| 25 | * header). |
Philipp Tomsich | 366aad4 | 2017-04-17 17:48:01 +0200 | [diff] [blame] | 26 | */ |
Jeffy Chen | 7bf274b | 2015-11-27 12:07:17 +0800 | [diff] [blame] | 27 | size = params->file_size - RK_SPL_HDR_START; |
| 28 | ret = rkcommon_set_header(buf, size, params); |
Simon Glass | f9a3c27 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 29 | if (ret) { |
| 30 | /* TODO(sjg@chromium.org): This method should return an error */ |
Philipp Tomsich | 366aad4 | 2017-04-17 17:48:01 +0200 | [diff] [blame] | 31 | printf("Warning: SPL image is too large (size %#x) and will " |
| 32 | "not boot\n", size); |
Simon Glass | f9a3c27 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 33 | } |
Simon Glass | f9a3c27 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 34 | } |
| 35 | |
Simon Glass | f9a3c27 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 36 | static 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 Glass | f9a3c27 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 44 | static int rksd_vrec_header(struct image_tool_params *params, |
| 45 | struct image_type_params *tparams) |
| 46 | { |
Philipp Tomsich | c25b8c3 | 2017-04-17 17:48:03 +0200 | [diff] [blame] | 47 | /* |
Philipp Tomsich | ad972ac | 2017-05-30 23:32:09 +0200 | [diff] [blame] | 48 | * 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 Tomsich | c25b8c3 | 2017-04-17 17:48:03 +0200 | [diff] [blame] | 50 | */ |
Philipp Tomsich | ad972ac | 2017-05-30 23:32:09 +0200 | [diff] [blame] | 51 | return rkcommon_vrec_header(params, tparams, RK_INIT_SIZE_ALIGN); |
Simon Glass | f9a3c27 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /* |
| 55 | * rk_sd parameters |
| 56 | */ |
| 57 | U_BOOT_IMAGE_TYPE( |
| 58 | rksd, |
| 59 | "Rockchip SD Boot Image support", |
Philipp Tomsich | 111bcc4 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 60 | 0, |
| 61 | NULL, |
Jeffy Chen | 7bf274b | 2015-11-27 12:07:17 +0800 | [diff] [blame] | 62 | rkcommon_check_params, |
Philipp Tomsich | 2fb371f | 2017-05-30 23:32:08 +0200 | [diff] [blame] | 63 | rkcommon_verify_header, |
| 64 | rkcommon_print_header, |
Simon Glass | f9a3c27 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 65 | rksd_set_header, |
Philipp Tomsich | 2fb371f | 2017-05-30 23:32:08 +0200 | [diff] [blame] | 66 | NULL, |
Simon Glass | f9a3c27 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 67 | rksd_check_image_type, |
| 68 | NULL, |
| 69 | rksd_vrec_header |
| 70 | ); |