ARM: zynq: add zynq fsbl checksum script
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. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
097513b8f8
commit
26121ef51d
|
@ -36,6 +36,7 @@ barebox.netx
|
||||||
barebox.s5p
|
barebox.s5p
|
||||||
barebox.spi
|
barebox.spi
|
||||||
barebox.ubl
|
barebox.ubl
|
||||||
|
barebox.zynq
|
||||||
barebox.uimage
|
barebox.uimage
|
||||||
barebox.map
|
barebox.map
|
||||||
barebox-flash-image
|
barebox-flash-image
|
||||||
|
|
|
@ -249,6 +249,14 @@ KBUILD_TARGET := barebox.spi
|
||||||
KBUILD_IMAGE := barebox.spi
|
KBUILD_IMAGE := barebox.spi
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
barebox.zynq: $(KBUILD_BINARY)
|
||||||
|
$(Q)scripts/zynq_mkimage $< $@
|
||||||
|
|
||||||
|
ifeq ($(machine-y),zynq)
|
||||||
|
KBUILD_TARGET := barebox.zynq
|
||||||
|
KBUILD_IMAGE := barebox.zynq
|
||||||
|
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)/$@
|
||||||
|
|
|
@ -7,3 +7,4 @@ mkimage
|
||||||
mkublheader
|
mkublheader
|
||||||
omap_signGP
|
omap_signGP
|
||||||
omap4_usbboot
|
omap4_usbboot
|
||||||
|
zynq_mkimage
|
||||||
|
|
|
@ -12,6 +12,7 @@ hostprogs-$(CONFIG_ARCH_NETX) += gen_netx_image
|
||||||
hostprogs-$(CONFIG_ARCH_OMAP) += omap_signGP mk-am35xx-spi-image
|
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
|
||||||
|
hostprogs-$(CONFIG_ARCH_ZYNQ) += zynq_mkimage
|
||||||
|
|
||||||
HOSTLOADLIBES_omap4_usbboot = -lpthread
|
HOSTLOADLIBES_omap4_usbboot = -lpthread
|
||||||
omap4_usbboot-objs := usb_linux.o omap4_usbboot.o
|
omap4_usbboot-objs := usb_linux.o omap4_usbboot.o
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue