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>
This commit is contained in:
Tom Rini 2012-10-16 13:06:06 +00:00
parent 22cbeed454
commit 79b9ebb700
2 changed files with 68 additions and 24 deletions

View File

@ -112,16 +112,13 @@ LDPPFLAGS += \
$(shell $(LD) --version | \ $(shell $(LD) --version | \
sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p') sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p')
ifdef CONFIG_OMAP
$(OBJTREE)/MLO: $(obj)u-boot-spl.bin $(OBJTREE)/MLO: $(obj)u-boot-spl.bin
$(OBJTREE)/tools/mkimage -T omapimage \ $(OBJTREE)/tools/mkimage -T omapimage \
-a $(CONFIG_SPL_TEXT_BASE) -d $< $@ -a $(CONFIG_SPL_TEXT_BASE) -d $< $@
endif
ifdef CONFIG_AM33XX $(OBJTREE)/MLO.byteswap: $(obj)u-boot-spl.bin
$(OBJTREE)/MLO: $(obj)u-boot-spl.bin $(OBJTREE)/tools/mkimage -T omapimage -n byteswap \
$(OBJTREE)/tools/mkimage -T omapimage \
-a $(CONFIG_SPL_TEXT_BASE) -d $< $@ -a $(CONFIG_SPL_TEXT_BASE) -d $< $@
endif
ALL-y += $(obj)u-boot-spl.bin ALL-y += $(obj)u-boot-spl.bin

View File

@ -42,6 +42,18 @@
#define OMAP_GP_HDR_SIZE (sizeof(struct gp_header)) #define OMAP_GP_HDR_SIZE (sizeof(struct gp_header))
#define OMAP_FILE_HDR_SIZE (OMAP_CH_HDR_SIZE+OMAP_GP_HDR_SIZE) #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 uint8_t omapimage_header[OMAP_FILE_HDR_SIZE];
static int omapimage_check_image_types(uint8_t type) 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 ch_toc *toc = (struct ch_toc *)ptr;
struct gp_header *gph = (struct gp_header *)(ptr+OMAP_CH_HDR_SIZE); 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 while (toc->section_offset != 0xffffffff
&& toc->section_size != 0xffffffff) { && toc->section_size != 0xffffffff) {
offset = toc->section_offset; if (do_swap32) {
size = toc->section_size; offset = omapimage_swap32(toc->section_offset);
size = omapimage_swap32(toc->section_size);
} else {
offset = toc->section_offset;
size = toc->section_size;
}
if (!offset || !size) if (!offset || !size)
return -1; return -1;
if (offset >= OMAP_CH_HDR_SIZE || if (offset >= OMAP_CH_HDR_SIZE ||
@ -93,9 +110,18 @@ static int omapimage_verify_header(unsigned char *ptr, int image_size,
return -1; return -1;
toc++; 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; return -1;
if (!valid_gph_load_addr(gph->load_addr)) if (!valid_gph_load_addr(gph_load_addr))
return -1; return -1;
return 0; 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 ch_toc *toc = (struct ch_toc *)ptr;
const struct gp_header *gph = const struct gp_header *gph =
(struct gp_header *)(ptr+OMAP_CH_HDR_SIZE); (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 while (toc->section_offset != 0xffffffff
&& toc->section_size != 0xffffffff) { && toc->section_size != 0xffffffff) {
offset = toc->section_offset; if (do_swap32) {
size = toc->section_size; 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 || if (offset >= OMAP_CH_HDR_SIZE ||
offset+size >= OMAP_CH_HDR_SIZE) offset+size >= OMAP_CH_HDR_SIZE)
@ -148,22 +179,26 @@ static void omapimage_print_header(const void *ptr)
toc++; toc++;
} }
if (!valid_gph_size(gph->size)) { if (do_swap32) {
fprintf(stderr, gph_size = omapimage_swap32(gph->size);
"Error: invalid image size %x\n", gph_load_addr = omapimage_swap32(gph->load_addr);
gph->size); } 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); exit(EXIT_FAILURE);
} }
if (!valid_gph_load_addr(gph->load_addr)) { if (!valid_gph_load_addr(gph_load_addr)) {
fprintf(stderr, fprintf(stderr, "Error: invalid image load address %x\n",
"Error: invalid image load address %x\n", gph_load_addr);
gph->size);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
printf("GP Header: Size %x LoadAddr %x\n", printf("GP Header: Size %x LoadAddr %x\n", gph_size, gph_load_addr);
gph->size, gph->load_addr);
} }
static int toc_offset(void *hdr, void *member) 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->size = sbuf->st_size - OMAP_FILE_HDR_SIZE;
gph->load_addr = params->addr; 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) int omapimage_check_params(struct mkimage_params *params)