[U-Boot] [PATCH v6 7/8] lpc32xx: add lpc32xx-spl.bin boot image target
Albert ARIBAUD (3ADEV)
albert.aribaud at 3adev.fr
Wed Mar 18 10:04:50 CET 2015
Signed-off-by: Albert ARIBAUD (3ADEV) <albert.aribaud at 3adev.fr>
---
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3:
- remove script/Makefile.spl change
Changes in v2:
- move boot image generation to mkimage framework
common/image.c | 1 +
include/image.h | 1 +
tools/Makefile | 1 +
tools/lpc32xximage.c | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 181 insertions(+)
create mode 100644 tools/lpc32xximage.c
diff --git a/common/image.c b/common/image.c
index a911aa9..162b682 100644
--- a/common/image.c
+++ b/common/image.c
@@ -149,6 +149,7 @@ static const table_entry_t uimage_type[] = {
{ IH_TYPE_MXSIMAGE, "mxsimage", "Freescale MXS Boot Image",},
{ IH_TYPE_ATMELIMAGE, "atmelimage", "ATMEL ROM-Boot Image",},
{ IH_TYPE_X86_SETUP, "x86_setup", "x86 setup.bin", },
+ { IH_TYPE_LPC32XXIMAGE, "lpc32xximage", "LPC32XX Boot Image", },
{ -1, "", "", },
};
diff --git a/include/image.h b/include/image.h
index 0e6af00..3844be6 100644
--- a/include/image.h
+++ b/include/image.h
@@ -242,6 +242,7 @@ struct lmb;
#define IH_TYPE_ATMELIMAGE 18 /* ATMEL ROM bootable Image */
#define IH_TYPE_SOCFPGAIMAGE 19 /* Altera SOCFPGA Preloader */
#define IH_TYPE_X86_SETUP 20 /* x86 setup.bin Image */
+#define IH_TYPE_LPC32XXIMAGE 21 /* x86 setup.bin Image */
/*
* Compression Types
diff --git a/tools/Makefile b/tools/Makefile
index 88770b0..4bbb153 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -83,6 +83,7 @@ dumpimage-mkimage-objs := aisimage.o \
imximage.o \
kwbimage.o \
lib/md5.o \
+ lpc32xximage.o \
mxsimage.o \
omapimage.o \
os_support.o \
diff --git a/tools/lpc32xximage.c b/tools/lpc32xximage.c
new file mode 100644
index 0000000..6b3865f
--- /dev/null
+++ b/tools/lpc32xximage.c
@@ -0,0 +1,178 @@
+/*
+ * Image manipulator for LPC32XX SoCs
+ *
+ * (C) Copyright 2015 DENX Software Engineering GmbH
+ * Written-by: Albert ARIBAUD <albert.aribaud at 3adev.fr>
+ *
+ * Derived from omapimage.c:
+ *
+ * (C) Copyright 2010
+ * Linaro LTD, www.linaro.org
+ * Author: John Rigby <john.rigby at linaro.org>
+ * Based on TI's signGP.c
+ *
+ * (C) Copyright 2009
+ * Stefano Babic, DENX Software Engineering, sbabic at denx.de.
+ *
+ * (C) Copyright 2008
+ * Marvell Semiconductor <www.marvell.com>
+ * Written-by: Prafulla Wadaskar <prafulla at marvell.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include "imagetool.h"
+#include <compiler.h>
+#include <image.h>
+
+/*
+ * NAND page 0 boot header
+ */
+
+struct nand_page_0_boot_header {
+ uint32_t data[129];
+ uint32_t pad[383];
+};
+
+/*
+ * Default ICC (interface configuration data [sic]) if none specified
+ * in board config
+ */
+
+#ifndef LPC32XX_BOOT_ICR
+#define LPC32XX_BOOT_ICR 0x00000096
+#endif
+
+/*
+ * Default boot NAND page size if none specified in board config
+ */
+
+#ifndef LPC32XX_BOOT_NAND_PAGESIZE
+#define LPC32XX_BOOT_NAND_PAGESIZE 2048
+#endif
+
+/*
+ * Default boot NAND pages per sector if none specified in board config
+ */
+
+#ifndef LPC32XX_BOOT_NAND_PAGES_PER_SECTOR
+#define LPC32XX_BOOT_NAND_PAGES_PER_SECTOR 64
+#endif
+
+/*
+ * Maximum size for boot code is 56K unless defined in board config
+ */
+
+#ifndef LPC32XX_BOOT_CODESIZE
+#define LPC32XX_BOOT_CODESIZE (56*1024)
+#endif
+
+/* signature byte for a readable block */
+
+#define LPC32XX_BOOT_BLOCK_OK 0xaa
+
+static struct nand_page_0_boot_header lpc32xximage_header;
+
+static int lpc32xximage_check_image_types(uint8_t type)
+{
+ if (type == IH_TYPE_LPC32XXIMAGE)
+ return EXIT_SUCCESS;
+ return EXIT_FAILURE;
+}
+
+static int lpc32xximage_verify_header(unsigned char *ptr, int image_size,
+ struct image_tool_params *params)
+{
+ struct nand_page_0_boot_header *hdr =
+ (struct nand_page_0_boot_header *)ptr;
+
+ /* turn image size from bytes to NAND pages, page 0 included */
+ int image_size_in_pages = ((image_size - 1)
+ / LPC32XX_BOOT_NAND_PAGESIZE);
+
+ if (hdr->data[0] != (0xff & LPC32XX_BOOT_ICR))
+ return -1;
+ if (hdr->data[1] != (0xff & ~LPC32XX_BOOT_ICR))
+ return -1;
+ if (hdr->data[2] != (0xff & LPC32XX_BOOT_ICR))
+ return -1;
+ if (hdr->data[3] != (0xff & ~LPC32XX_BOOT_ICR))
+ return -1;
+ if (hdr->data[4] != (0xff & image_size_in_pages))
+ return -1;
+ if (hdr->data[5] != (0xff & ~image_size_in_pages))
+ return -1;
+ if (hdr->data[6] != (0xff & image_size_in_pages))
+ return -1;
+ if (hdr->data[7] != (0xff & ~image_size_in_pages))
+ return -1;
+ if (hdr->data[8] != (0xff & image_size_in_pages))
+ return -1;
+ if (hdr->data[9] != (0xff & ~image_size_in_pages))
+ return -1;
+ if (hdr->data[10] != (0xff & image_size_in_pages))
+ return -1;
+ if (hdr->data[11] != (0xff & ~image_size_in_pages))
+ return -1;
+ if (hdr->data[12] != LPC32XX_BOOT_BLOCK_OK)
+ return -1;
+ if (hdr->data[128] != LPC32XX_BOOT_BLOCK_OK)
+ return -1;
+ return 0;
+}
+
+static void print_hdr_byte(struct nand_page_0_boot_header *hdr, int ofs)
+{
+ printf("header[%d] = %02x\n", ofs, hdr->data[ofs]);
+}
+
+static void lpc32xximage_print_header(const void *ptr)
+{
+ struct nand_page_0_boot_header *hdr =
+ (struct nand_page_0_boot_header *)ptr;
+ int ofs;
+
+ for (ofs = 0; ofs <= 12; ofs++)
+ print_hdr_byte(hdr, ofs);
+ print_hdr_byte(hdr, 128);
+}
+
+static void lpc32xximage_set_header(void *ptr, struct stat *sbuf, int ifd,
+ struct image_tool_params *params)
+{
+ struct nand_page_0_boot_header *hdr =
+ (struct nand_page_0_boot_header *)ptr;
+
+ /* turn image size from bytes to NAND pages, page 0 included */
+ int image_size_in_pages = ((sbuf->st_size
+ + LPC32XX_BOOT_NAND_PAGESIZE - 1)
+ / LPC32XX_BOOT_NAND_PAGESIZE);
+
+ /* fill header -- default byte value is 0x00, not 0xFF */
+ memset((void *)hdr, 0, sizeof(*hdr));
+ hdr->data[0] = (hdr->data[2] = 0xff & LPC32XX_BOOT_ICR);
+ hdr->data[1] = (hdr->data[3] = 0xff & ~LPC32XX_BOOT_ICR);
+ hdr->data[4] = (hdr->data[6] = (hdr->data[8]
+ = (hdr->data[10] = 0xff & image_size_in_pages)));
+ hdr->data[5] = (hdr->data[7] = (hdr->data[9]
+ = (hdr->data[11] = 0xff & ~image_size_in_pages)));
+ hdr->data[12] = (hdr->data[128] = LPC32XX_BOOT_BLOCK_OK);
+}
+
+/*
+ * lpc32xximage parameters
+ */
+U_BOOT_IMAGE_TYPE(
+ lpc32xximage,
+ "LPC32XX Boot Image",
+ sizeof(lpc32xximage_header),
+ (void *)&lpc32xximage_header,
+ NULL,
+ lpc32xximage_verify_header,
+ lpc32xximage_print_header,
+ lpc32xximage_set_header,
+ NULL,
+ lpc32xximage_check_image_types,
+ NULL,
+ NULL
+);
--
2.1.0
More information about the U-Boot
mailing list