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)
26 size = params->orig_file_size;
27 ret = rkcommon_set_header(buf, size, params);
28 debug("size %x\n", size);
30 /* TODO(sjg@chromium.org): This method should return an error */
31 printf("Warning: SPL image is too large (size %#x) and will "
36 * Spread the image out so we only use the first 2KB of each 4KB
37 * region. This is a feature of the SPI format required by the Rockchip
38 * boot ROM. Its rationale is unknown.
40 for (sector = size / RKSPI_SECT_LEN - 1; sector >= 0; sector--) {
41 debug("sector %u\n", sector);
42 memmove(buf + sector * RKSPI_SECT_LEN * 2,
43 buf + sector * RKSPI_SECT_LEN,
45 memset(buf + sector * RKSPI_SECT_LEN * 2 + RKSPI_SECT_LEN,
46 '\0', RKSPI_SECT_LEN);
50 static int rkspi_check_image_type(uint8_t type)
52 if (type == IH_TYPE_RKSPI)
59 * The SPI payload needs to be padded out to make space for odd half-sector
60 * layout used in flash (i.e. only the first 2K of each 4K sector is used).
62 static int rkspi_vrec_header(struct image_tool_params *params,
63 struct image_type_params *tparams)
65 int padding = rkcommon_vrec_header(params, tparams, RK_INIT_SIZE_ALIGN);
67 * The file size has not been adjusted at this point (our caller will
68 * eventually add the header/padding to the file_size), so we need to
69 * add up the header_size, file_size and padding ourselves.
71 int padded_size = tparams->header_size + params->file_size + padding;
74 * We need to store the original file-size (i.e. before padding), as
75 * imagetool does not set this during its adjustment of file_size.
77 params->orig_file_size = padded_size;
80 * Converting to the SPI format (i.e. splitting each 4K page into two
81 * 2K subpages and then padding these 2K pages up to take a complete
82 * 4K sector again) will will double the image size.
84 * Thus we return the padded_size as an additional padding requirement
85 * (be sure to add this to the padding returned from the common code).
87 return padded_size + padding;
95 "Rockchip SPI Boot Image support",
98 rkcommon_check_params,
99 rkcommon_verify_header,
100 rkcommon_print_header,
103 rkspi_check_image_type,