scripts: add tool to create image for SPI boot on AM35xx
Booting from SPI on an AM35xx (and possibly other TI SOCs) requires a special format: - 32 bit image size in big-endian - 32 bit load address in big-endian - binary image converted from little- to big-endian The mk-am35xx-spi-image tool converts barebox.bin to this format. Signed-off-by: Jan Luebbe <jlu@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
3fc5a75457
commit
93ca711e64
|
@ -34,6 +34,7 @@ barebox.bin
|
||||||
barebox.srec
|
barebox.srec
|
||||||
barebox.netx
|
barebox.netx
|
||||||
barebox.s5p
|
barebox.s5p
|
||||||
|
barebox.spi
|
||||||
barebox.ubl
|
barebox.ubl
|
||||||
barebox.map
|
barebox.map
|
||||||
System.map
|
System.map
|
||||||
|
|
3
Makefile
3
Makefile
|
@ -1009,7 +1009,8 @@ CLEAN_FILES += barebox System.map include/generated/barebox_default_env.h \
|
||||||
.tmp_version .tmp_barebox* barebox.bin barebox.map barebox.S \
|
.tmp_version .tmp_barebox* barebox.bin barebox.map barebox.S \
|
||||||
.tmp_kallsyms* barebox_default_env* barebox.ldr \
|
.tmp_kallsyms* barebox_default_env* barebox.ldr \
|
||||||
scripts/bareboxenv-target barebox-flash-image \
|
scripts/bareboxenv-target barebox-flash-image \
|
||||||
Doxyfile.version barebox.srec barebox.s5p
|
Doxyfile.version barebox.srec barebox.s5p \
|
||||||
|
barebox.spi
|
||||||
|
|
||||||
# Directories & files removed with 'make mrproper'
|
# Directories & files removed with 'make mrproper'
|
||||||
MRPROPER_DIRS += include/config include2 usr/include
|
MRPROPER_DIRS += include/config include2 usr/include
|
||||||
|
|
|
@ -212,6 +212,17 @@ KBUILD_TARGET := barebox.ubl
|
||||||
KBUILD_BINARY := $(KBUILD_TARGET)
|
KBUILD_BINARY := $(KBUILD_TARGET)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
quiet_cmd_am35xx_spi_image = SPI-IMG $@
|
||||||
|
cmd_am35xx_spi_image = scripts/mk-am35xx-spi-image $< > $@
|
||||||
|
|
||||||
|
barebox.spi: $(KBUILD_BINARY) FORCE
|
||||||
|
$(call if_changed,am35xx_spi_image)
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_OMAP_BUILD_SPI),y)
|
||||||
|
KBUILD_TARGET := barebox.spi
|
||||||
|
KBUILD_IMAGE := barebox.spi
|
||||||
|
endif
|
||||||
|
|
||||||
pbl := arch/arm/pbl
|
pbl := arch/arm/pbl
|
||||||
zbarebox.S zbarebox.bin zbarebox: barebox.bin
|
zbarebox.S zbarebox.bin zbarebox: barebox.bin
|
||||||
$(Q)$(MAKE) $(build)=$(pbl) $(pbl)/$@
|
$(Q)$(MAKE) $(build)=$(pbl) $(pbl)/$@
|
||||||
|
|
|
@ -78,6 +78,13 @@ config OMAP_BUILD_IFT
|
||||||
prompt "build ift binary"
|
prompt "build ift binary"
|
||||||
bool
|
bool
|
||||||
|
|
||||||
|
config OMAP_BUILD_SPI
|
||||||
|
prompt "build SPI binary"
|
||||||
|
bool
|
||||||
|
help
|
||||||
|
Say Y here if you want to build an barebox.spi image as used
|
||||||
|
on the AM35xx chips when booting form SPI NOR flash.
|
||||||
|
|
||||||
config ARCH_TEXT_BASE
|
config ARCH_TEXT_BASE
|
||||||
hex
|
hex
|
||||||
default 0x80e80000 if MACH_OMAP343xSDP
|
default 0x80e80000 if MACH_OMAP343xSDP
|
||||||
|
|
|
@ -2,6 +2,7 @@ bareboxenv
|
||||||
bin2c
|
bin2c
|
||||||
gen_netx_image
|
gen_netx_image
|
||||||
kallsyms
|
kallsyms
|
||||||
|
mk-am35xx-spi-image
|
||||||
mkimage
|
mkimage
|
||||||
mkublheader
|
mkublheader
|
||||||
omap_signGP
|
omap_signGP
|
||||||
|
|
|
@ -9,7 +9,7 @@ hostprogs-y += bin2c
|
||||||
hostprogs-y += mkimage
|
hostprogs-y += mkimage
|
||||||
hostprogs-y += bareboxenv
|
hostprogs-y += bareboxenv
|
||||||
hostprogs-$(CONFIG_ARCH_NETX) += gen_netx_image
|
hostprogs-$(CONFIG_ARCH_NETX) += gen_netx_image
|
||||||
hostprogs-$(CONFIG_ARCH_OMAP) += omap_signGP
|
hostprogs-$(CONFIG_ARCH_OMAP) += omap_signGP mk-am35xx-spi-image
|
||||||
hostprogs-$(CONFIG_ARCH_S5PCxx) += s5p_cksum
|
hostprogs-$(CONFIG_ARCH_S5PCxx) += s5p_cksum
|
||||||
hostprogs-$(CONFIG_ARCH_DAVINCI) += mkublheader
|
hostprogs-$(CONFIG_ARCH_DAVINCI) += mkublheader
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,141 @@
|
||||||
|
/*
|
||||||
|
* mk-am35xx-spi-image.c - convert a barebox image for SPI loading on AM35xx
|
||||||
|
*
|
||||||
|
* Copyright (C) 2012 Jan Luebbe <j.luebbe@pengutronix.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief convert a barebox image for SPI loading on AM35xx
|
||||||
|
*
|
||||||
|
* FileName: scripts/mk-am35xx-spi-image.c
|
||||||
|
*
|
||||||
|
* Booting from SPI on an AM35xx (and possibly other TI SOCs) requires
|
||||||
|
* a special format:
|
||||||
|
*
|
||||||
|
* - 32 bit image size in big-endian
|
||||||
|
* - 32 bit load address in big-endian
|
||||||
|
* - binary image converted from little- to big-endian
|
||||||
|
*
|
||||||
|
* This tool converts barebox.bin to the required format.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _BSD_SOURCE
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <endian.h>
|
||||||
|
|
||||||
|
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",
|
||||||
|
prgname);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
FILE *input;
|
||||||
|
int opt;
|
||||||
|
off_t pos;
|
||||||
|
size_t size;
|
||||||
|
uint32_t addr = 0x40200000;
|
||||||
|
uint32_t temp;
|
||||||
|
|
||||||
|
while((opt = getopt(argc, argv, "a:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'a':
|
||||||
|
addr = strtoul(optarg, NULL, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optind >= argc) {
|
||||||
|
usage(argv[0]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
input = fopen(argv[optind], "r");
|
||||||
|
if (input == NULL) {
|
||||||
|
perror("fopen");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fseeko(input, 0, SEEK_END) == -1) {
|
||||||
|
perror("fseeko");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
pos = ftello(input);
|
||||||
|
if (pos == -1) {
|
||||||
|
perror("ftello");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (pos % 4) {
|
||||||
|
printf("error: image size must be a multiple of 4 bytes\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if (pos > 0x100000) {
|
||||||
|
printf("error: image should be smaller than 1 MiB\n");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fseeko(input, 0, SEEK_SET) == -1) {
|
||||||
|
perror("fseeko");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* image size */
|
||||||
|
temp = htobe32((uint32_t)pos);
|
||||||
|
fwrite(&temp, sizeof(uint32_t), 1, stdout);
|
||||||
|
|
||||||
|
/* memory address */
|
||||||
|
temp = htobe32(addr);
|
||||||
|
fwrite(&temp, sizeof(uint32_t), 1, stdout);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
size = fread(&temp, 1, sizeof(uint32_t), input);
|
||||||
|
if (!size)
|
||||||
|
break;
|
||||||
|
if (size != 4) {
|
||||||
|
perror("fread");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
temp = htobe32(le32toh(temp));
|
||||||
|
if (fwrite(&temp, 1, sizeof(uint32_t), stdout) != 4) {
|
||||||
|
perror("fwrite");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fclose(input) != 0) {
|
||||||
|
perror("fclose");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
Loading…
Reference in New Issue