1
2
3
4
5
6
7
8
9#include "imagetool.h"
10#include <image.h>
11#include <rc4.h>
12#include "mkimage.h"
13#include "rkcommon.h"
14
15enum {
16 RKSPI_SECT_LEN = RK_BLK_SIZE * 4,
17};
18
19static void rkspi_set_header(void *buf, struct stat *sbuf, int ifd,
20 struct image_tool_params *params)
21{
22 int sector;
23 unsigned int size;
24
25 size = params->orig_file_size;
26
27 rkcommon_set_header(buf, sbuf, ifd, params);
28
29
30
31
32
33
34 if (params->vflag)
35 fprintf(stderr, "Spreading spi image from %u to %u\n",
36 size, params->file_size);
37
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,
42 RKSPI_SECT_LEN);
43 memset(buf + sector * RKSPI_SECT_LEN * 2 + RKSPI_SECT_LEN,
44 '\0', RKSPI_SECT_LEN);
45 }
46}
47
48static int rkspi_check_image_type(uint8_t type)
49{
50 if (type == IH_TYPE_RKSPI)
51 return EXIT_SUCCESS;
52 else
53 return EXIT_FAILURE;
54}
55
56
57
58
59
60static int rkspi_vrec_header(struct image_tool_params *params,
61 struct image_type_params *tparams)
62{
63 rkcommon_vrec_header(params, tparams);
64
65
66
67
68
69
70 params->file_size = ROUND(params->file_size, RKSPI_SECT_LEN) << 1;
71
72
73 return 0;
74}
75
76
77
78
79U_BOOT_IMAGE_TYPE(
80 rkspi,
81 "Rockchip SPI Boot Image support",
82 0,
83 NULL,
84 rkcommon_check_params,
85 rkcommon_verify_header,
86 rkcommon_print_header,
87 rkspi_set_header,
88 NULL,
89 rkspi_check_image_type,
90 NULL,
91 rkspi_vrec_header
92);
93