Commit a131c1f44231e3546b1cca8480400c98d1dd7ac8
1 parent
1b99e5bbb6
Exists in
v2017.01-smarct4x
and in
30 other branches
rockchip: Add the rkimage format to mkimage
Rockchip SoCs require certain formats for code that they execute, The simplest format is a 4-byte header at the start of a binary file. Add support for this so that we can create images that the boot ROM understands. Signed-off-by: Simon Glass <sjg@chromium.org>
Showing 6 changed files with 171 additions and 1 deletions Side-by-side Diff
common/image.c
... | ... | @@ -155,6 +155,7 @@ |
155 | 155 | { IH_TYPE_ATMELIMAGE, "atmelimage", "ATMEL ROM-Boot Image",}, |
156 | 156 | { IH_TYPE_X86_SETUP, "x86_setup", "x86 setup.bin", }, |
157 | 157 | { IH_TYPE_LPC32XXIMAGE, "lpc32xximage", "LPC32XX Boot Image", }, |
158 | + { IH_TYPE_RKIMAGE, "rkimage", "Rockchip Boot Image" }, | |
158 | 159 | { -1, "", "", }, |
159 | 160 | }; |
160 | 161 |
include/image.h
... | ... | @@ -245,8 +245,9 @@ |
245 | 245 | #define IH_TYPE_X86_SETUP 20 /* x86 setup.bin Image */ |
246 | 246 | #define IH_TYPE_LPC32XXIMAGE 21 /* x86 setup.bin Image */ |
247 | 247 | #define IH_TYPE_LOADABLE 22 /* A list of typeless images */ |
248 | +#define IH_TYPE_RKIMAGE 23 /* Rockchip Boot Image */ | |
248 | 249 | |
249 | -#define IH_TYPE_COUNT 23 /* Number of image types */ | |
250 | +#define IH_TYPE_COUNT 24 /* Number of image types */ | |
250 | 251 | |
251 | 252 | /* |
252 | 253 | * Compression Types |
tools/Makefile
... | ... | @@ -64,6 +64,8 @@ |
64 | 64 | rsa-sign.o rsa-verify.o rsa-checksum.o \ |
65 | 65 | rsa-mod-exp.o) |
66 | 66 | |
67 | +ROCKCHIP_OBS = lib/rc4.o rkcommon.o rkimage.o | |
68 | + | |
67 | 69 | # common objs for dumpimage and mkimage |
68 | 70 | dumpimage-mkimage-objs := aisimage.o \ |
69 | 71 | atmelimage.o \ |
... | ... | @@ -90,6 +92,7 @@ |
90 | 92 | os_support.o \ |
91 | 93 | pblimage.o \ |
92 | 94 | pbl_crc32.o \ |
95 | + $(ROCKCHIP_OBS) \ | |
93 | 96 | socfpgaimage.o \ |
94 | 97 | lib/sha1.o \ |
95 | 98 | lib/sha256.o \ |
tools/rkcommon.c
1 | +/* | |
2 | + * (C) Copyright 2015 Google, Inc | |
3 | + * Written by Simon Glass <sjg@chromium.org> | |
4 | + * | |
5 | + * SPDX-License-Identifier: GPL-2.0+ | |
6 | + * | |
7 | + * Helper functions for Rockchip images | |
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 { | |
17 | + RK_SIGNATURE = 0x0ff0aa55, | |
18 | +}; | |
19 | + | |
20 | +/** | |
21 | + * struct header0_info - header block for boot ROM | |
22 | + * | |
23 | + * This is stored at SD card block 64 (where each block is 512 bytes, or at | |
24 | + * the start of SPI flash. It is encoded with RC4. | |
25 | + * | |
26 | + * @signature: Signature (must be RKSD_SIGNATURE) | |
27 | + * @disable_rc4: 0 to use rc4 for boot image, 1 to use plain binary | |
28 | + * @code1_offset: Offset in blocks of the SPL code from this header | |
29 | + * block. E.g. 4 means 2KB after the start of this header. | |
30 | + * Other fields are not used by U-Boot | |
31 | + */ | |
32 | +struct header0_info { | |
33 | + uint32_t signature; | |
34 | + uint8_t reserved[4]; | |
35 | + uint32_t disable_rc4; | |
36 | + uint16_t code1_offset; | |
37 | + uint16_t code2_offset; | |
38 | + uint8_t reserved1[490]; | |
39 | + uint16_t usflashdatasize; | |
40 | + uint16_t ucflashbootsize; | |
41 | + uint8_t reserved2[2]; | |
42 | +}; | |
43 | + | |
44 | +static unsigned char rc4_key[16] = { | |
45 | + 124, 78, 3, 4, 85, 5, 9, 7, | |
46 | + 45, 44, 123, 56, 23, 13, 23, 17 | |
47 | +}; | |
48 | + | |
49 | +int rkcommon_set_header(void *buf, uint file_size) | |
50 | +{ | |
51 | + struct header0_info *hdr; | |
52 | + | |
53 | + if (file_size > RK_MAX_CODE1_SIZE) | |
54 | + return -ENOSPC; | |
55 | + | |
56 | + memset(buf, '\0', RK_CODE1_OFFSET * RK_BLK_SIZE); | |
57 | + hdr = (struct header0_info *)buf; | |
58 | + hdr->signature = RK_SIGNATURE; | |
59 | + hdr->disable_rc4 = 1; | |
60 | + hdr->code1_offset = RK_CODE1_OFFSET; | |
61 | + hdr->code2_offset = 8; | |
62 | + | |
63 | + hdr->usflashdatasize = (file_size + RK_BLK_SIZE - 1) / RK_BLK_SIZE; | |
64 | + hdr->usflashdatasize = (hdr->usflashdatasize + 3) & ~3; | |
65 | + hdr->ucflashbootsize = hdr->usflashdatasize; | |
66 | + | |
67 | + debug("size=%x, %x\n", params->file_size, hdr->usflashdatasize); | |
68 | + | |
69 | + rc4_encode(buf, RK_BLK_SIZE, rc4_key); | |
70 | + | |
71 | + return 0; | |
72 | +} |
tools/rkcommon.h
1 | +/* | |
2 | + * (C) Copyright 2015 Google, Inc | |
3 | + * Written by Simon Glass <sjg@chromium.org> | |
4 | + * | |
5 | + * SPDX-License-Identifier: GPL-2.0+ | |
6 | + */ | |
7 | + | |
8 | +#ifndef _RKCOMMON_H | |
9 | +#define _RKCOMMON_H | |
10 | + | |
11 | +enum { | |
12 | + RK_BLK_SIZE = 512, | |
13 | + RK_CODE1_OFFSET = 4, | |
14 | + RK_MAX_CODE1_SIZE = 32 << 10, | |
15 | +}; | |
16 | + | |
17 | +/** | |
18 | + * rkcommon_set_header() - set up the header for a Rockchip boot image | |
19 | + * | |
20 | + * This sets up a 2KB header which can be interpreted by the Rockchip boot ROM. | |
21 | + * | |
22 | + * @buf: Pointer to header place (must be at least 2KB in size) | |
23 | + * @file_size: Size of the file we want the boot ROM to load, in bytes | |
24 | + * @return 0 if OK, -ENOSPC if too large | |
25 | + */ | |
26 | +int rkcommon_set_header(void *buf, uint file_size); | |
27 | + | |
28 | +#endif |
tools/rkimage.c
1 | +/* | |
2 | + * (C) Copyright 2015 Google, Inc | |
3 | + * Written by Simon Glass <sjg@chromium.org> | |
4 | + * | |
5 | + * SPDX-License-Identifier: GPL-2.0+ | |
6 | + * | |
7 | + * See README.rockchip for details of the rkimage format | |
8 | + */ | |
9 | + | |
10 | +#include "imagetool.h" | |
11 | +#include <image.h> | |
12 | + | |
13 | +static uint32_t header; | |
14 | + | |
15 | +static int rkimage_check_params(struct image_tool_params *params) | |
16 | +{ | |
17 | + return 0; | |
18 | +} | |
19 | + | |
20 | +static int rkimage_verify_header(unsigned char *buf, int size, | |
21 | + struct image_tool_params *params) | |
22 | +{ | |
23 | + return 0; | |
24 | +} | |
25 | + | |
26 | +static void rkimage_print_header(const void *buf) | |
27 | +{ | |
28 | +} | |
29 | + | |
30 | +static void rkimage_set_header(void *buf, struct stat *sbuf, int ifd, | |
31 | + struct image_tool_params *params) | |
32 | +{ | |
33 | + memcpy(buf, "RK32", 4); | |
34 | +} | |
35 | + | |
36 | +static int rkimage_extract_subimage(void *buf, struct image_tool_params *params) | |
37 | +{ | |
38 | + return 0; | |
39 | +} | |
40 | + | |
41 | +static int rkimage_check_image_type(uint8_t type) | |
42 | +{ | |
43 | + if (type == IH_TYPE_RKIMAGE) | |
44 | + return EXIT_SUCCESS; | |
45 | + else | |
46 | + return EXIT_FAILURE; | |
47 | +} | |
48 | + | |
49 | +/* | |
50 | + * rk_image parameters | |
51 | + */ | |
52 | +U_BOOT_IMAGE_TYPE( | |
53 | + rkimage, | |
54 | + "Rockchip Boot Image support", | |
55 | + 4, | |
56 | + &header, | |
57 | + rkimage_check_params, | |
58 | + rkimage_verify_header, | |
59 | + rkimage_print_header, | |
60 | + rkimage_set_header, | |
61 | + rkimage_extract_subimage, | |
62 | + rkimage_check_image_type, | |
63 | + NULL, | |
64 | + NULL | |
65 | +); |