public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: "Andreas Bießmann" <andreas.devel@googlemail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC PATCH 1/2] mkimage: add atmelimage
Date: Wed, 23 Apr 2014 16:29:24 +0200	[thread overview]
Message-ID: <1398263365-17931-2-git-send-email-andreas.devel@googlemail.com> (raw)
In-Reply-To: <1398263365-17931-1-git-send-email-andreas.devel@googlemail.com>

The new atmelimage converts a machine code BLOB to bootable ROM image. Atmel
ROM has no sophisticated image format, it only checks the first 7 ARM vectors.
The vectors can contain valid B or LDR opcodes, the 6'th vector contains the
image size to load. The image size must not exceed 64 KiB.

Signed-off-by: Andreas Bie?mann <andreas.devel@googlemail.com>
---

 common/image.c     |    1 +
 include/image.h    |    1 +
 tools/Makefile     |    1 +
 tools/atmelimage.c |   88 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/imagetool.c  |    2 ++
 tools/imagetool.h  |    1 +
 6 files changed, 94 insertions(+)
 create mode 100644 tools/atmelimage.c

diff --git a/common/image.c b/common/image.c
index 9c6bec5..86bcd10 100644
--- a/common/image.c
+++ b/common/image.c
@@ -138,6 +138,7 @@ static const table_entry_t uimage_type[] = {
 	{	IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
 	{	IH_TYPE_UBLIMAGE,   "ublimage",   "Davinci UBL image",},
 	{	IH_TYPE_MXSIMAGE,   "mxsimage",   "Freescale MXS Boot Image",},
+	{	IH_TYPE_ATMELIMAGE, "atmelimage", "ATMEL ROM-Boot Image",},
 	{	-1,		    "",		  "",			},
 };
 
diff --git a/include/image.h b/include/image.h
index 2508d7d..542c90d 100644
--- a/include/image.h
+++ b/include/image.h
@@ -224,6 +224,7 @@ struct lmb;
 #define IH_TYPE_KERNEL_NOLOAD	14	/* OS Kernel Image, can run from any load address */
 #define IH_TYPE_PBLIMAGE	15	/* Freescale PBL Boot Image	*/
 #define IH_TYPE_MXSIMAGE	16	/* Freescale MXSBoot Image	*/
+#define IH_TYPE_ATMELIMAGE	17	/* ATMEL ROM bootable Image	*/
 
 /*
  * Compression Types
diff --git a/tools/Makefile b/tools/Makefile
index c34df4f..003727e 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -69,6 +69,7 @@ RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := rsa-sign.o rsa-verify.o rsa-checksum.o
 
 # common objs for dumpimage and mkimage
 dumpimage-mkimage-objs := aisimage.o \
+			atmelimage.o \
 			$(FIT_SIG_OBJS-y) \
 			crc32.o \
 			default_image.o \
diff --git a/tools/atmelimage.c b/tools/atmelimage.c
new file mode 100644
index 0000000..21436d3
--- /dev/null
+++ b/tools/atmelimage.c
@@ -0,0 +1,88 @@
+/*
+ * (C) Copyright 2014
+ * Andreas Bie?mann <andreas.devel@googlemail.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include "imagetool.h"
+#include <image.h>
+
+static int atmel_check_image_type(uint8_t type)
+{
+	if (type == IH_TYPE_ATMELIMAGE)
+		return EXIT_SUCCESS;
+	else
+		return EXIT_FAILURE;
+}
+
+static int atmel_verify_header(unsigned char *ptr, int image_size,
+			struct image_tool_params *params)
+{
+	uint32_t *ints = (uint32_t *)ptr;
+	size_t pos;
+
+	/* The size must not exceed 64 Kbytes */
+	if (image_size >= 64 * 1024)
+		return 1;
+
+	for (pos = 0; pos < 7; pos++) {
+		/*
+		 * all vectors except the 6'th one must contain valid
+		 * LDR or B Opcode
+		 */
+		if (pos == 5)
+			/* 6'th vector has image size set, check later */
+			continue;
+		if ((ints[pos] & 0xff000000) == 0xea000000)
+			/* valid B Opcode */
+			continue;
+		if ((ints[pos] & 0xfffff000) == 0xe59ff000)
+			/* valid LDR (I=0, P=1, U=1, B=0, W=0, L=1) */
+			continue;
+		/* ouch, one of the checks has missed ... */
+		return 1;
+	}
+	return ints[5] != image_size;
+}
+
+static void atmel_print_header(const void *ptr)
+{
+	printf("Image Type:   ATMEL ROM-Boot Image\n");
+}
+
+static void atmel_set_header(void *ptr, struct stat *sbuf, int ifd,
+				struct image_tool_params *params)
+{
+	/* just save the image size into 6'th interrupt vector */
+	uint32_t *ints = (uint32_t *)ptr;
+
+	/* The size must not exceed 64 Kbytes */
+	if (sbuf->st_size < 64 * 1024)
+		ints[5] = sbuf->st_size;
+}
+
+static int atmel_check_params(struct image_tool_params *params)
+{
+	return !(!params->eflag &&
+		!params->fflag &&
+		!params->xflag &&
+		((params->dflag && !params->lflag) ||
+		 (params->lflag && !params->dflag)));
+}
+
+static struct image_type_params atmelimage_params = {
+	.name		= "ATMEL ROM-Boot Image support",
+	.header_size	= 0,
+	.hdr		= NULL,
+	.check_image_type = atmel_check_image_type,
+	.verify_header	= atmel_verify_header,
+	.print_header	= atmel_print_header,
+	.set_header	= atmel_set_header,
+	.check_params	= atmel_check_params,
+};
+
+void init_atmel_image_type(void)
+{
+	register_image_type(&atmelimage_params);
+}
diff --git a/tools/imagetool.c b/tools/imagetool.c
index 29d2189..27072c8 100644
--- a/tools/imagetool.c
+++ b/tools/imagetool.c
@@ -27,6 +27,8 @@ void register_image_tool(imagetool_register_t image_register)
 	 */
 	register_func = image_register;
 
+	/* Init ATMEL ROM Boot Image generation/list support */
+	init_atmel_image_type();
 	/* Init Freescale PBL Boot image generation/list support */
 	init_pbl_image_type();
 	/* Init Kirkwood Boot image generation/list support */
diff --git a/tools/imagetool.h b/tools/imagetool.h
index c2c9aea..558f332 100644
--- a/tools/imagetool.h
+++ b/tools/imagetool.h
@@ -159,6 +159,7 @@ void register_image_type(struct image_type_params *tparams);
  * Supported image types init functions
  */
 void init_default_image_type(void);
+void init_atmel_image_type(void);
 void init_pbl_image_type(void);
 void init_ais_image_type(void);
 void init_kwb_image_type(void);
-- 
1.7.10.4

  reply	other threads:[~2014-04-23 14:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-23 14:29 [U-Boot] [RFC PATCH 0/2] Add atmel ROM code image Andreas Bießmann
2014-04-23 14:29 ` Andreas Bießmann [this message]
2014-04-24  3:09   ` [U-Boot] [RFC PATCH 1/2] mkimage: add atmelimage Bo Shen
2014-04-24  5:23     ` Andreas Bießmann
2014-04-23 14:29 ` [U-Boot] [RFC PATCH 2/2] arm:at91: enable ROM loadable atmel image Andreas Bießmann
2014-04-24  3:10   ` Bo Shen
2014-04-24  3:03 ` [U-Boot] [RFC PATCH 0/2] Add atmel ROM code image Bo Shen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1398263365-17931-2-git-send-email-andreas.devel@googlemail.com \
    --to=andreas.devel@googlemail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox