mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 3/9] ARM: zynq: add zynq fsbl checksum script
Date: Mon, 11 Mar 2013 11:05:38 +0100	[thread overview]
Message-ID: <20130311100538.GG1906@pengutronix.de> (raw)
In-Reply-To: <1362993306-19262-4-git-send-email-s.trumtrar@pengutronix.de>

On Mon, Mar 11, 2013 at 10:15:00AM +0100, Steffen Trumtrar wrote:
> The bootrom only reads an image if the correct checksum is present in the
> header. The calculation is pretty simple:
> sum over all words from 0x20 to 0x44
> Two of this words are the image length. That is why the checksum can not be
> calculated until barebox_image_size is known.
> The easiest solution is a program that has to be run after make.
> Maybe this can be replaced with some linker-fu.
> 
> Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
> ---
>  scripts/Makefile        |  1 +
>  scripts/zynq_checksum.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 56 insertions(+)
>  create mode 100644 scripts/zynq_checksum.c
> 
> diff --git a/scripts/Makefile b/scripts/Makefile
> index 08b325c..41c892e 100644
> --- a/scripts/Makefile
> +++ b/scripts/Makefile
> @@ -12,6 +12,7 @@ hostprogs-$(CONFIG_ARCH_NETX)    += gen_netx_image
>  hostprogs-$(CONFIG_ARCH_OMAP)    += omap_signGP mk-am35xx-spi-image
>  hostprogs-$(CONFIG_ARCH_S5PCxx)  += s5p_cksum
>  hostprogs-$(CONFIG_ARCH_DAVINCI) += mkublheader
> +hostprogs-$(CONFIG_ARCH_ZYNQ)	 += zynq_checksum
>  
>  HOSTLOADLIBES_omap4_usbboot = -lpthread
>  omap4_usbboot-objs               := usb_linux.o omap4_usbboot.o
> diff --git a/scripts/zynq_checksum.c b/scripts/zynq_checksum.c
> new file mode 100644
> index 0000000..e814f86
> --- /dev/null
> +++ b/scripts/zynq_checksum.c
> @@ -0,0 +1,55 @@
> +#include <malloc.h>
> +#include <stdio.h>
> +#include <sys/stat.h>
> +
> +int main(int argc, char *argv[])
> +{
> +	FILE *ifile, *ofile;
> +	unsigned int *buf;
> +	const char *infile;
> +	const char *outfile;
> +	struct stat st;
> +	unsigned int i;
> +	unsigned long sum = 0;
> +
> +	infile = argv[1];
> +	outfile = argv[2];
> +
> +	stat(infile, &st);
> +
> +	buf = malloc(sizeof(*buf) * st.st_size);
> +	if (!buf) {
> +		fprintf(stderr, "Unable to allocate buffer\n");
> +		return -1;
> +	}
> +	ifile = fopen(infile, "rb");
> +	if (!ifile) {
> +		fprintf(stderr, "Cannot open %s for reading\n",
> +			infile);
> +		free(buf);
> +		return -1;
> +	}
> +	ofile = fopen(outfile, "wb");
> +	if (!ofile) {
> +		fprintf(stderr, "Cannot open %s for writing\n",
> +			outfile);
> +		fclose(ifile);
> +		free(buf);
> +		return -1;
> +	}
> +
> +	fread(buf, 4, st.st_size, ifile);
> +
> +	for (i = 0x8; i < 0x12; i++)
> +		sum += buf[i];

endianess?

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

  reply	other threads:[~2013-03-11 10:05 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-11  9:14 [PATCH 0/9] ARM: add support for Zynq Steffen Trumtrar
2013-03-11  9:14 ` [PATCH 1/9] serial: Add driver for Cadence UART Steffen Trumtrar
2013-03-11  9:56   ` Sascha Hauer
2013-03-11  9:14 ` [PATCH 2/9] ARM: Zynq: Add new architecture zynq Steffen Trumtrar
2013-03-11 10:04   ` Sascha Hauer
2013-03-11 18:13   ` Josh Cartwright
2013-03-12 13:42   ` Josh Cartwright
2013-03-11  9:15 ` [PATCH 3/9] ARM: zynq: add zynq fsbl checksum script Steffen Trumtrar
2013-03-11 10:05   ` Sascha Hauer [this message]
2013-03-11  9:15 ` [PATCH 4/9] ARM: zynq: Add support for the Avnet Zedboard Steffen Trumtrar
2013-03-11 10:06   ` Sascha Hauer
2013-03-11  9:15 ` [PATCH 5/9] ARM: zynq: add clk support for zynq7000 Steffen Trumtrar
2013-03-11  9:15 ` [PATCH 6/9] ARM: zynq: clk: replace define with header Steffen Trumtrar
2013-03-11 18:29   ` Josh Cartwright
2013-03-11 18:55     ` Steffen Trumtrar
2013-03-11  9:15 ` [PATCH 7/9] ARM: zynq: clk: add pll type Steffen Trumtrar
2013-03-11 18:28   ` Josh Cartwright
2013-03-11 18:59     ` Steffen Trumtrar
2013-03-11  9:15 ` [PATCH 8/9] ARM: zynq: clk: convert to platform driver Steffen Trumtrar
2013-03-11  9:15 ` [PATCH 9/9] ARM: zynq: remove clocksource Steffen Trumtrar
2013-03-11 18:17   ` Josh Cartwright

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=20130311100538.GG1906@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.trumtrar@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