summaryrefslogtreecommitdiff
path: root/tools/omapimage.c
diff options
context:
space:
mode:
authorTom Rini <trini@ti.com>2012-10-16 13:06:06 +0000
committerTom Rini <trini@ti.com>2012-10-25 11:30:50 -0700
commit79b9ebb7007cd99409ff506c1bf57b2ab0975243 (patch)
tree50be078e8075e3472788ad1446f7cbeff64cdac3 /tools/omapimage.c
parent22cbeed454087ffa6ae6e56880bfff125497619b (diff)
downloadu-boot-79b9ebb7007cd99409ff506c1bf57b2ab0975243.tar.gz
omapimage: Add support for byteswapped SPI images
Add MLO.byteswap as a target to spl/Makefile and un-guard the first MLO rule so we don't have to duplicate it. Signed-off-by: Tom Rini <trini@ti.com>
Diffstat (limited to 'tools/omapimage.c')
-rw-r--r--tools/omapimage.c83
1 files changed, 65 insertions, 18 deletions
diff --git a/tools/omapimage.c b/tools/omapimage.c
index 5e739ac647..d242cca3a8 100644
--- a/tools/omapimage.c
+++ b/tools/omapimage.c
@@ -42,6 +42,18 @@
#define OMAP_GP_HDR_SIZE (sizeof(struct gp_header))
#define OMAP_FILE_HDR_SIZE (OMAP_CH_HDR_SIZE+OMAP_GP_HDR_SIZE)
+static int do_swap32 = 0;
+
+static uint32_t omapimage_swap32(uint32_t data)
+{
+ uint32_t result = 0;
+ result = (data & 0xFF000000) >> 24;
+ result |= (data & 0x00FF0000) >> 8;
+ result |= (data & 0x0000FF00) << 8;
+ result |= (data & 0x000000FF) << 24;
+ return result;
+}
+
static uint8_t omapimage_header[OMAP_FILE_HDR_SIZE];
static int omapimage_check_image_types(uint8_t type)
@@ -80,12 +92,17 @@ static int omapimage_verify_header(unsigned char *ptr, int image_size,
{
struct ch_toc *toc = (struct ch_toc *)ptr;
struct gp_header *gph = (struct gp_header *)(ptr+OMAP_CH_HDR_SIZE);
- uint32_t offset, size;
+ uint32_t offset, size, gph_size, gph_load_addr;
while (toc->section_offset != 0xffffffff
&& toc->section_size != 0xffffffff) {
- offset = toc->section_offset;
- size = toc->section_size;
+ if (do_swap32) {
+ offset = omapimage_swap32(toc->section_offset);
+ size = omapimage_swap32(toc->section_size);
+ } else {
+ offset = toc->section_offset;
+ size = toc->section_size;
+ }
if (!offset || !size)
return -1;
if (offset >= OMAP_CH_HDR_SIZE ||
@@ -93,9 +110,18 @@ static int omapimage_verify_header(unsigned char *ptr, int image_size,
return -1;
toc++;
}
- if (!valid_gph_size(gph->size))
+
+ if (do_swap32) {
+ gph_size = omapimage_swap32(gph->size);
+ gph_load_addr = omapimage_swap32(gph->load_addr);
+ } else {
+ gph_size = gph->size;
+ gph_load_addr = gph->load_addr;
+ }
+
+ if (!valid_gph_size(gph_size))
return -1;
- if (!valid_gph_load_addr(gph->load_addr))
+ if (!valid_gph_load_addr(gph_load_addr))
return -1;
return 0;
@@ -128,12 +154,17 @@ static void omapimage_print_header(const void *ptr)
const struct ch_toc *toc = (struct ch_toc *)ptr;
const struct gp_header *gph =
(struct gp_header *)(ptr+OMAP_CH_HDR_SIZE);
- uint32_t offset, size;
+ uint32_t offset, size, gph_size, gph_load_addr;
while (toc->section_offset != 0xffffffff
&& toc->section_size != 0xffffffff) {
- offset = toc->section_offset;
- size = toc->section_size;
+ if (do_swap32) {
+ offset = omapimage_swap32(toc->section_offset);
+ size = omapimage_swap32(toc->section_size);
+ } else {
+ offset = toc->section_offset;
+ size = toc->section_size;
+ }
if (offset >= OMAP_CH_HDR_SIZE ||
offset+size >= OMAP_CH_HDR_SIZE)
@@ -148,22 +179,26 @@ static void omapimage_print_header(const void *ptr)
toc++;
}
- if (!valid_gph_size(gph->size)) {
- fprintf(stderr,
- "Error: invalid image size %x\n",
- gph->size);
+ if (do_swap32) {
+ gph_size = omapimage_swap32(gph->size);
+ gph_load_addr = omapimage_swap32(gph->load_addr);
+ } else {
+ gph_size = gph->size;
+ gph_load_addr = gph->load_addr;
+ }
+
+ if (!valid_gph_size(gph_size)) {
+ fprintf(stderr, "Error: invalid image size %x\n", gph_size);
exit(EXIT_FAILURE);
}
- if (!valid_gph_load_addr(gph->load_addr)) {
- fprintf(stderr,
- "Error: invalid image load address %x\n",
- gph->size);
+ if (!valid_gph_load_addr(gph_load_addr)) {
+ fprintf(stderr, "Error: invalid image load address %x\n",
+ gph_load_addr);
exit(EXIT_FAILURE);
}
- printf("GP Header: Size %x LoadAddr %x\n",
- gph->size, gph->load_addr);
+ printf("GP Header: Size %x LoadAddr %x\n", gph_size, gph_load_addr);
}
static int toc_offset(void *hdr, void *member)
@@ -194,6 +229,18 @@ static void omapimage_set_header(void *ptr, struct stat *sbuf, int ifd,
gph->size = sbuf->st_size - OMAP_FILE_HDR_SIZE;
gph->load_addr = params->addr;
+
+ if (strncmp(params->imagename, "byteswap", 8) == 0) {
+ do_swap32 = 1;
+ int swapped = 0;
+ uint32_t *data = (uint32_t *)ptr;
+
+ while (swapped <= (sbuf->st_size / sizeof(uint32_t))) {
+ *data = omapimage_swap32(*data);
+ swapped++;
+ data++;
+ }
+ }
}
int omapimage_check_params(struct mkimage_params *params)