]>
Commit | Line | Data |
---|---|---|
10b84fe1 SG |
1 | /* |
2 | * (C) Copyright 2015 Google, Inc | |
3 | * Written by Simon Glass <[email protected]> | |
4 | * | |
5 | * SPDX-License-Identifier: GPL-2.0+ | |
6 | * | |
7 | * See README.rockchip for details of the rkspi format | |
8 | */ | |
9 | ||
10 | #include "imagetool.h" | |
11 | #include <image.h> | |
12 | #include <rc4.h> | |
13 | #include "mkimage.h" | |
14 | #include "rkcommon.h" | |
15 | ||
16 | enum { | |
10b84fe1 SG |
17 | RKSPI_SECT_LEN = RK_BLK_SIZE * 4, |
18 | }; | |
19 | ||
7bf274b9 | 20 | static char dummy_hdr[RK_IMAGE_HEADER_LEN]; |
10b84fe1 SG |
21 | |
22 | static int rkspi_verify_header(unsigned char *buf, int size, | |
23 | struct image_tool_params *params) | |
24 | { | |
25 | return 0; | |
26 | } | |
27 | ||
28 | static void rkspi_print_header(const void *buf) | |
29 | { | |
30 | } | |
31 | ||
32 | static void rkspi_set_header(void *buf, struct stat *sbuf, int ifd, | |
33 | struct image_tool_params *params) | |
34 | { | |
35 | int sector; | |
36 | unsigned int size; | |
37 | int ret; | |
38 | ||
39 | size = params->orig_file_size; | |
7bf274b9 | 40 | ret = rkcommon_set_header(buf, size, params); |
10b84fe1 SG |
41 | debug("size %x\n", size); |
42 | if (ret) { | |
43 | /* TODO([email protected]): This method should return an error */ | |
44 | printf("Warning: SPL image is too large (size %#x) and will not boot\n", | |
45 | size); | |
46 | } | |
47 | ||
7bf274b9 JC |
48 | memcpy(buf + RK_SPL_HDR_START, rkcommon_get_spl_hdr(params), |
49 | RK_SPL_HDR_SIZE); | |
10b84fe1 SG |
50 | |
51 | /* | |
52 | * Spread the image out so we only use the first 2KB of each 4KB | |
53 | * region. This is a feature of the SPI format required by the Rockchip | |
54 | * boot ROM. Its rationale is unknown. | |
55 | */ | |
56 | for (sector = size / RKSPI_SECT_LEN - 1; sector >= 0; sector--) { | |
25525ebe | 57 | debug("sector %u\n", sector); |
10b84fe1 SG |
58 | memmove(buf + sector * RKSPI_SECT_LEN * 2, |
59 | buf + sector * RKSPI_SECT_LEN, | |
60 | RKSPI_SECT_LEN); | |
61 | memset(buf + sector * RKSPI_SECT_LEN * 2 + RKSPI_SECT_LEN, | |
62 | '\0', RKSPI_SECT_LEN); | |
63 | } | |
64 | } | |
65 | ||
66 | static int rkspi_extract_subimage(void *buf, struct image_tool_params *params) | |
67 | { | |
68 | return 0; | |
69 | } | |
70 | ||
71 | static int rkspi_check_image_type(uint8_t type) | |
72 | { | |
73 | if (type == IH_TYPE_RKSPI) | |
74 | return EXIT_SUCCESS; | |
75 | else | |
76 | return EXIT_FAILURE; | |
77 | } | |
78 | ||
79 | /* We pad the file out to a fixed size - this method returns that size */ | |
80 | static int rkspi_vrec_header(struct image_tool_params *params, | |
81 | struct image_type_params *tparams) | |
82 | { | |
83 | int pad_size; | |
84 | ||
7bf274b9 | 85 | pad_size = (rkcommon_get_spl_size(params) + 0x7ff) / 0x800 * 0x800; |
10b84fe1 SG |
86 | params->orig_file_size = pad_size; |
87 | ||
88 | /* We will double the image size due to the SPI format */ | |
89 | pad_size *= 2; | |
7bf274b9 | 90 | pad_size += RK_SPL_HDR_START; |
10b84fe1 SG |
91 | debug("pad_size %x\n", pad_size); |
92 | ||
93 | return pad_size - params->file_size; | |
94 | } | |
95 | ||
96 | /* | |
97 | * rk_spi parameters | |
98 | */ | |
99 | U_BOOT_IMAGE_TYPE( | |
100 | rkspi, | |
101 | "Rockchip SPI Boot Image support", | |
7bf274b9 | 102 | RK_IMAGE_HEADER_LEN, |
10b84fe1 | 103 | dummy_hdr, |
7bf274b9 | 104 | rkcommon_check_params, |
10b84fe1 SG |
105 | rkspi_verify_header, |
106 | rkspi_print_header, | |
107 | rkspi_set_header, | |
108 | rkspi_extract_subimage, | |
109 | rkspi_check_image_type, | |
110 | NULL, | |
111 | rkspi_vrec_header | |
112 | ); |