mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: Jan Luebbe <jlu@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 02/13] scripts: add tool to create image for SPI boot on AM35xx
Date: Mon, 20 Aug 2012 16:40:48 +0200	[thread overview]
Message-ID: <20120820144048.GW6271@game.jcrosoft.org> (raw)
In-Reply-To: <1345472428-17417-3-git-send-email-jlu@pengutronix.de>

On 16:20 Mon 20 Aug     , Jan Luebbe wrote:
> 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>
> ---
>  arch/arm/Makefile             |    8 +++
>  arch/arm/mach-omap/Kconfig    |    7 +++
>  scripts/.gitignore            |    5 +-
>  scripts/Makefile              |    2 +-
>  scripts/mk-am35xx-spi-image.c |  126 +++++++++++++++++++++++++++++++++++++++++
>  5 files changed, 145 insertions(+), 3 deletions(-)
>  create mode 100644 scripts/mk-am35xx-spi-image.c
> 
> diff --git a/arch/arm/Makefile b/arch/arm/Makefile
> index 1225df7..c2eb598 100644
> --- a/arch/arm/Makefile
> +++ b/arch/arm/Makefile
> @@ -186,6 +186,14 @@ endif
>  
>  all: $(KBUILD_IMAGE)
>  
> +barebox.spi: barebox.bin
> +	@echo "  SPI    " $@
> +	$(Q)scripts/mk-am35xx-spi-image barebox.bin > barebox.spi
you need to use cmd_ style and be in sync wtih the next branch

> +
> +ifeq ($(CONFIG_OMAP_BUILD_SPI),y)
> +all: barebox.spi
> +endif
> +
>  archprepare: maketools
>  maketools:
>  	$(Q)$(MAKE) $(build)=arch/arm/tools include/generated/mach-types.h
> diff --git a/arch/arm/mach-omap/Kconfig b/arch/arm/mach-omap/Kconfig
> index 386c484..aa9ab8c 100644
> --- a/arch/arm/mach-omap/Kconfig
> +++ b/arch/arm/mach-omap/Kconfig
> @@ -91,6 +91,13 @@ config OMAP_BUILD_IFT
>  	prompt "build ift binary"
>  	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
>  	hex
>  	default 0x80e80000 if MACH_OMAP343xSDP
> diff --git a/scripts/.gitignore b/scripts/.gitignore
> index 11fd2df..8772205 100644
> --- a/scripts/.gitignore
> +++ b/scripts/.gitignore
> @@ -1,6 +1,7 @@
>  bareboxenv
>  bin2c
> -mkimage
> -kallsyms
>  gen_netx_image
> +kallsyms
> +mk-am35xx-spi-image
> +mkimage
>  omap_signGP
> diff --git a/scripts/Makefile b/scripts/Makefile
> index 784d205..9b6b628 100644
> --- a/scripts/Makefile
> +++ b/scripts/Makefile
> @@ -9,7 +9,7 @@ hostprogs-y                      += bin2c
>  hostprogs-y                      += mkimage
>  hostprogs-y                      += bareboxenv
>  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
>  
>  always		:= $(hostprogs-y) $(hostprogs-m)
> diff --git a/scripts/mk-am35xx-spi-image.c b/scripts/mk-am35xx-spi-image.c
> new file mode 100644
> index 0000000..133f2b7
> --- /dev/null
> +++ b/scripts/mk-am35xx-spi-image.c
> @@ -0,0 +1,126 @@
> +/*
> + * mkublheader.c - produce the header needed to load barebox on OMAP-L138
> + *
> + * 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.
> + */
> +
> +#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);
why this??

you just need to create a PRE_IMAGE

so no need ot this

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2012-08-20 14:40 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-20 14:20 Jan Luebbe
2012-08-20 14:20 ` [PATCH 01/13] Makefile: add target to produce a SPL compatible uimage Jan Luebbe
2012-08-20 14:20 ` [PATCH 02/13] scripts: add tool to create image for SPI boot on AM35xx Jan Luebbe
2012-08-20 14:40   ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2012-08-21  6:51     ` Jan Luebbe
2012-08-21 13:04       ` Jean-Christophe PLAGNIOL-VILLARD
2012-08-20 14:20 ` [PATCH 03/13] common: split out meminfo output and make it optional Jan Luebbe
2012-08-20 14:42   ` Jean-Christophe PLAGNIOL-VILLARD
2012-08-21  6:55     ` Jan Luebbe
2012-08-20 14:20 ` [PATCH 04/13] omap: add SPI as a boot mode for xload Jan Luebbe
2012-08-20 14:20 ` [PATCH 05/13] drivers/net/ksz8864rmn: add driver for Micrel KSZ8864RMN Ethernet Switch Jan Luebbe
2012-08-20 14:20 ` [PATCH 06/13] drivers/net: add driver for the EMAC device found in some TI SoCs Jan Luebbe
2012-08-20 14:47   ` Jean-Christophe PLAGNIOL-VILLARD
2012-08-21  6:59     ` Jan Luebbe
2012-08-21 12:16       ` Jean-Christophe PLAGNIOL-VILLARD
2012-08-20 14:20 ` [PATCH 07/13] omap3: allow enabling clocks for UART3, MMC1 and SPI Jan Luebbe
2012-08-20 14:47   ` Jean-Christophe PLAGNIOL-VILLARD
2012-08-21  7:08     ` Jan Luebbe
2012-08-21 12:15       ` Jean-Christophe PLAGNIOL-VILLARD
2012-08-20 14:20 ` [PATCH 08/13] drivers/spi: add driver for the Multichannel SPI controller found in TI SoCs Jan Luebbe
2012-08-20 14:58   ` Jean-Christophe PLAGNIOL-VILLARD
2012-08-21  7:16     ` Jan Luebbe
2012-08-21 12:14       ` Jean-Christophe PLAGNIOL-VILLARD
2012-08-20 14:20 ` [PATCH 09/13] m25p80: add JEDEC ID for Micron/Numonyx SPI NOR flash Jan Luebbe
2012-08-20 14:20 ` [PATCH 10/13] defaultenv: support NAND and NOR kernel partitions at the same time Jan Luebbe
2012-08-20 14:59   ` Jean-Christophe PLAGNIOL-VILLARD
2012-08-20 14:20 ` [PATCH 11/13] defaultenv: use /env/oftree if it exists Jan Luebbe
2012-08-20 15:00   ` Jean-Christophe PLAGNIOL-VILLARD
2012-08-20 14:20 ` [PATCH 12/13] defaultenv: support kernel and oftree on a filesystem Jan Luebbe
2012-08-20 15:00   ` Jean-Christophe PLAGNIOL-VILLARD
2012-08-20 14:20 ` [PATCH 13/13] omap3_clock: avoid initializing cores not present on TI AM35xx Jan Luebbe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120820144048.GW6271@game.jcrosoft.org \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.org \
    --cc=jlu@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox