1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
6 * See README.rockchip for details of the rkspi format
16 RKSPI_SECT_LEN = RK_BLK_SIZE * 4,
19 static void rkspi_set_header(void *buf, struct stat *sbuf, int ifd,
20 struct image_tool_params *params)
25 size = params->orig_file_size;
27 rkcommon_set_header(buf, sbuf, ifd, params);
30 * Spread the image out so we only use the first 2KB of each 4KB
31 * region. This is a feature of the SPI format required by the Rockchip
32 * boot ROM. Its rationale is unknown.
35 fprintf(stderr, "Spreading spi image from %u to %u\n",
36 size, params->file_size);
38 for (sector = size / RKSPI_SECT_LEN - 1; sector >= 0; sector--) {
39 debug("sector %u\n", sector);
40 memmove(buf + sector * RKSPI_SECT_LEN * 2,
41 buf + sector * RKSPI_SECT_LEN,
43 memset(buf + sector * RKSPI_SECT_LEN * 2 + RKSPI_SECT_LEN,
44 '\0', RKSPI_SECT_LEN);
48 static int rkspi_check_image_type(uint8_t type)
50 if (type == IH_TYPE_RKSPI)
57 * The SPI payload needs to make space for odd half-sector layout used in flash
58 * (i.e. only the first 2K of each 4K sector is used).
60 static int rkspi_vrec_header(struct image_tool_params *params,
61 struct image_type_params *tparams)
63 rkcommon_vrec_header(params, tparams);
66 * Converting to the SPI format (i.e. splitting each 4K page into two
67 * 2K subpages and then padding these 2K pages up to take a complete
68 * 4K sector again) which will double the image size.
70 params->file_size = ROUND(params->file_size, RKSPI_SECT_LEN) << 1;
72 /* Ignoring pad len, since we are using our own copy_image() */
81 "Rockchip SPI Boot Image support",
84 rkcommon_check_params,
85 rkcommon_verify_header,
86 rkcommon_print_header,
89 rkspi_check_image_type,