summaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-imx/imx-bbu-internal.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2013-07-26 10:52:25 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2013-08-06 15:38:40 +0200
commit15ee30138f59eac95379a4b94c538c1fcc338ed5 (patch)
tree133a2024ef3b0a5c8ec8cac0635adf1eaf0e41e8 /arch/arm/mach-imx/imx-bbu-internal.c
parentd00f5f0b996f17ce96e48d9ff17f76eb5e521e8c (diff)
downloadbarebox-15ee30138f59eac95379a4b94c538c1fcc338ed5.tar.gz
barebox-15ee30138f59eac95379a4b94c538c1fcc338ed5.tar.xz
ARM: i.MX: bbu-internal: optionally use DCD data from image
We used to pass the DCD data from the boards. This patch allows to optionally skip passing DCD data. In this case the DCD data from the flash image is used if present. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/arm/mach-imx/imx-bbu-internal.c')
-rw-r--r--arch/arm/mach-imx/imx-bbu-internal.c76
1 files changed, 50 insertions, 26 deletions
diff --git a/arch/arm/mach-imx/imx-bbu-internal.c b/arch/arm/mach-imx/imx-bbu-internal.c
index 70b7c444dc..a96b11044e 100644
--- a/arch/arm/mach-imx/imx-bbu-internal.c
+++ b/arch/arm/mach-imx/imx-bbu-internal.c
@@ -337,37 +337,14 @@ out:
return ret;
}
-/*
- * Update barebox on a v2 type internal boot (i.MX53)
- *
- * This constructs a DCD header, adds the specific DCD data and writes
- * the resulting image to the device. Currently this handles MMC/SD
- * and NAND devices.
- */
-static int imx_bbu_internal_v2_update(struct bbu_handler *handler, struct bbu_data *data)
+static void imx_bbu_internal_v2_init_flash_header(struct bbu_handler *handler, struct bbu_data *data,
+ void *imx_pre_image, int imx_pre_image_size)
{
struct imx_internal_bbu_handler *imx_handler =
container_of(handler, struct imx_internal_bbu_handler, handler);
struct imx_flash_header_v2 *flash_header;
unsigned long flash_header_offset = imx_handler->flash_header_offset;
- void *imx_pre_image;
- int imx_pre_image_size;
- int ret, image_len;
- void *buf;
-
- ret = imx_bbu_check_prereq(data);
- if (ret)
- return ret;
-
- printf("updating to %s\n", data->devicefile);
-
- if (imx_handler->flags & IMX_INTERNAL_FLAG_NAND)
- /* NAND needs additional space for the DBBT */
- imx_pre_image_size = 0x8000;
- else
- imx_pre_image_size = 0x2000;
- imx_pre_image = xzalloc(imx_pre_image_size);
flash_header = imx_pre_image + flash_header_offset;
flash_header->header.tag = IVT_HEADER_TAG;
@@ -394,11 +371,58 @@ static int imx_bbu_internal_v2_update(struct bbu_handler *handler, struct bbu_da
/* Add dcd data */
memcpy((void *)flash_header + sizeof(*flash_header), imx_handler->dcd, imx_handler->dcdsize);
+}
+
+#define IVT_BARKER 0x402000d1
+
+/*
+ * Update barebox on a v2 type internal boot (i.MX53)
+ *
+ * This constructs a DCD header, adds the specific DCD data and writes
+ * the resulting image to the device. Currently this handles MMC/SD
+ * and NAND devices.
+ */
+static int imx_bbu_internal_v2_update(struct bbu_handler *handler, struct bbu_data *data)
+{
+ struct imx_internal_bbu_handler *imx_handler =
+ container_of(handler, struct imx_internal_bbu_handler, handler);
+ void *imx_pre_image = NULL;
+ int imx_pre_image_size;
+ int ret, image_len;
+ void *buf;
+
+ ret = imx_bbu_check_prereq(data);
+ if (ret)
+ return ret;
+
+ if (imx_handler->dcd) {
+ imx_pre_image_size = 0x2000;
+ } else {
+ uint32_t *barker = data->image + imx_handler->flash_header_offset;
+
+ if (*barker != IVT_BARKER) {
+ printf("Board does not provide DCD data and this image is no imximage\n");
+ return -EINVAL;
+ }
+
+ imx_pre_image_size = 0;
+ }
+
+ if (imx_handler->flags & IMX_INTERNAL_FLAG_NAND)
+ /* NAND needs additional space for the DBBT */
+ imx_pre_image_size += 0x6000;
+
+ if (imx_pre_image_size)
+ imx_pre_image = xzalloc(imx_pre_image_size);
+
+ if (imx_handler->dcd)
+ imx_bbu_internal_v2_init_flash_header(handler, data, imx_pre_image, imx_pre_image_size);
/* Create a buffer containing header and image data */
image_len = data->len + imx_pre_image_size;
buf = xzalloc(image_len);
- memcpy(buf, imx_pre_image, imx_pre_image_size);
+ if (imx_pre_image_size)
+ memcpy(buf, imx_pre_image, imx_pre_image_size);
memcpy(buf + imx_pre_image_size, data->image, data->len);
if (imx_handler->flags & IMX_INTERNAL_FLAG_NAND) {