Simon Glass | 3b1e507 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 1 | /* |
| 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 Glass | 3b1e507 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 16 | static int rksd_verify_header(unsigned char *buf, int size, |
| 17 | struct image_tool_params *params) |
| 18 | { |
| 19 | return 0; |
| 20 | } |
| 21 | |
| 22 | static void rksd_print_header(const void *buf) |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | static void rksd_set_header(void *buf, struct stat *sbuf, int ifd, |
| 27 | struct image_tool_params *params) |
| 28 | { |
| 29 | unsigned int size; |
| 30 | int ret; |
| 31 | |
Philipp Tomsich | d2eaf41 | 2017-04-17 17:48:01 +0200 | [diff] [blame] | 32 | printf("params->file_size %d\n", params->file_size); |
| 33 | printf("params->orig_file_size %d\n", params->orig_file_size); |
| 34 | |
| 35 | /* |
| 36 | * We need to calculate this using 'RK_SPL_HDR_START' and not using |
| 37 | * 'tparams->header_size', as the additional byte inserted when |
| 38 | * 'is_boot0' is true counts towards the payload. |
| 39 | */ |
Jeffy Chen | 06cdc34 | 2015-11-27 12:07:17 +0800 | [diff] [blame] | 40 | size = params->file_size - RK_SPL_HDR_START; |
| 41 | ret = rkcommon_set_header(buf, size, params); |
Simon Glass | 3b1e507 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 42 | if (ret) { |
| 43 | /* TODO(sjg@chromium.org): This method should return an error */ |
Philipp Tomsich | d2eaf41 | 2017-04-17 17:48:01 +0200 | [diff] [blame] | 44 | printf("Warning: SPL image is too large (size %#x) and will " |
| 45 | "not boot\n", size); |
Simon Glass | 3b1e507 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 46 | } |
Simon Glass | 3b1e507 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | static int rksd_extract_subimage(void *buf, struct image_tool_params *params) |
| 50 | { |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | static int rksd_check_image_type(uint8_t type) |
| 55 | { |
| 56 | if (type == IH_TYPE_RKSD) |
| 57 | return EXIT_SUCCESS; |
| 58 | else |
| 59 | return EXIT_FAILURE; |
| 60 | } |
| 61 | |
Simon Glass | 3b1e507 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 62 | static int rksd_vrec_header(struct image_tool_params *params, |
| 63 | struct image_type_params *tparams) |
| 64 | { |
Philipp Tomsich | 0e28d03 | 2017-04-17 17:48:03 +0200 | [diff] [blame] | 65 | /* |
| 66 | * Pad to the RK_BLK_SIZE (512 bytes) to be consistent with init_size |
| 67 | * being encoded in RK_BLK_SIZE units in header0 (see rkcommon.c). |
| 68 | */ |
| 69 | return rkcommon_vrec_header(params, tparams, RK_BLK_SIZE); |
Simon Glass | 3b1e507 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /* |
| 73 | * rk_sd parameters |
| 74 | */ |
| 75 | U_BOOT_IMAGE_TYPE( |
| 76 | rksd, |
| 77 | "Rockchip SD Boot Image support", |
Philipp Tomsich | 087ce82 | 2017-03-15 12:08:43 +0100 | [diff] [blame] | 78 | 0, |
| 79 | NULL, |
Jeffy Chen | 06cdc34 | 2015-11-27 12:07:17 +0800 | [diff] [blame] | 80 | rkcommon_check_params, |
Simon Glass | 3b1e507 | 2015-08-30 16:55:25 -0600 | [diff] [blame] | 81 | rksd_verify_header, |
| 82 | rksd_print_header, |
| 83 | rksd_set_header, |
| 84 | rksd_extract_subimage, |
| 85 | rksd_check_image_type, |
| 86 | NULL, |
| 87 | rksd_vrec_header |
| 88 | ); |