
Hi Philipp,
On 17 April 2017 at 09:48, Philipp Tomsich < philipp.tomsich@theobroma-systems.com> wrote:
The rockchip image generation was previously missing the ability to verify the generated header (and dump the image-type) without having to resort to hexdump or od. Experience in our testing has showed it to be very easy to get the rkspi and rksd images mixed up and the lab... so we add the necessary support to have dumpimage tell us what image type we're dealing with.
This change set adds the verify_header and print_header capability to the rksd/rkspi image drivers (through shared code in rkcommon).
As of now, we only support images fully that are not RC4-encoded for the SPL payload (i.e. header1 and payload). For RC4-encoded payloads, the outer header (header0) is checked, but no detection of whether this is a SD/MMC or SPI formatted payload takes place.
The output of dumpsys now prints the image type (spl_hdr), whether it is a SD/MMC or SPI image, and the (padded) size of the image: $ ./tools/dumpimage -l ./spl.img Image Type: Rockchip RK33 (SD/MMC) boot image ^^^^^^ SD/MMC vs. SPI indication ^^^^ spl_hdr indicated by the image Data Size: 79872 bytes
Signed-off-by: Philipp Tomsich philipp.tomsich@theobroma-systems.com
tools/rkcommon.c | 119
++++++++++++++++++++++++++++++++++++++++++++++++++++++-
tools/rkcommon.h | 19 +++++++++ tools/rksd.c | 29 +++----------- tools/rkspi.c | 21 ++-------- 4 files changed, 146 insertions(+), 42 deletions(-)
Acked-by: Simon Glass sjg@chromium.org
But please see below.
diff --git a/tools/rkcommon.c b/tools/rkcommon.c index 773e4f6..ae414b3 100644 --- a/tools/rkcommon.c +++ b/tools/rkcommon.c @@ -2,6 +2,8 @@
- (C) Copyright 2015 Google, Inc
- Written by Simon Glass sjg@chromium.org
- (C) 2017 Theobroma Systems Design und Consulting GmbH
- SPDX-License-Identifier: GPL-2.0+
- Helper functions for Rockchip images
@@ -200,7 +202,7 @@ int rkcommon_set_header(void *buf, uint file_size,
rkcommon_set_header0(buf, file_size, params);
- /* Set up the SPL name */
- /* Set up the SPL name (i.e. copy spl_hdr over) */
memcpy(&hdr->magic, rkcommon_get_spl_hdr(params), RK_SPL_HDR_SIZE);
if (rkcommon_need_rc4_spl(params)) @@ -210,6 +212,121 @@ int rkcommon_set_header(void *buf, uint file_size, return 0; }
+static inline unsigned rkcommon_offset_to_spi(unsigned offset) +{
- /*
- While SD/MMC images use a flat addressing, SPI images are padded
- to use the first 2K of every 4K sector only.
- */
- return ((offset & ~0x7ff) << 1) + (offset & 0x7ff);
+}
+static inline unsigned rkcommon_spi_to_offset(unsigned offset) +{
- return ((offset & ~0x7ff) >> 1) + (offset & 0x7ff);
+}
+static int rkcommon_parse_header(const void *buf, struct header0_info
*header0,
- struct spl_info **spl_info)
+{
- unsigned hdr1_offset;
- struct header1_info *hdr1_sdmmc, *hdr1_spi;
- int i;
- if (spl_info)
- *spl_info = NULL;
- /*
- The first header (hdr0) is always RC4 encoded, so try to decrypt
- with the well-known key.
- */
- memcpy((void *)header0, buf, sizeof(struct header0_info));
- rc4_encode((void *)header0, sizeof(struct header0_info), rc4_key);
- if (header0->signature != RK_SIGNATURE)
- return -FDT_ERR_BADSTRUCTURE;
Can you choose a standard error? We cannot mix and match erno and libfdt.h
- /* We don't support RC4 encoded image payloads here, yet... */
- if (header0->disable_rc4 == 0)
- return -ENOSYS;
Regards, Simon