scripts: mk-am3xxx-spi-image: fix wrong assumptions about SPI images
We assumed that there is a special image format for SPI. This is not the case. The AM33xx can boot either images generated with omap_signGP or raw images which only have the image size and load address in front of the image. Whether these images are booted from SPI or another boot medium doesn't matter. The only special thing about SPI is that the image is in big endian format. - renames mk-am3xxx-spi-image.c to mk-omap-image.c as the image format is not only supported by AM3xxx but also by the OMAP SoCs - removes the option to specify the SoC - introduces -s to build a big endian image - detects if an image already is an image generated with omap_signGP So the behaviour is like this: raw image -> mk-omap-image -> prepend size/address -> image for SD/MMC raw image -> mk-omap-image -s -> prepend size/address, big endian swap -> image for SPI CH image -> mk-omap-image -> nothing, input == output CH image -> mk-omap-image -s -> big endian swap -> image for SPI Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
b1536a3298
commit
ad428bcb5d
|
@ -163,7 +163,7 @@ KBUILD_IMAGE := barebox.ubl
|
|||
endif
|
||||
|
||||
quiet_cmd_am35xx_spi_image = SPI-IMG $@
|
||||
cmd_am35xx_spi_image = scripts/mk-am3xxx-spi-image -s am35xx -a $(TEXT_BASE) $< > $@
|
||||
cmd_am35xx_spi_image = scripts/mk-omap-image -s -a $(TEXT_BASE) $< > $@
|
||||
|
||||
barebox.spi: $(KBUILD_BINARY) FORCE
|
||||
$(call if_changed,am35xx_spi_image)
|
||||
|
|
|
@ -10,7 +10,7 @@ kwbimage
|
|||
kwboot
|
||||
gen_netx_image
|
||||
omap_signGP
|
||||
mk-am3xxx-spi-image
|
||||
mk-omap-image
|
||||
s5p_cksum
|
||||
mkublheader
|
||||
zynq_mkimage
|
||||
|
|
|
@ -14,7 +14,7 @@ hostprogs-$(CONFIG_IMD) += bareboximd
|
|||
hostprogs-$(CONFIG_KALLSYMS) += kallsyms
|
||||
hostprogs-$(CONFIG_ARCH_MVEBU) += kwbimage kwboot
|
||||
hostprogs-$(CONFIG_ARCH_NETX) += gen_netx_image
|
||||
hostprogs-$(CONFIG_ARCH_OMAP) += omap_signGP mk-am3xxx-spi-image
|
||||
hostprogs-$(CONFIG_ARCH_OMAP) += omap_signGP mk-omap-image
|
||||
hostprogs-$(CONFIG_ARCH_S5PCxx) += s5p_cksum
|
||||
hostprogs-$(CONFIG_ARCH_DAVINCI) += mkublheader
|
||||
hostprogs-$(CONFIG_ARCH_ZYNQ) += zynq_mkimage
|
||||
|
|
|
@ -48,66 +48,38 @@
|
|||
#include <getopt.h>
|
||||
#include <endian.h>
|
||||
|
||||
enum soc {
|
||||
SOC_AM33XX,
|
||||
SOC_AM35XX,
|
||||
SOC_UNKNOWN,
|
||||
};
|
||||
|
||||
static char *soc_names[] = {
|
||||
[SOC_AM33XX] = "am33xx",
|
||||
[SOC_AM35XX] = "am35xx",
|
||||
};
|
||||
|
||||
void usage(char *prgname)
|
||||
{
|
||||
printf("usage: %s [OPTION] FILE > IMAGE\n"
|
||||
"\n"
|
||||
"options:\n"
|
||||
" -a <address> memory address for the loaded image in SRAM\n"
|
||||
" -s <soc> SoC to use (am33xx, am35xx)\n",
|
||||
" -s Write big endian image needed for direct flashing to SPI\n",
|
||||
prgname);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *input;
|
||||
int opt, i;
|
||||
int opt;
|
||||
off_t pos;
|
||||
size_t size;
|
||||
uint32_t addr = 0x40200000;
|
||||
uint32_t temp;
|
||||
enum soc soc = SOC_UNKNOWN;
|
||||
char *socname = NULL;
|
||||
int chsettings = 0;
|
||||
int swap = 0;
|
||||
|
||||
while((opt = getopt(argc, argv, "a:s:")) != -1) {
|
||||
while((opt = getopt(argc, argv, "a:s")) != -1) {
|
||||
switch (opt) {
|
||||
case 'a':
|
||||
addr = strtoul(optarg, NULL, 0);
|
||||
break;
|
||||
case 's':
|
||||
socname = optarg;
|
||||
swap = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!socname) {
|
||||
fprintf(stderr, "SoC not specified. Use -s <soc>\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (!strcmp(socname, soc_names[i])) {
|
||||
soc = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (soc == SOC_UNKNOWN) {
|
||||
fprintf(stderr, "SoC %s unknown\n", socname);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (optind >= argc) {
|
||||
usage(argv[0]);
|
||||
exit(1);
|
||||
|
@ -134,20 +106,43 @@ int main(int argc, char *argv[])
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (fseeko(input, 0, SEEK_SET) == -1) {
|
||||
if (fseeko(input, 0x14, SEEK_SET) == -1) {
|
||||
perror("fseeko");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
size = fread(&temp, 1, sizeof(uint32_t), input);
|
||||
if (!size) {
|
||||
perror("fseeko");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test if this is an image generated with omap_signGP. These don't
|
||||
* need size and load address prepended.
|
||||
*/
|
||||
if (le32toh(temp) == 0x45534843)
|
||||
chsettings = 1;
|
||||
|
||||
if (fseeko(input, 0x0, SEEK_SET) == -1) {
|
||||
perror("fseeko");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
pos = (pos + 3) & ~3;
|
||||
|
||||
/* image size */
|
||||
if (soc == SOC_AM35XX) {
|
||||
temp = htobe32((uint32_t)pos);
|
||||
if (!chsettings) {
|
||||
/* image size */
|
||||
temp = pos;
|
||||
if (swap)
|
||||
temp = htobe32(temp);
|
||||
|
||||
fwrite(&temp, sizeof(uint32_t), 1, stdout);
|
||||
|
||||
/* memory address */
|
||||
temp = htobe32(addr);
|
||||
temp = addr;
|
||||
if (swap)
|
||||
temp = htobe32(temp);
|
||||
fwrite(&temp, sizeof(uint32_t), 1, stdout);
|
||||
}
|
||||
|
||||
|
@ -159,7 +154,8 @@ int main(int argc, char *argv[])
|
|||
perror("fread");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
temp = htobe32(le32toh(temp));
|
||||
if (swap)
|
||||
temp = htobe32(le32toh(temp));
|
||||
if (fwrite(&temp, 1, sizeof(uint32_t), stdout) != 4) {
|
||||
perror("fwrite");
|
||||
exit(EXIT_FAILURE);
|
Loading…
Reference in New Issue