1
2
3
4
5
6
7
8
9
10#include "imagetool.h"
11#include <image.h>
12#include <rc4.h>
13#include "mkimage.h"
14#include "rkcommon.h"
15
16enum {
17 RKSPI_SECT_LEN = RK_BLK_SIZE * 4,
18};
19
20static void rkspi_set_header(void *buf, struct stat *sbuf, int ifd,
21 struct image_tool_params *params)
22{
23 int sector;
24 unsigned int size;
25 int ret;
26
27 size = params->orig_file_size;
28 ret = rkcommon_set_header(buf, size, params);
29 debug("size %x\n", size);
30 if (ret) {
31
32 printf("Warning: SPL image is too large (size %#x) and will "
33 "not boot\n", size);
34 }
35
36
37
38
39
40
41 for (sector = size / RKSPI_SECT_LEN - 1; sector >= 0; sector--) {
42 debug("sector %u\n", sector);
43 memmove(buf + sector * RKSPI_SECT_LEN * 2,
44 buf + sector * RKSPI_SECT_LEN,
45 RKSPI_SECT_LEN);
46 memset(buf + sector * RKSPI_SECT_LEN * 2 + RKSPI_SECT_LEN,
47 '\0', RKSPI_SECT_LEN);
48 }
49}
50
51static int rkspi_check_image_type(uint8_t type)
52{
53 if (type == IH_TYPE_RKSPI)
54 return EXIT_SUCCESS;
55 else
56 return EXIT_FAILURE;
57}
58
59
60
61
62
63static int rkspi_vrec_header(struct image_tool_params *params,
64 struct image_type_params *tparams)
65{
66 int padding = rkcommon_vrec_header(params, tparams, RK_INIT_SIZE_ALIGN);
67
68
69
70
71
72 int padded_size = tparams->header_size + params->file_size + padding;
73
74
75
76
77
78 params->orig_file_size = padded_size;
79
80
81
82
83
84
85
86
87
88 return padded_size + padding;
89}
90
91
92
93
94U_BOOT_IMAGE_TYPE(
95 rkspi,
96 "Rockchip SPI Boot Image support",
97 0,
98 NULL,
99 rkcommon_check_params,
100 rkcommon_verify_header,
101 rkcommon_print_header,
102 rkspi_set_header,
103 NULL,
104 rkspi_check_image_type,
105 NULL,
106 rkspi_vrec_header
107);
108