aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorTom Rini <trini@ti.com>2014-05-30 11:34:39 -0400
committerTom Rini <trini@ti.com>2014-05-30 11:34:39 -0400
commit90b51c33f362926e17d4c07dcef1ce822abaa89f (patch)
tree9eb339bb2b864bfac2434d0cd808301506e9bb82 /tools
parent95856248ca93b9048d87264fbef67ca382975650 (diff)
parent9637a1bb896efe392a58dd2772e2c3fcb646409d (diff)
Merge branch 'master' of git://git.denx.de/u-boot-arm
Diffstat (limited to 'tools')
-rw-r--r--tools/.gitignore1
-rw-r--r--tools/Makefile5
-rw-r--r--tools/atmel_pmecc_params.c51
-rw-r--r--tools/atmelimage.c342
-rw-r--r--tools/imagetool.c2
-rw-r--r--tools/imagetool.h1
-rw-r--r--tools/mksunxiboot.c142
7 files changed, 544 insertions, 0 deletions
diff --git a/tools/.gitignore b/tools/.gitignore
index b1e997fc3e..725db906e8 100644
--- a/tools/.gitignore
+++ b/tools/.gitignore
@@ -11,6 +11,7 @@
/mkexynosspl
/mpc86x_clk
/mxsboot
+/mksunxiboot
/ncb
/proftool
/relocate-rela
diff --git a/tools/Makefile b/tools/Makefile
index 6e43a0150d..761055764b 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -38,6 +38,8 @@ 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$(SFX)
+
# TODO: CONFIG_CMD_LICENSE does not work
hostprogs-$(CONFIG_CMD_LICENSE) += bin2header$(SFX)
hostprogs-$(CONFIG_LCD_LOGO) += bmp_logo$(SFX)
@@ -69,6 +71,7 @@ RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := 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 \
default_image.o \
@@ -131,6 +134,8 @@ hostprogs-$(CONFIG_MX23) += mxsboot$(SFX)
hostprogs-$(CONFIG_MX28) += mxsboot$(SFX)
HOSTCFLAGS_mxsboot$(SFX).o := -pedantic
+hostprogs-$(CONFIG_SUNXI) += mksunxiboot$(SFX)
+
hostprogs-$(CONFIG_NETCONSOLE) += ncb$(SFX)
hostprogs-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1$(SFX)
diff --git a/tools/atmel_pmecc_params.c b/tools/atmel_pmecc_params.c
new file mode 100644
index 0000000000..8eaf27f804
--- /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 0000000000..c8101d2ddc
--- /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/imagetool.c b/tools/imagetool.c
index da72115e53..32d6278edb 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 a3e9d302eb..c480687ec1 100644
--- a/tools/imagetool.h
+++ b/tools/imagetool.h
@@ -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/mksunxiboot.c b/tools/mksunxiboot.c
new file mode 100644
index 0000000000..da7c9f0ddc
--- /dev/null
+++ b/tools/mksunxiboot.c
@@ -0,0 +1,142 @@
+/*
+ * (C) Copyright 2007-2011
+ * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
+ * Tom Cubie <tangliang@allwinnertech.com>
+ *
+ * a simple tool to generate bootable image for sunxi platform.
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+/* boot head definition from sun4i boot code */
+struct boot_file_head {
+ uint32_t b_instruction; /* one intruction jumping to real code */
+ uint8_t magic[8]; /* ="eGON.BT0" or "eGON.BT1", not C-style str */
+ uint32_t check_sum; /* generated by PC */
+ uint32_t length; /* generated by PC */
+ /*
+ * We use a simplified header, only filling in what is needed
+ * by the boot ROM. To be compatible with Allwinner tools we
+ * would need to implement the proper fields here instead of
+ * padding.
+ */
+ uint8_t pad[12]; /* align to 32 bytes */
+};
+
+#define BOOT0_MAGIC "eGON.BT0"
+#define STAMP_VALUE 0x5F0A6C39
+
+/* check sum functon from sun4i boot code */
+int gen_check_sum(struct boot_file_head *head_p)
+{
+ uint32_t length;
+ uint32_t *buf;
+ uint32_t loop;
+ uint32_t i;
+ uint32_t sum;
+
+ length = head_p->length;
+ if ((length & 0x3) != 0) /* must 4-byte-aligned */
+ return -1;
+ buf = (uint32_t *)head_p;
+ head_p->check_sum = STAMP_VALUE; /* fill stamp */
+ loop = length >> 2;
+
+ /* calculate the sum */
+ for (i = 0, sum = 0; i < loop; i++)
+ sum += buf[i];
+
+ /* write back check sum */
+ head_p->check_sum = sum;
+
+ return 0;
+}
+
+#define ALIGN(x, a) __ALIGN_MASK((x), (typeof(x))(a)-1)
+#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
+
+#define SUN4I_SRAM_SIZE 0x7600 /* 0x7748+ is used by BROM */
+#define SRAM_LOAD_MAX_SIZE (SUN4I_SRAM_SIZE - sizeof(struct boot_file_head))
+#define BLOCK_SIZE 512
+
+struct boot_img {
+ struct boot_file_head header;
+ char code[SRAM_LOAD_MAX_SIZE];
+ char pad[BLOCK_SIZE];
+};
+
+int main(int argc, char *argv[])
+{
+ int fd_in, fd_out;
+ struct boot_img img;
+ unsigned file_size, load_size;
+ int count;
+
+ if (argc < 2) {
+ printf("\tThis program makes an input bin file to sun4i " \
+ "bootable image.\n" \
+ "\tUsage: %s input_file out_putfile\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ fd_in = open(argv[1], O_RDONLY);
+ if (fd_in < 0) {
+ perror("Open input file");
+ return EXIT_FAILURE;
+ }
+
+ memset(img.pad, 0, BLOCK_SIZE);
+
+ /* get input file size */
+ file_size = lseek(fd_in, 0, SEEK_END);
+
+ if (file_size > SRAM_LOAD_MAX_SIZE) {
+ fprintf(stderr, "ERROR: File too large!\n");
+ return EXIT_FAILURE;
+ } else {
+ load_size = ALIGN(file_size, sizeof(int));
+ }
+
+ fd_out = open(argv[2], O_WRONLY | O_CREAT, 0666);
+ if (fd_out < 0) {
+ perror("Open output file");
+ return EXIT_FAILURE;
+ }
+
+ /* read file to buffer to calculate checksum */
+ lseek(fd_in, 0, SEEK_SET);
+ count = read(fd_in, img.code, load_size);
+ if (count != load_size) {
+ perror("Reading input image");
+ return EXIT_FAILURE;
+ }
+
+ /* fill the header */
+ img.header.b_instruction = /* b instruction */
+ 0xEA000000 | /* jump to the first instr after the header */
+ ((sizeof(struct boot_file_head) / sizeof(int) - 2)
+ & 0x00FFFFFF);
+ memcpy(img.header.magic, BOOT0_MAGIC, 8); /* no '0' termination */
+ img.header.length =
+ ALIGN(load_size + sizeof(struct boot_file_head), BLOCK_SIZE);
+ gen_check_sum(&img.header);
+
+ count = write(fd_out, &img, img.header.length);
+ if (count != img.header.length) {
+ perror("Writing output");
+ return EXIT_FAILURE;
+ }
+
+ close(fd_in);
+ close(fd_out);
+
+ return EXIT_SUCCESS;
+}