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_SPL_HDR_START = RK_INIT_OFFSET * RK_BLK_SIZE,
18 RKSPI_SPL_START = RKSPI_SPL_HDR_START + 4,
19 RKSPI_HEADER_LEN = RKSPI_SPL_START,
20 RKSPI_SECT_LEN = RK_BLK_SIZE * 4,
23 static char dummy_hdr[RKSPI_HEADER_LEN];
25 static int rkspi_check_params(struct image_tool_params *params)
30 static int rkspi_verify_header(unsigned char *buf, int size,
31 struct image_tool_params *params)
36 static void rkspi_print_header(const void *buf)
40 static void rkspi_set_header(void *buf, struct stat *sbuf, int ifd,
41 struct image_tool_params *params)
47 size = params->orig_file_size;
48 ret = rkcommon_set_header(buf, size);
49 debug("size %x\n", size);
51 /* TODO(sjg@chromium.org): This method should return an error */
52 printf("Warning: SPL image is too large (size %#x) and will not boot\n",
56 memcpy(buf + RKSPI_SPL_HDR_START, "RK32", 4);
59 * Spread the image out so we only use the first 2KB of each 4KB
60 * region. This is a feature of the SPI format required by the Rockchip
61 * boot ROM. Its rationale is unknown.
63 for (sector = size / RKSPI_SECT_LEN - 1; sector >= 0; sector--) {
64 printf("sector %u\n", sector);
65 memmove(buf + sector * RKSPI_SECT_LEN * 2,
66 buf + sector * RKSPI_SECT_LEN,
68 memset(buf + sector * RKSPI_SECT_LEN * 2 + RKSPI_SECT_LEN,
69 '\0', RKSPI_SECT_LEN);
73 static int rkspi_extract_subimage(void *buf, struct image_tool_params *params)
78 static int rkspi_check_image_type(uint8_t type)
80 if (type == IH_TYPE_RKSPI)
86 /* We pad the file out to a fixed size - this method returns that size */
87 static int rkspi_vrec_header(struct image_tool_params *params,
88 struct image_type_params *tparams)
92 pad_size = (RK_MAX_CODE1_SIZE + 0x7ff) / 0x800 * 0x800;
93 params->orig_file_size = pad_size;
95 /* We will double the image size due to the SPI format */
97 pad_size += RKSPI_SPL_HDR_START;
98 debug("pad_size %x\n", pad_size);
100 return pad_size - params->file_size;
108 "Rockchip SPI Boot Image support",
115 rkspi_extract_subimage,
116 rkspi_check_image_type,