summaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2018-07-19 18:03:52 -0700
committerSascha Hauer <s.hauer@pengutronix.de>2018-08-09 08:19:50 +0200
commit4967ffecf8acf4136013e0ce8e87fb950da72bf6 (patch)
tree807abe78634c82c393d2a46526601fdb0e7e53af /arch
parentf7818799aca7bc673e85d4ffad8fa5a24e164670 (diff)
downloadbarebox-4967ffecf8acf4136013e0ce8e87fb950da72bf6.tar.gz
barebox-4967ffecf8acf4136013e0ce8e87fb950da72bf6.tar.xz
ARM: i.MX: xload-esdhc: Make use of <mach/imx-header.h>
Convert esdhc_start_image() to use constants and data types from <mach/imx-header.h>. Also, while at it, define a simple inline function to test if an arbitrary binary blob is i.MX flash header v2. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/mach-imx/include/mach/imx-header.h10
-rw-r--r--arch/arm/mach-imx/xload-esdhc.c14
2 files changed, 19 insertions, 5 deletions
diff --git a/arch/arm/mach-imx/include/mach/imx-header.h b/arch/arm/mach-imx/include/mach/imx-header.h
index 4fedba7adf..c9b2a58819 100644
--- a/arch/arm/mach-imx/include/mach/imx-header.h
+++ b/arch/arm/mach-imx/include/mach/imx-header.h
@@ -1,6 +1,8 @@
#ifndef __IMX_HEADER_H__
#define __IMX_HEADER_H__
+#include <linux/types.h>
+
#define HEADER_LEN 0x1000 /* length of the blank area + IVT + DCD */
/*
@@ -66,6 +68,14 @@ struct imx_flash_header_v2 {
struct imx_ivt_header dcd_header;
} __attribute__((packed));
+static inline bool is_imx_flash_header_v2(const void *blob)
+{
+ const struct imx_flash_header_v2 *hdr = blob;
+
+ return hdr->header.tag == TAG_IVT_HEADER &&
+ hdr->header.version >= IVT_VERSION;
+}
+
struct config_data {
uint32_t image_load_addr;
uint32_t image_dcd_offset;
diff --git a/arch/arm/mach-imx/xload-esdhc.c b/arch/arm/mach-imx/xload-esdhc.c
index 08ba9b08dc..5ce83b0bf0 100644
--- a/arch/arm/mach-imx/xload-esdhc.c
+++ b/arch/arm/mach-imx/xload-esdhc.c
@@ -18,6 +18,7 @@
#include <mach/imx8mq-regs.h>
#include <mach/xload.h>
#include <linux/sizes.h>
+#include <mach/imx-header.h>
#include "../../../drivers/mci/sdhci.h"
#include "../../../drivers/mci/imx-esdhc.h"
@@ -220,8 +221,9 @@ static int esdhc_read_blocks(struct esdhc *esdhc, void *dst, size_t len)
static int
esdhc_start_image(struct esdhc *esdhc, ptrdiff_t address, u32 offset)
{
+
void *buf = (void *)address;
- u32 *ivt = buf + offset + SZ_1K;
+ struct imx_flash_header_v2 *hdr = buf + offset + SZ_1K;
int ret, len;
void __noreturn (*bb)(void);
unsigned int ofs;
@@ -233,9 +235,11 @@ esdhc_start_image(struct esdhc *esdhc, ptrdiff_t address, u32 offset)
if (ret)
return ret;
- if (*(u32 *)(ivt) != 0x402000d1) {
- pr_debug("IVT header not found on SD card. Found 0x%08x instead of 0x402000d1\n",
- *ivt);
+ if (!is_imx_flash_header_v2(hdr)) {
+ pr_debug("IVT header not found on SD card. "
+ "Found tag: 0x%02x length: 0x%04x version: %02x\n",
+ hdr->header.tag, hdr->header.length,
+ hdr->header.version);
return -EINVAL;
}
@@ -249,7 +253,7 @@ esdhc_start_image(struct esdhc *esdhc, ptrdiff_t address, u32 offset)
pr_debug("Image loaded successfully\n");
- ofs = offset + *(ivt + 1) - *(ivt + 8);
+ ofs = offset + hdr->entry - hdr->boot_data.start;
bb = buf + ofs;