diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2013-04-04 23:23:19 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2013-04-04 23:23:19 +0200 |
commit | 0a637bcc3c66c647f52970ddd1dbae2d749dc969 (patch) | |
tree | 55ccc56a785cac9a3b990130f70316869ee77b47 /scripts | |
parent | dd9f6d08a2736bf8ddc0004779c563a4c3a77cef (diff) | |
parent | c6ef15b3879607a9e31964fc8942f95c253122f9 (diff) | |
download | barebox-0a637bcc3c66c647f52970ddd1dbae2d749dc969.tar.gz barebox-0a637bcc3c66c647f52970ddd1dbae2d749dc969.tar.xz |
Merge branch 'for-next/zynq'
Conflicts:
arch/arm/Makefile
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/.gitignore | 1 | ||||
-rw-r--r-- | scripts/Makefile | 1 | ||||
-rw-r--r-- | scripts/zynq_mkimage.c | 86 |
3 files changed, 88 insertions, 0 deletions
diff --git a/scripts/.gitignore b/scripts/.gitignore index 1ca66030c1..bff805ddf8 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -7,3 +7,4 @@ mkimage mkublheader omap_signGP omap4_usbboot +zynq_mkimage diff --git a/scripts/Makefile b/scripts/Makefile index e3e55aa6c7..f062fc011b 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_mkimage HOSTLOADLIBES_omap4_usbboot = -lpthread omap4_usbboot-objs := usb_linux.o omap4_usbboot.o diff --git a/scripts/zynq_mkimage.c b/scripts/zynq_mkimage.c new file mode 100644 index 0000000000..a096b834d1 --- /dev/null +++ b/scripts/zynq_mkimage.c @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2013 Steffen Trumtrar <s.trumtrar@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. + */ + +#include <endian.h> +#include <errno.h> +#include <malloc.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/stat.h> + +static void usage(char *name) +{ + printf("Usage: %s barebox-flash-image <outfile>\n", name); +} + +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; + + if (argc != 3) { + usage(argv[0]); + exit(1); + } + + infile = argv[1]; + outfile = argv[2]; + + if (stat(infile, &st) == -1) { + perror("stat"); + exit(EXIT_FAILURE); + } + + buf = malloc(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); + exit(EXIT_FAILURE); + } + ofile = fopen(outfile, "wb"); + if (!ofile) { + fprintf(stderr, "Cannot open %s for writing\n", + outfile); + fclose(ifile); + free(buf); + exit(EXIT_FAILURE); + } + + fread(buf, 4, st.st_size, ifile); + + for (i = 0x8; i < 0x12; i++) + sum += htole32(buf[i]); + + sum = ~sum; + buf[i] = sum; + + fwrite(buf, st.st_size / 4, 4, ofile); + + fclose(ofile); + fclose(ifile); + free(buf); + + return 0; +} |