]>
git.ipfire.org Git - people/ms/u-boot.git/blob - tools/rkspi.c
2 * (C) Copyright 2015 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
5 * SPDX-License-Identifier: GPL-2.0+
7 * See README.rockchip for details of the rkspi format
10 #include "imagetool.h"
17 RKSPI_SECT_LEN
= RK_BLK_SIZE
* 4,
20 static char dummy_hdr
[RK_IMAGE_HEADER_LEN
];
22 static int rkspi_verify_header(unsigned char *buf
, int size
,
23 struct image_tool_params
*params
)
28 static void rkspi_print_header(const void *buf
)
32 static void rkspi_set_header(void *buf
, struct stat
*sbuf
, int ifd
,
33 struct image_tool_params
*params
)
39 size
= params
->orig_file_size
;
40 ret
= rkcommon_set_header(buf
, size
, params
);
41 debug("size %x\n", size
);
43 /* TODO(sjg@chromium.org): This method should return an error */
44 printf("Warning: SPL image is too large (size %#x) and will not boot\n",
48 memcpy(buf
+ RK_SPL_HDR_START
, rkcommon_get_spl_hdr(params
),
51 if (rkcommon_need_rc4_spl(params
))
52 rkcommon_rc4_encode_spl(buf
, RK_SPL_START
- 4,
53 params
->file_size
- RK_SPL_START
+ 4);
56 * Spread the image out so we only use the first 2KB of each 4KB
57 * region. This is a feature of the SPI format required by the Rockchip
58 * boot ROM. Its rationale is unknown.
60 for (sector
= size
/ RKSPI_SECT_LEN
- 1; sector
>= 0; sector
--) {
61 debug("sector %u\n", sector
);
62 memmove(buf
+ sector
* RKSPI_SECT_LEN
* 2,
63 buf
+ sector
* RKSPI_SECT_LEN
,
65 memset(buf
+ sector
* RKSPI_SECT_LEN
* 2 + RKSPI_SECT_LEN
,
66 '\0', RKSPI_SECT_LEN
);
70 static int rkspi_extract_subimage(void *buf
, struct image_tool_params
*params
)
75 static int rkspi_check_image_type(uint8_t type
)
77 if (type
== IH_TYPE_RKSPI
)
83 /* We pad the file out to a fixed size - this method returns that size */
84 static int rkspi_vrec_header(struct image_tool_params
*params
,
85 struct image_type_params
*tparams
)
89 pad_size
= (rkcommon_get_spl_size(params
) + 0x7ff) / 0x800 * 0x800;
90 params
->orig_file_size
= pad_size
;
92 /* We will double the image size due to the SPI format */
94 pad_size
+= RK_SPL_HDR_START
;
95 debug("pad_size %x\n", pad_size
);
97 return pad_size
- params
->file_size
;
105 "Rockchip SPI Boot Image support",
108 rkcommon_check_params
,
112 rkspi_extract_subimage
,
113 rkspi_check_image_type
,