summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/.gitignore4
-rw-r--r--tools/Makefile134
-rw-r--r--tools/atmel_pmecc_params.c51
-rw-r--r--tools/atmelimage.c342
-rw-r--r--tools/buildman/toolchain.py4
-rw-r--r--tools/crc32.c1
-rw-r--r--tools/dumpimage.h2
-rw-r--r--tools/env_embedded.c1
-rw-r--r--tools/fdt.c1
-rw-r--r--tools/fdt_ro.c1
-rw-r--r--tools/fdt_rw.c1
-rw-r--r--tools/fdt_strerror.c1
-rw-r--r--tools/fdt_wip.c1
-rw-r--r--tools/fdtdec.c1
-rw-r--r--tools/fit_check_sign.c26
-rw-r--r--tools/fit_common.c49
-rw-r--r--tools/fit_common.h15
-rw-r--r--tools/fit_image.c112
-rw-r--r--tools/fit_info.c14
-rw-r--r--tools/image-fit.c1
-rw-r--r--tools/image-host.c40
-rw-r--r--tools/image-sig.c1
-rw-r--r--tools/image.c1
-rw-r--r--tools/imagetool.c2
-rw-r--r--tools/imagetool.h3
-rw-r--r--tools/md5.c1
-rw-r--r--tools/mkimage.h2
-rw-r--r--tools/mxsimage.c32
-rw-r--r--tools/patman/gitutil.py4
-rw-r--r--tools/pbl_crc32.c56
-rw-r--r--tools/pbl_crc32.h13
-rw-r--r--tools/pblimage.c47
-rw-r--r--tools/rsa-checksum.c1
-rw-r--r--tools/rsa-sign.c1
-rw-r--r--tools/rsa-verify.c1
-rw-r--r--tools/sha1.c1
-rw-r--r--tools/sha256.c1
-rw-r--r--tools/ubsha1.c2
38 files changed, 732 insertions, 239 deletions
diff --git a/tools/.gitignore b/tools/.gitignore
index 725db90..cefe923 100644
--- a/tools/.gitignore
+++ b/tools/.gitignore
@@ -17,7 +17,9 @@
/relocate-rela
/ubsha1
/xway-swap-bytes
-/*.exe
/easylogo/easylogo
/gdb/gdbcont
/gdb/gdbsend
+
+/lib/
+/common/
diff --git a/tools/Makefile b/tools/Makefile
index b645224..61b2048 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -5,15 +5,6 @@
# SPDX-License-Identifier: GPL-2.0+
#
-#
-# toolchains targeting win32 generate .exe files
-#
-ifneq (,$(findstring WIN32 ,$(shell $(HOSTCC) -E -dM -xc /dev/null)))
-SFX = .exe
-else
-SFX =
-endif
-
# Enable all the config-independent tools
ifneq ($(HOST_TOOLS_ALL),)
CONFIG_LCD_LOGO = y
@@ -38,111 +29,118 @@ ENVCRC-$(CONFIG_ENV_IS_IN_NVRAM) = y
ENVCRC-$(CONFIG_ENV_IS_IN_SPI_FLASH) = y
CONFIG_BUILD_ENVCRC ?= $(ENVCRC-y)
+hostprogs-$(CONFIG_SPL_GENERATE_ATMEL_PMECC_HEADER) += atmel_pmecc_params
+
# TODO: CONFIG_CMD_LICENSE does not work
-hostprogs-$(CONFIG_CMD_LICENSE) += bin2header$(SFX)
-hostprogs-$(CONFIG_LCD_LOGO) += bmp_logo$(SFX)
-hostprogs-$(CONFIG_VIDEO_LOGO) += bmp_logo$(SFX)
-HOSTCFLAGS_bmp_logo$(SFX).o := -pedantic
+hostprogs-$(CONFIG_CMD_LICENSE) += bin2header
+hostprogs-$(CONFIG_LCD_LOGO) += bmp_logo
+hostprogs-$(CONFIG_VIDEO_LOGO) += bmp_logo
+HOSTCFLAGS_bmp_logo.o := -pedantic
-hostprogs-$(CONFIG_BUILD_ENVCRC) += envcrc$(SFX)
-envcrc$(SFX)-objs := crc32.o env_embedded.o envcrc.o sha1.o
+hostprogs-$(CONFIG_BUILD_ENVCRC) += envcrc
+envcrc-objs := envcrc.o lib/crc32.o common/env_embedded.o lib/sha1.o
-hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr$(SFX)
-HOSTCFLAGS_gen_eth_addr$(SFX).o := -pedantic
+hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr
+HOSTCFLAGS_gen_eth_addr.o := -pedantic
-hostprogs-$(CONFIG_CMD_LOADS) += img2srec$(SFX)
-HOSTCFLAGS_img2srec$(SFX).o := -pedantic
+hostprogs-$(CONFIG_CMD_LOADS) += img2srec
+HOSTCFLAGS_img2srec.o := -pedantic
-hostprogs-$(CONFIG_XWAY_SWAP_BYTES) += xway-swap-bytes$(SFX)
-HOSTCFLAGS_xway-swap-bytes$(SFX).o := -pedantic
+hostprogs-$(CONFIG_XWAY_SWAP_BYTES) += xway-swap-bytes
+HOSTCFLAGS_xway-swap-bytes.o := -pedantic
-hostprogs-y += mkenvimage$(SFX)
-mkenvimage$(SFX)-objs := crc32.o mkenvimage.o os_support.o
+hostprogs-y += mkenvimage
+mkenvimage-objs := mkenvimage.o os_support.o lib/crc32.o
-hostprogs-y += dumpimage$(SFX) mkimage$(SFX)
-hostprogs-$(CONFIG_FIT_SIGNATURE) += fit_info$(SFX) fit_check_sign$(SFX)
+hostprogs-y += dumpimage mkimage
+hostprogs-$(CONFIG_FIT_SIGNATURE) += fit_info fit_check_sign
-FIT_SIG_OBJS-$(CONFIG_FIT_SIGNATURE) := image-sig.o
+FIT_SIG_OBJS-$(CONFIG_FIT_SIGNATURE) := common/image-sig.o
# Flattened device tree objects
-LIBFDT_OBJS := fdt.o fdt_ro.o fdt_rw.o fdt_strerror.o fdt_wip.o
-RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := rsa-sign.o rsa-verify.o rsa-checksum.o
+LIBFDT_OBJS := $(addprefix lib/libfdt/, \
+ fdt.o fdt_ro.o fdt_rw.o fdt_strerror.o fdt_wip.o)
+RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := $(addprefix lib/rsa/, \
+ rsa-sign.o rsa-verify.o rsa-checksum.o)
# common objs for dumpimage and mkimage
dumpimage-mkimage-objs := aisimage.o \
+ atmelimage.o \
$(FIT_SIG_OBJS-y) \
- crc32.o \
+ common/bootm.o \
+ lib/crc32.o \
default_image.o \
- fdtdec.o \
+ lib/fdtdec_common.o \
+ lib/fdtdec.o \
fit_common.o \
fit_image.o \
gpimage.o \
gpimage-common.o \
- image-fit.o \
+ common/image-fit.o \
image-host.o \
- image.o \
+ common/image.o \
imagetool.o \
imximage.o \
kwbimage.o \
- md5.o \
+ lib/md5.o \
mxsimage.o \
omapimage.o \
os_support.o \
pblimage.o \
- sha1.o \
- sha256.o \
+ pbl_crc32.o \
+ lib/sha1.o \
+ lib/sha256.o \
ublimage.o \
$(LIBFDT_OBJS) \
$(RSA_OBJS-y)
-dumpimage$(SFX)-objs := $(dumpimage-mkimage-objs) dumpimage.o
-mkimage$(SFX)-objs := $(dumpimage-mkimage-objs) mkimage.o
-fit_info$(SFX)-objs := $(dumpimage-mkimage-objs) fit_info.o
-fit_check_sign$(SFX)-objs := $(dumpimage-mkimage-objs) fit_check_sign.o
+dumpimage-objs := $(dumpimage-mkimage-objs) dumpimage.o
+mkimage-objs := $(dumpimage-mkimage-objs) mkimage.o
+fit_info-objs := $(dumpimage-mkimage-objs) fit_info.o
+fit_check_sign-objs := $(dumpimage-mkimage-objs) fit_check_sign.o
# TODO(sjg@chromium.org): Is this correct on Mac OS?
-# MXSImage needs LibSSL
ifneq ($(CONFIG_MX23)$(CONFIG_MX28),)
-HOSTLOADLIBES_dumpimage$(SFX) := -lssl -lcrypto
-HOSTLOADLIBES_mkimage$(SFX) := -lssl -lcrypto
-HOSTLOADLIBES_fit_info$(SFX) := -lssl -lcrypto
-HOSTLOADLIBES_fit_check_sign$(SFX) := -lssl -lcrypto
# Add CONFIG_MXS into host CFLAGS, so we can check whether or not register
# the mxsimage support within tools/mxsimage.c .
HOSTCFLAGS_mxsimage.o += -DCONFIG_MXS
endif
ifdef CONFIG_FIT_SIGNATURE
-HOSTLOADLIBES_dumpimage$(SFX) := -lssl -lcrypto
-HOSTLOADLIBES_mkimage$(SFX) := -lssl -lcrypto
-HOSTLOADLIBES_fit_info$(SFX) := -lssl -lcrypto
-HOSTLOADLIBES_fit_check_sign$(SFX) := -lssl -lcrypto
-
# This affects include/image.h, but including the board config file
# is tricky, so manually define this options here.
HOST_EXTRACFLAGS += -DCONFIG_FIT_SIGNATURE
endif
-hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl$(SFX)
-hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl$(SFX)
-HOSTCFLAGS_mkexynosspl$(SFX).o := -pedantic
+# MXSImage needs LibSSL
+ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CONFIG_FIT_SIGNATURE),)
+HOSTLOADLIBES_mkimage += -lssl -lcrypto
+endif
+
+HOSTLOADLIBES_dumpimage := $(HOSTLOADLIBES_mkimage)
+HOSTLOADLIBES_fit_info := $(HOSTLOADLIBES_mkimage)
+HOSTLOADLIBES_fit_check_sign := $(HOSTLOADLIBES_mkimage)
+
+hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl
+hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl
+HOSTCFLAGS_mkexynosspl.o := -pedantic
-hostprogs-$(CONFIG_MX23) += mxsboot$(SFX)
-hostprogs-$(CONFIG_MX28) += mxsboot$(SFX)
-HOSTCFLAGS_mxsboot$(SFX).o := -pedantic
+hostprogs-$(CONFIG_MX23) += mxsboot
+hostprogs-$(CONFIG_MX28) += mxsboot
+HOSTCFLAGS_mxsboot.o := -pedantic
-hostprogs-$(CONFIG_SUNXI) += mksunxiboot$(SFX)
+hostprogs-$(CONFIG_SUNXI) += mksunxiboot
-hostprogs-$(CONFIG_NETCONSOLE) += ncb$(SFX)
-hostprogs-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1$(SFX)
+hostprogs-$(CONFIG_NETCONSOLE) += ncb
+hostprogs-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1
-ubsha1$(SFX)-objs := os_support.o sha1.o ubsha1.o
+ubsha1-objs := os_support.o ubsha1.o lib/sha1.o
HOSTCFLAGS_ubsha1.o := -pedantic
-hostprogs-$(CONFIG_KIRKWOOD) += kwboot$(SFX)
-hostprogs-y += proftool$(SFX)
-hostprogs-$(CONFIG_STATIC_RELA) += relocate-rela$(SFX)
+hostprogs-$(CONFIG_KIRKWOOD) += kwboot
+hostprogs-y += proftool
+hostprogs-$(CONFIG_STATIC_RELA) += relocate-rela
# We build some files with extra pedantic flags to try to minimize things
# that won't build on some weird host compiler -- though there are lots of
@@ -153,8 +151,16 @@ HOSTCFLAGS_sha1.o := -pedantic
HOSTCFLAGS_sha256.o := -pedantic
# Don't build by default
-#hostprogs-$(CONFIG_PPC) += mpc86x_clk$(SFX)
-#HOSTCFLAGS_mpc86x_clk$(SFX).o := -pedantic
+#hostprogs-$(CONFIG_PPC) += mpc86x_clk
+#HOSTCFLAGS_mpc86x_clk.o := -pedantic
+
+quiet_cmd_wrap = WRAP $@
+cmd_wrap = echo "\#include <$(srctree)/$(patsubst $(obj)/%,%,$@)>" >$@
+
+$(obj)/lib/%.c $(obj)/common/%.c:
+ $(call cmd,wrap)
+
+clean-dirs := lib common
always := $(hostprogs-y)
diff --git a/tools/atmel_pmecc_params.c b/tools/atmel_pmecc_params.c
new file mode 100644
index 0000000..8eaf27f
--- /dev/null
+++ b/tools/atmel_pmecc_params.c
@@ -0,0 +1,51 @@
+/*
+ * (C) Copyright 2014 Andreas Bießmann <andreas.devel@googlemail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+/*
+ * This is a host tool for generating an appropriate string out of board
+ * configuration. The string is required for correct generation of PMECC
+ * header which in turn is required for NAND flash booting of Atmel AT91 style
+ * hardware.
+ *
+ * See doc/README.atmel_pmecc for more information.
+ */
+
+#include <config.h>
+#include <stdlib.h>
+
+static int pmecc_get_ecc_bytes(int cap, int sector_size)
+{
+ int m = 12 + sector_size / 512;
+ return (m * cap + 7) / 8;
+}
+
+int main(int argc, char *argv[])
+{
+ unsigned int use_pmecc = 0;
+ unsigned int sector_per_page;
+ unsigned int sector_size = CONFIG_PMECC_SECTOR_SIZE;
+ unsigned int oob_size = CONFIG_SYS_NAND_OOBSIZE;
+ unsigned int ecc_bits = CONFIG_PMECC_CAP;
+ unsigned int ecc_offset;
+
+#ifdef CONFIG_ATMEL_NAND_HW_PMECC
+ use_pmecc = 1;
+#endif
+
+ sector_per_page = CONFIG_SYS_NAND_PAGE_SIZE / CONFIG_PMECC_SECTOR_SIZE;
+ ecc_offset = oob_size -
+ pmecc_get_ecc_bytes(ecc_bits, sector_size) * sector_per_page;
+
+ printf("usePmecc=%d,", use_pmecc);
+ printf("sectorPerPage=%d,", sector_per_page);
+ printf("sectorSize=%d,", sector_size);
+ printf("spareSize=%d,", oob_size);
+ printf("eccBits=%d,", ecc_bits);
+ printf("eccOffset=%d", ecc_offset);
+ printf("\n");
+
+ exit(EXIT_SUCCESS);
+}
diff --git a/tools/atmelimage.c b/tools/atmelimage.c
new file mode 100644
index 0000000..c8101d2
--- /dev/null
+++ b/tools/atmelimage.c
@@ -0,0 +1,342 @@
+/*
+ * (C) Copyright 2014
+ * Andreas Bießmann <andreas.devel@googlemail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "imagetool.h"
+#include "mkimage.h"
+
+#include <image.h>
+
+#define pr_err(fmt, args...) fprintf(stderr, "atmelimage Error: " fmt, ##args)
+
+static int atmel_check_image_type(uint8_t type)
+{
+ if (type == IH_TYPE_ATMELIMAGE)
+ return EXIT_SUCCESS;
+ else
+ return EXIT_FAILURE;
+}
+
+static uint32_t nand_pmecc_header[52];
+
+/*
+ * A helper struct for parsing the mkimage -n parameter
+ *
+ * Keep in same order as the configs array!
+ */
+static struct pmecc_config {
+ int use_pmecc;
+ int sector_per_page;
+ int spare_size;
+ int ecc_bits;
+ int sector_size;
+ int ecc_offset;
+} pmecc;
+
+/*
+ * Strings used for configure the PMECC header via -n mkimage switch
+ *
+ * We estimate a coma separated list of key=value pairs. The mkimage -n
+ * parameter argument should not contain any whitespace.
+ *
+ * Keep in same order as struct pmecc_config!
+ */
+static const char * const configs[] = {
+ "usePmecc",
+ "sectorPerPage",
+ "spareSize",
+ "eccBits",
+ "sectorSize",
+ "eccOffset"
+};
+
+static int atmel_find_pmecc_parameter_in_token(const char *token)
+{
+ size_t pos;
+ char *param;
+
+ debug("token: '%s'\n", token);
+
+ for (pos = 0; pos < ARRAY_SIZE(configs); pos++) {
+ if (strncmp(token, configs[pos], strlen(configs[pos])) == 0) {
+ param = strstr(token, "=");
+ if (!param)
+ goto err;
+
+ param++;
+ debug("\t%s parameter: '%s'\n", configs[pos], param);
+
+ switch (pos) {
+ case 0:
+ pmecc.use_pmecc = strtol(param, NULL, 10);
+ return EXIT_SUCCESS;
+ case 1:
+ pmecc.sector_per_page = strtol(param, NULL, 10);
+ return EXIT_SUCCESS;
+ case 2:
+ pmecc.spare_size = strtol(param, NULL, 10);
+ return EXIT_SUCCESS;
+ case 3:
+ pmecc.ecc_bits = strtol(param, NULL, 10);
+ return EXIT_SUCCESS;
+ case 4:
+ pmecc.sector_size = strtol(param, NULL, 10);
+ return EXIT_SUCCESS;
+ case 5:
+ pmecc.ecc_offset = strtol(param, NULL, 10);
+ return EXIT_SUCCESS;
+ }
+ }
+ }
+
+err:
+ pr_err("Could not find parameter in token '%s'\n", token);
+ return EXIT_FAILURE;
+}
+
+static int atmel_parse_pmecc_params(char *txt)
+{
+ char *token;
+
+ token = strtok(txt, ",");
+ while (token != NULL) {
+ if (atmel_find_pmecc_parameter_in_token(token))
+ return EXIT_FAILURE;
+
+ token = strtok(NULL, ",");
+ }
+
+ return EXIT_SUCCESS;
+}
+
+static int atmel_verify_header(unsigned char *ptr, int image_size,
+ struct image_tool_params *params)
+{
+ uint32_t *ints = (uint32_t *)ptr;
+ size_t pos;
+ size_t size = image_size;
+
+ /* check if we have an PMECC header attached */
+ for (pos = 0; pos < ARRAY_SIZE(nand_pmecc_header); pos++)
+ if (ints[pos] >> 28 != 0xC)
+ break;
+
+ if (pos == ARRAY_SIZE(nand_pmecc_header)) {
+ ints += ARRAY_SIZE(nand_pmecc_header);
+ size -= sizeof(nand_pmecc_header);
+ }
+
+ /* check the seven interrupt vectors of binary */
+ for (pos = 0; pos < 7; pos++) {
+ debug("atmelimage: interrupt vector #%d is 0x%08X\n", pos+1,
+ ints[pos]);
+ /*
+ * all vectors except the 6'th one must contain valid
+ * LDR or B Opcode
+ */
+ if (pos == 5)
+ /* 6'th vector has image size set, check later */
+ continue;
+ if ((ints[pos] & 0xff000000) == 0xea000000)
+ /* valid B Opcode */
+ continue;
+ if ((ints[pos] & 0xfffff000) == 0xe59ff000)
+ /* valid LDR (I=0, P=1, U=1, B=0, W=0, L=1) */
+ continue;
+ /* ouch, one of the checks has missed ... */
+ return 1;
+ }
+
+ return ints[5] != cpu_to_le32(size);
+}
+
+static void atmel_print_pmecc_header(const uint32_t word)
+{
+ int val;
+
+ printf("\t\tPMECC header\n");
+
+ printf("\t\t====================\n");
+
+ val = (word >> 18) & 0x1ff;
+ printf("\t\teccOffset: %9i\n", val);
+
+ val = (((word >> 16) & 0x3) == 0) ? 512 : 1024;
+ printf("\t\tsectorSize: %8i\n", val);
+
+ if (((word >> 13) & 0x7) <= 2)
+ val = (2 << ((word >> 13) & 0x7));
+ else
+ val = (12 << (((word >> 13) & 0x7) - 3));
+ printf("\t\teccBitReq: %9i\n", val);
+
+ val = (word >> 4) & 0x1ff;
+ printf("\t\tspareSize: %9i\n", val);
+
+ val = (1 << ((word >> 1) & 0x3));
+ printf("\t\tnbSectorPerPage: %3i\n", val);
+
+ printf("\t\tusePmecc: %10i\n", word & 0x1);
+ printf("\t\t====================\n");
+}
+
+static void atmel_print_header(const void *ptr)
+{
+ uint32_t *ints = (uint32_t *)ptr;
+ size_t pos;
+
+ /* check if we have an PMECC header attached */
+ for (pos = 0; pos < ARRAY_SIZE(nand_pmecc_header); pos++)
+ if (ints[pos] >> 28 != 0xC)
+ break;
+
+ if (pos == ARRAY_SIZE(nand_pmecc_header)) {
+ printf("Image Type:\tATMEL ROM-Boot Image with PMECC Header\n");
+ atmel_print_pmecc_header(ints[0]);
+ pos += 5;
+ } else {
+ printf("Image Type:\tATMEL ROM-Boot Image without PMECC Header\n");
+ pos = 5;
+ }
+ printf("\t\t6'th vector has %u set\n", le32_to_cpu(ints[pos]));
+}
+
+static void atmel_set_header(void *ptr, struct stat *sbuf, int ifd,
+ struct image_tool_params *params)
+{
+ /* just save the image size into 6'th interrupt vector */
+ uint32_t *ints = (uint32_t *)ptr;
+ size_t cnt;
+ size_t pos = 5;
+ size_t size = sbuf->st_size;
+
+ for (cnt = 0; cnt < ARRAY_SIZE(nand_pmecc_header); cnt++)
+ if (ints[cnt] >> 28 != 0xC)
+ break;
+
+ if (cnt == ARRAY_SIZE(nand_pmecc_header)) {
+ pos += ARRAY_SIZE(nand_pmecc_header);
+ size -= sizeof(nand_pmecc_header);
+ }
+
+ ints[pos] = cpu_to_le32(size);
+}
+
+static int atmel_check_params(struct image_tool_params *params)
+{
+ if (strlen(params->imagename) > 0)
+ if (atmel_parse_pmecc_params(params->imagename))
+ return EXIT_FAILURE;
+
+ return !(!params->eflag &&
+ !params->fflag &&
+ !params->xflag &&
+ ((params->dflag && !params->lflag) ||
+ (params->lflag && !params->dflag)));
+}
+
+static int atmel_vrec_header(struct image_tool_params *params,
+ struct image_type_params *tparams)
+{
+ uint32_t tmp;
+ size_t pos;
+
+ if (strlen(params->imagename) == 0)
+ return EXIT_SUCCESS;
+
+ tmp = 0xC << 28;
+
+ tmp |= (pmecc.ecc_offset & 0x1ff) << 18;
+
+ switch (pmecc.sector_size) {
+ case 512:
+ tmp |= 0 << 16;
+ break;
+ case 1024:
+ tmp |= 1 << 16;
+ break;
+
+ default:
+ pr_err("Wrong sectorSize (%i) for PMECC header\n",
+ pmecc.sector_size);
+ return EXIT_FAILURE;
+ }
+
+ switch (pmecc.ecc_bits) {
+ case 2:
+ tmp |= 0 << 13;
+ break;
+ case 4:
+ tmp |= 1 << 13;
+ break;
+ case 8:
+ tmp |= 2 << 13;
+ break;
+ case 12:
+ tmp |= 3 << 13;
+ break;
+ case 24:
+ tmp |= 4 << 13;
+ break;
+
+ default:
+ pr_err("Wrong eccBits (%i) for PMECC header\n",
+ pmecc.ecc_bits);
+ return EXIT_FAILURE;
+ }
+
+ tmp |= (pmecc.spare_size & 0x1ff) << 4;
+
+ switch (pmecc.sector_per_page) {
+ case 1:
+ tmp |= 0 << 1;
+ break;
+ case 2:
+ tmp |= 1 << 1;
+ break;
+ case 4:
+ tmp |= 2 << 1;
+ break;
+ case 8:
+ tmp |= 3 << 1;
+ break;
+
+ default:
+ pr_err("Wrong sectorPerPage (%i) for PMECC header\n",
+ pmecc.sector_per_page);
+ return EXIT_FAILURE;
+ }
+
+ if (pmecc.use_pmecc)
+ tmp |= 1;
+
+ for (pos = 0; pos < ARRAY_SIZE(nand_pmecc_header); pos++)
+ nand_pmecc_header[pos] = tmp;
+
+ debug("PMECC header filled 52 times with 0x%08X\n", tmp);
+
+ tparams->header_size = sizeof(nand_pmecc_header);
+ tparams->hdr = nand_pmecc_header;
+
+ return EXIT_SUCCESS;
+}
+
+static struct image_type_params atmelimage_params = {
+ .name = "ATMEL ROM-Boot Image support",
+ .header_size = 0,
+ .hdr = NULL,
+ .check_image_type = atmel_check_image_type,
+ .verify_header = atmel_verify_header,
+ .print_header = atmel_print_header,
+ .set_header = atmel_set_header,
+ .check_params = atmel_check_params,
+ .vrec_header = atmel_vrec_header,
+};
+
+void init_atmel_image_type(void)
+{
+ register_image_type(&atmelimage_params);
+}
diff --git a/tools/buildman/toolchain.py b/tools/buildman/toolchain.py
index b643386..1b9771f 100644
--- a/tools/buildman/toolchain.py
+++ b/tools/buildman/toolchain.py
@@ -66,7 +66,7 @@ class Toolchain:
Returns:
Priority of toolchain, 0=highest, 20=lowest.
"""
- priority_list = ['-elf', '-unknown-linux-gnu', '-linux', '-elf',
+ priority_list = ['-elf', '-unknown-linux-gnu', '-linux',
'-none-linux-gnueabi', '-uclinux', '-none-eabi',
'-gentoo-linux-gnu', '-linux-gnueabi', '-le-linux', '-uclinux']
for prio in range(len(priority_list)):
@@ -103,7 +103,7 @@ class Toolchains:
if not toolchains:
print ("Warning: No tool chains - please add a [toolchain] section"
" to your buildman config file %s. See README for details" %
- config_fname)
+ bsettings.config_fname)
for name, value in toolchains:
if '*' in value:
diff --git a/tools/crc32.c b/tools/crc32.c
deleted file mode 100644
index aed7112..0000000
--- a/tools/crc32.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/crc32.c"
diff --git a/tools/dumpimage.h b/tools/dumpimage.h
index d78523d..e415f14 100644
--- a/tools/dumpimage.h
+++ b/tools/dumpimage.h
@@ -18,7 +18,7 @@
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
-#include <sha1.h>
+#include <u-boot/sha1.h>
#include "fdt_host.h"
#include "imagetool.h"
diff --git a/tools/env_embedded.c b/tools/env_embedded.c
deleted file mode 100644
index 59a6357..0000000
--- a/tools/env_embedded.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../common/env_embedded.c"
diff --git a/tools/fdt.c b/tools/fdt.c
deleted file mode 100644
index 1eafc56..0000000
--- a/tools/fdt.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/libfdt/fdt.c"
diff --git a/tools/fdt_ro.c b/tools/fdt_ro.c
deleted file mode 100644
index 9005fe3..0000000
--- a/tools/fdt_ro.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/libfdt/fdt_ro.c"
diff --git a/tools/fdt_rw.c b/tools/fdt_rw.c
deleted file mode 100644
index adc3fdf..0000000
--- a/tools/fdt_rw.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/libfdt/fdt_rw.c"
diff --git a/tools/fdt_strerror.c b/tools/fdt_strerror.c
deleted file mode 100644
index d0b5822..0000000
--- a/tools/fdt_strerror.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/libfdt/fdt_strerror.c"
diff --git a/tools/fdt_wip.c b/tools/fdt_wip.c
deleted file mode 100644
index 7810f07..0000000
--- a/tools/fdt_wip.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/libfdt/fdt_wip.c"
diff --git a/tools/fdtdec.c b/tools/fdtdec.c
deleted file mode 100644
index f1c2256..0000000
--- a/tools/fdtdec.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/fdtdec.c"
diff --git a/tools/fit_check_sign.c b/tools/fit_check_sign.c
index d6d9340..69e99c0 100644
--- a/tools/fit_check_sign.c
+++ b/tools/fit_check_sign.c
@@ -42,12 +42,13 @@ int main(int argc, char **argv)
void *fit_blob;
char *fdtfile = NULL;
char *keyfile = NULL;
- char cmdname[50];
+ char cmdname[256];
int ret;
void *key_blob;
int c;
- strcpy(cmdname, *argv);
+ strncpy(cmdname, *argv, sizeof(cmdname) - 1);
+ cmdname[sizeof(cmdname) - 1] = '\0';
while ((c = getopt(argc, argv, "f:k:")) != -1)
switch (c) {
case 'f':
@@ -61,20 +62,31 @@ int main(int argc, char **argv)
break;
}
- ffd = mmap_fdt(cmdname, fdtfile, &fit_blob, &fsbuf, 0);
+ if (!fdtfile) {
+ fprintf(stderr, "%s: Missing fdt file\n", *argv);
+ usage(*argv);
+ }
+ if (!keyfile) {
+ fprintf(stderr, "%s: Missing key file\n", *argv);
+ usage(*argv);
+ }
+
+ ffd = mmap_fdt(cmdname, fdtfile, 0, &fit_blob, &fsbuf, false);
if (ffd < 0)
return EXIT_FAILURE;
- kfd = mmap_fdt(cmdname, keyfile, &key_blob, &ksbuf, 0);
+ kfd = mmap_fdt(cmdname, keyfile, 0, &key_blob, &ksbuf, false);
if (ffd < 0)
return EXIT_FAILURE;
image_set_host_blob(key_blob);
ret = fit_check_sign(fit_blob, key_blob);
-
- if (ret)
+ if (!ret) {
ret = EXIT_SUCCESS;
- else
+ fprintf(stderr, "Signature check OK\n");
+ } else {
ret = EXIT_FAILURE;
+ fprintf(stderr, "Signature check Bad (error %d)\n", ret);
+ }
(void) munmap((void *)fit_blob, fsbuf.st_size);
(void) munmap((void *)key_blob, ksbuf.st_size);
diff --git a/tools/fit_common.c b/tools/fit_common.c
index ee1767b..81ba698 100644
--- a/tools/fit_common.c
+++ b/tools/fit_common.c
@@ -38,8 +38,8 @@ int fit_check_image_types(uint8_t type)
return EXIT_FAILURE;
}
-int mmap_fdt(char *cmdname, const char *fname, void **blobp,
- struct stat *sbuf, int useunlink)
+int mmap_fdt(const char *cmdname, const char *fname, size_t size_inc,
+ void **blobp, struct stat *sbuf, bool delete_on_error)
{
void *ptr;
int fd;
@@ -50,17 +50,22 @@ int mmap_fdt(char *cmdname, const char *fname, void **blobp,
if (fd < 0) {
fprintf(stderr, "%s: Can't open %s: %s\n",
cmdname, fname, strerror(errno));
- if (useunlink)
- unlink(fname);
- return -1;
+ goto err;
}
if (fstat(fd, sbuf) < 0) {
fprintf(stderr, "%s: Can't stat %s: %s\n",
cmdname, fname, strerror(errno));
- if (useunlink)
- unlink(fname);
- return -1;
+ goto err;
+ }
+
+ if (size_inc) {
+ sbuf->st_size += size_inc;
+ if (ftruncate(fd, sbuf->st_size)) {
+ fprintf(stderr, "%s: Can't expand %s: %s\n",
+ cmdname, fname, strerror(errno));
+ goto err;
+ }
}
errno = 0;
@@ -68,19 +73,35 @@ int mmap_fdt(char *cmdname, const char *fname, void **blobp,
if ((ptr == MAP_FAILED) || (errno != 0)) {
fprintf(stderr, "%s: Can't read %s: %s\n",
cmdname, fname, strerror(errno));
- if (useunlink)
- unlink(fname);
- return -1;
+ goto err;
}
/* check if ptr has a valid blob */
if (fdt_check_header(ptr)) {
fprintf(stderr, "%s: Invalid FIT blob\n", cmdname);
- if (useunlink)
- unlink(fname);
- return -1;
+ goto err;
+ }
+
+ /* expand if needed */
+ if (size_inc) {
+ int ret;
+
+ ret = fdt_open_into(ptr, ptr, sbuf->st_size);
+ if (ret) {
+ fprintf(stderr, "%s: Cannot expand FDT: %s\n",
+ cmdname, fdt_strerror(ret));
+ goto err;
+ }
}
*blobp = ptr;
return fd;
+
+err:
+ if (fd >= 0)
+ close(fd);
+ if (delete_on_error)
+ unlink(fname);
+
+ return -1;
}
diff --git a/tools/fit_common.h b/tools/fit_common.h
index adf4404..b8d8438 100644
--- a/tools/fit_common.h
+++ b/tools/fit_common.h
@@ -16,7 +16,18 @@ int fit_verify_header(unsigned char *ptr, int image_size,
int fit_check_image_types(uint8_t type);
-int mmap_fdt(char *cmdname, const char *fname, void **blobp,
- struct stat *sbuf, int useunlink);
+/**
+ * Map an FDT into memory, optionally increasing its size
+ *
+ * @cmdname: Tool name (for displaying with error messages)
+ * @fname: Filename containing FDT
+ * @size_inc: Amount to increase size by (0 = leave it alone)
+ * @blobp: Returns pointer to FDT blob
+ * @sbuf: File status information is stored here
+ * @delete_on_error: true to delete the file if we get an error
+ * @return 0 if OK, -1 on error.
+ */
+int mmap_fdt(const char *cmdname, const char *fname, size_t size_inc,
+ void **blobp, struct stat *sbuf, bool delete_on_error);
#endif /* _FIT_COMMON_H_ */
diff --git a/tools/fit_image.c b/tools/fit_image.c
index eeee484..3ececf9 100644
--- a/tools/fit_image.c
+++ b/tools/fit_image.c
@@ -22,6 +22,54 @@
static image_header_t header;
+static int fit_add_file_data(struct image_tool_params *params, size_t size_inc,
+ const char *tmpfile)
+{
+ int tfd, destfd = 0;
+ void *dest_blob = NULL;
+ off_t destfd_size = 0;
+ struct stat sbuf;
+ void *ptr;
+ int ret = 0;
+
+ tfd = mmap_fdt(params->cmdname, tmpfile, size_inc, &ptr, &sbuf, true);
+ if (tfd < 0)
+ return -EIO;
+
+ if (params->keydest) {
+ struct stat dest_sbuf;
+
+ destfd = mmap_fdt(params->cmdname, params->keydest, size_inc,
+ &dest_blob, &dest_sbuf, false);
+ if (destfd < 0) {
+ ret = -EIO;
+ goto err_keydest;
+ }
+ destfd_size = dest_sbuf.st_size;
+ }
+
+ /* for first image creation, add a timestamp at offset 0 i.e., root */
+ if (params->datafile)
+ ret = fit_set_timestamp(ptr, 0, sbuf.st_mtime);
+
+ if (!ret) {
+ ret = fit_add_verification_data(params->keydir, dest_blob, ptr,
+ params->comment,
+ params->require_keys);
+ }
+
+ if (dest_blob) {
+ munmap(dest_blob, destfd_size);
+ close(destfd);
+ }
+
+err_keydest:
+ munmap(ptr, sbuf.st_size);
+ close(tfd);
+
+ return ret;
+}
+
/**
* fit_handle_file - main FIT file processing function
*
@@ -38,11 +86,8 @@ static int fit_handle_file(struct image_tool_params *params)
{
char tmpfile[MKIMAGE_MAX_TMPFILE_LEN];
char cmd[MKIMAGE_MAX_DTC_CMDLINE_LEN];
- int tfd, destfd = 0;
- void *dest_blob = NULL;
- struct stat sbuf;
- void *ptr;
- off_t destfd_size = 0;
+ size_t size_inc;
+ int ret;
/* Flattened Image Tree (FIT) format handling */
debug ("FIT format handling\n");
@@ -73,40 +118,26 @@ static int fit_handle_file(struct image_tool_params *params)
goto err_system;
}
- if (params->keydest) {
- destfd = mmap_fdt(params->cmdname, params->keydest,
- &dest_blob, &sbuf, 1);
- if (destfd < 0)
- goto err_keydest;
- destfd_size = sbuf.st_size;
+ /*
+ * Set hashes for images in the blob. Unfortunately we may need more
+ * space in either FDT, so keep trying until we succeed.
+ *
+ * Note: this is pretty inefficient for signing, since we must
+ * calculate the signature every time. It would be better to calculate
+ * all the data and then store it in a separate step. However, this
+ * would be considerably more complex to implement. Generally a few
+ * steps of this loop is enough to sign with several keys.
+ */
+ for (size_inc = 0; size_inc < 64 * 1024; size_inc += 1024) {
+ ret = fit_add_file_data(params, size_inc, tmpfile);
+ if (!ret || ret != -ENOSPC)
+ break;
}
- tfd = mmap_fdt(params->cmdname, tmpfile, &ptr, &sbuf, 1);
- if (tfd < 0)
- goto err_mmap;
-
- /* set hashes for images in the blob */
- if (fit_add_verification_data(params->keydir,
- dest_blob, ptr, params->comment,
- params->require_keys)) {
+ if (ret) {
fprintf(stderr, "%s Can't add hashes to FIT blob\n",
params->cmdname);
- goto err_add_hashes;
- }
-
- /* for first image creation, add a timestamp at offset 0 i.e., root */
- if (params->datafile && fit_set_timestamp(ptr, 0, sbuf.st_mtime)) {
- fprintf (stderr, "%s: Can't add image timestamp\n",
- params->cmdname);
- goto err_add_timestamp;
- }
- debug ("Added timestamp successfully\n");
-
- munmap ((void *)ptr, sbuf.st_size);
- close (tfd);
- if (dest_blob) {
- munmap(dest_blob, destfd_size);
- close(destfd);
+ goto err_system;
}
if (rename (tmpfile, params->imagefile) == -1) {
@@ -115,17 +146,10 @@ static int fit_handle_file(struct image_tool_params *params)
strerror (errno));
unlink (tmpfile);
unlink (params->imagefile);
- return (EXIT_FAILURE);
+ return EXIT_FAILURE;
}
- return (EXIT_SUCCESS);
+ return EXIT_SUCCESS;
-err_add_timestamp:
-err_add_hashes:
- munmap(ptr, sbuf.st_size);
-err_mmap:
- if (dest_blob)
- munmap(dest_blob, destfd_size);
-err_keydest:
err_system:
unlink(tmpfile);
return -1;
diff --git a/tools/fit_info.c b/tools/fit_info.c
index 50f3c8e..481ac6d 100644
--- a/tools/fit_info.c
+++ b/tools/fit_info.c
@@ -68,7 +68,19 @@ int main(int argc, char **argv)
break;
}
- ffd = mmap_fdt(cmdname, fdtfile, &fit_blob, &fsbuf, 0);
+ if (!fdtfile) {
+ fprintf(stderr, "%s: Missing fdt file\n", *argv);
+ usage(*argv);
+ }
+ if (!nodename) {
+ fprintf(stderr, "%s: Missing node name\n", *argv);
+ usage(*argv);
+ }
+ if (!propertyname) {
+ fprintf(stderr, "%s: Missing property name\n", *argv);
+ usage(*argv);
+ }
+ ffd = mmap_fdt(cmdname, fdtfile, 0, &fit_blob, &fsbuf, false);
if (ffd < 0) {
printf("Could not open %s\n", fdtfile);
diff --git a/tools/image-fit.c b/tools/image-fit.c
deleted file mode 100644
index 037e5cc..0000000
--- a/tools/image-fit.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../common/image-fit.c"
diff --git a/tools/image-host.c b/tools/image-host.c
index 651f1c2..0eff720 100644
--- a/tools/image-host.c
+++ b/tools/image-host.c
@@ -10,6 +10,7 @@
*/
#include "mkimage.h"
+#include <bootm.h>
#include <image.h>
#include <version.h>
@@ -224,7 +225,9 @@ static int fit_image_process_sig(const char *keydir, void *keydest,
ret = fit_image_write_sig(fit, noffset, value, value_len, comment,
NULL, 0);
if (ret) {
- printf("Can't write signature for '%s' signature node in '%s' image node: %s\n",
+ if (ret == -FDT_ERR_NOSPACE)
+ return -ENOSPC;
+ printf("Can't write signature for '%s' signature node in '%s' conf node: %s\n",
node_name, image_name, fdt_strerror(ret));
return -1;
}
@@ -589,10 +592,13 @@ static int fit_config_process_sig(const char *keydir, void *keydest,
return -1;
}
- if (fit_image_write_sig(fit, noffset, value, value_len, comment,
- region_prop, region_proplen)) {
- printf("Can't write signature for '%s' signature node in '%s' conf node\n",
- node_name, conf_name);
+ ret = fit_image_write_sig(fit, noffset, value, value_len, comment,
+ region_prop, region_proplen);
+ if (ret) {
+ if (ret == -FDT_ERR_NOSPACE)
+ return -ENOSPC;
+ printf("Can't write signature for '%s' signature node in '%s' conf node: %s\n",
+ node_name, conf_name, fdt_strerror(ret));
return -1;
}
free(value);
@@ -602,10 +608,15 @@ static int fit_config_process_sig(const char *keydir, void *keydest,
info.keyname = fdt_getprop(fit, noffset, "key-name-hint", NULL);
/* Write the public key into the supplied FDT file */
- if (keydest && info.algo->add_verify_data(&info, keydest)) {
- printf("Failed to add verification data for '%s' signature node in '%s' image node\n",
- node_name, conf_name);
- return -1;
+ if (keydest) {
+ ret = info.algo->add_verify_data(&info, keydest);
+ if (ret == -ENOSPC)
+ return -ENOSPC;
+ if (ret) {
+ printf("Failed to add verification data for '%s' signature node in '%s' image node\n",
+ node_name, conf_name);
+ }
+ return ret;
}
return 0;
@@ -697,16 +708,21 @@ int fit_add_verification_data(const char *keydir, void *keydest, void *fit,
}
#ifdef CONFIG_FIT_SIGNATURE
-int fit_check_sign(const void *working_fdt, const void *key)
+int fit_check_sign(const void *fit, const void *key)
{
int cfg_noffset;
int ret;
- cfg_noffset = fit_conf_get_node(working_fdt, NULL);
+ cfg_noffset = fit_conf_get_node(fit, NULL);
if (!cfg_noffset)
return -1;
- ret = fit_config_verify(working_fdt, cfg_noffset);
+ printf("Verifying Hash Integrity ... ");
+ ret = fit_config_verify(fit, cfg_noffset);
+ if (ret)
+ return ret;
+ ret = bootm_host_load_images(fit, cfg_noffset);
+
return ret;
}
#endif
diff --git a/tools/image-sig.c b/tools/image-sig.c
deleted file mode 100644
index e45419f..0000000
--- a/tools/image-sig.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../common/image-sig.c"
diff --git a/tools/image.c b/tools/image.c
deleted file mode 100644
index 0f9bacc..0000000
--- a/tools/image.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../common/image.c"
diff --git a/tools/imagetool.c b/tools/imagetool.c
index da72115..32d6278 100644
--- a/tools/imagetool.c
+++ b/tools/imagetool.c
@@ -27,6 +27,8 @@ void register_image_tool(imagetool_register_t image_register)
*/
register_func = image_register;
+ /* Init ATMEL ROM Boot Image generation/list support */
+ init_atmel_image_type();
/* Init Freescale PBL Boot image generation/list support */
init_pbl_image_type();
/* Init Kirkwood Boot image generation/list support */
diff --git a/tools/imagetool.h b/tools/imagetool.h
index a3e9d30..c8af0e8 100644
--- a/tools/imagetool.h
+++ b/tools/imagetool.h
@@ -18,7 +18,7 @@
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
-#include <sha1.h>
+#include <u-boot/sha1.h>
#include "fdt_host.h"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
@@ -159,6 +159,7 @@ void register_image_type(struct image_type_params *tparams);
* Supported image types init functions
*/
void init_default_image_type(void);
+void init_atmel_image_type(void);
void init_pbl_image_type(void);
void init_ais_image_type(void);
void init_kwb_image_type(void);
diff --git a/tools/md5.c b/tools/md5.c
deleted file mode 100644
index befaa32..0000000
--- a/tools/md5.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/md5.c"
diff --git a/tools/mkimage.h b/tools/mkimage.h
index d5491b6..3f369b7 100644
--- a/tools/mkimage.h
+++ b/tools/mkimage.h
@@ -18,7 +18,7 @@
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
-#include <sha1.h>
+#include <u-boot/sha1.h>
#include "fdt_host.h"
#include "imagetool.h"
diff --git a/tools/mxsimage.c b/tools/mxsimage.c
index 045b35a..81c7f2d 100644
--- a/tools/mxsimage.c
+++ b/tools/mxsimage.c
@@ -19,6 +19,7 @@
#include "imagetool.h"
#include "mxsimage.h"
+#include "pbl_crc32.h"
#include <image.h>
@@ -231,29 +232,6 @@ static int sb_aes_reinit(struct sb_image_ctx *ictx, int enc)
}
/*
- * CRC32
- */
-static uint32_t crc32(uint8_t *data, uint32_t len)
-{
- const uint32_t poly = 0x04c11db7;
- uint32_t crc32 = 0xffffffff;
- unsigned int byte, bit;
-
- for (byte = 0; byte < len; byte++) {
- crc32 ^= data[byte] << 24;
-
- for (bit = 8; bit > 0; bit--) {
- if (crc32 & (1UL << 31))
- crc32 = (crc32 << 1) ^ poly;
- else
- crc32 = (crc32 << 1);
- }
- }
-
- return crc32;
-}
-
-/*
* Debug
*/
static void soprintf(struct sb_image_ctx *ictx, const char *fmt, ...)
@@ -998,7 +976,9 @@ static int sb_build_command_load(struct sb_image_ctx *ictx,
ccmd->load.address = dest;
ccmd->load.count = cctx->length;
- ccmd->load.crc32 = crc32(cctx->data, cctx->length);
+ ccmd->load.crc32 = pbl_crc32(0,
+ (const char *)cctx->data,
+ cctx->length);
cctx->size = sizeof(*ccmd) + cctx->length;
@@ -1834,7 +1814,9 @@ static int sb_verify_command(struct sb_image_ctx *ictx,
EVP_DigestUpdate(&ictx->md_ctx, cctx->data, asize);
sb_aes_crypt(ictx, cctx->data, cctx->data, asize);
- if (ccmd->load.crc32 != crc32(cctx->data, asize)) {
+ if (ccmd->load.crc32 != pbl_crc32(0,
+ (const char *)cctx->data,
+ asize)) {
fprintf(stderr,
"ERR: SB LOAD command payload CRC32 invalid!\n");
return -EINVAL;
diff --git a/tools/patman/gitutil.py b/tools/patman/gitutil.py
index 3ea256d..7b75c83 100644
--- a/tools/patman/gitutil.py
+++ b/tools/patman/gitutil.py
@@ -232,6 +232,10 @@ def ApplyPatches(verbose, args, start_point):
print stdout
return False
old_head = stdout.splitlines()[0]
+ if old_head == 'undefined':
+ str = "Invalid HEAD '%s'" % stdout.strip()
+ print col.Color(col.RED, str)
+ return False
# Checkout the required start point
cmd = ['git', 'checkout', 'HEAD~%d' % start_point]
diff --git a/tools/pbl_crc32.c b/tools/pbl_crc32.c
new file mode 100644
index 0000000..6e6735a
--- /dev/null
+++ b/tools/pbl_crc32.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ *
+ * Cleaned up and refactored by Charles Manning.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+#include "pblimage.h"
+
+static uint32_t crc_table[256];
+static int crc_table_valid;
+
+static void make_crc_table(void)
+{
+ uint32_t mask;
+ int i, j;
+ uint32_t poly; /* polynomial exclusive-or pattern */
+
+ if (crc_table_valid)
+ return;
+
+ /*
+ * the polynomial used by PBL is 1 + x1 + x2 + x4 + x5 + x7 + x8 + x10
+ * + x11 + x12 + x16 + x22 + x23 + x26 + x32.
+ */
+ poly = 0x04c11db7;
+
+ for (i = 0; i < 256; i++) {
+ mask = i << 24;
+ for (j = 0; j < 8; j++) {
+ if (mask & 0x80000000)
+ mask = (mask << 1) ^ poly;
+ else
+ mask <<= 1;
+ }
+ crc_table[i] = mask;
+ }
+
+ crc_table_valid = 1;
+}
+
+uint32_t pbl_crc32(uint32_t in_crc, const char *buf, uint32_t len)
+{
+ uint32_t crc32_val;
+ int i;
+
+ make_crc_table();
+
+ crc32_val = ~in_crc;
+
+ for (i = 0; i < len; i++)
+ crc32_val = (crc32_val << 8) ^
+ crc_table[(crc32_val >> 24) ^ (*buf++ & 0xff)];
+
+ return crc32_val;
+}
diff --git a/tools/pbl_crc32.h b/tools/pbl_crc32.h
new file mode 100644
index 0000000..4ab55ee
--- /dev/null
+++ b/tools/pbl_crc32.h
@@ -0,0 +1,13 @@
+/*
+ * Copyright 2012 Freescale Semiconductor, Inc.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef PBLCRC32_H
+#define PBLCRC32_H
+
+#include <stdint.h>
+uint32_t pbl_crc32(uint32_t in_crc, const char *buf, uint32_t len);
+
+#endif
diff --git a/tools/pblimage.c b/tools/pblimage.c
index ef3d7f6..6e6e801 100644
--- a/tools/pblimage.c
+++ b/tools/pblimage.c
@@ -6,6 +6,7 @@
#include "imagetool.h"
#include <image.h>
#include "pblimage.h"
+#include "pbl_crc32.h"
/*
* Initialize to an invalid value.
@@ -137,52 +138,6 @@ static void pbl_parser(char *name)
fclose(fd);
}
-static uint32_t crc_table[256];
-
-static void make_crc_table(void)
-{
- uint32_t mask;
- int i, j;
- uint32_t poly; /* polynomial exclusive-or pattern */
-
- /*
- * the polynomial used by PBL is 1 + x1 + x2 + x4 + x5 + x7 + x8 + x10
- * + x11 + x12 + x16 + x22 + x23 + x26 + x32.
- */
- poly = 0x04c11db7;
-
- for (i = 0; i < 256; i++) {
- mask = i << 24;
- for (j = 0; j < 8; j++) {
- if (mask & 0x80000000)
- mask = (mask << 1) ^ poly;
- else
- mask <<= 1;
- }
- crc_table[i] = mask;
- }
-}
-
-unsigned long pbl_crc32(unsigned long crc, const char *buf, uint32_t len)
-{
- uint32_t crc32_val = 0xffffffff;
- uint32_t xor = 0x0;
- int i;
-
- make_crc_table();
-
- for (i = 0; i < len; i++)
- crc32_val = (crc32_val << 8) ^
- crc_table[(crc32_val >> 24) ^ (*buf++ & 0xff)];
-
- crc32_val = crc32_val ^ xor;
- if (crc32_val < 0) {
- crc32_val += 0xffffffff;
- crc32_val += 1;
- }
- return crc32_val;
-}
-
static uint32_t reverse_byte(uint32_t val)
{
uint32_t temp;
diff --git a/tools/rsa-checksum.c b/tools/rsa-checksum.c
deleted file mode 100644
index 09033e6..0000000
--- a/tools/rsa-checksum.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/rsa/rsa-checksum.c"
diff --git a/tools/rsa-sign.c b/tools/rsa-sign.c
deleted file mode 100644
index 150bbe1..0000000
--- a/tools/rsa-sign.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/rsa/rsa-sign.c"
diff --git a/tools/rsa-verify.c b/tools/rsa-verify.c
deleted file mode 100644
index bb662a1..0000000
--- a/tools/rsa-verify.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/rsa/rsa-verify.c"
diff --git a/tools/sha1.c b/tools/sha1.c
deleted file mode 100644
index 0d717df..0000000
--- a/tools/sha1.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/sha1.c"
diff --git a/tools/sha256.c b/tools/sha256.c
deleted file mode 100644
index 8ca931f..0000000
--- a/tools/sha256.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "../lib/sha256.c"
diff --git a/tools/ubsha1.c b/tools/ubsha1.c
index 1041588..4a17246 100644
--- a/tools/ubsha1.c
+++ b/tools/ubsha1.c
@@ -13,7 +13,7 @@
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
-#include "sha1.h"
+#include <u-boot/sha1.h>
int main (int argc, char **argv)
{