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.de...@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.de...@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

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to