2 * Image manipulator for LPC32XX SoCs
4 * (C) Copyright 2015 DENX Software Engineering GmbH
5 * Written-by: Albert ARIBAUD <albert.aribaud@3adev.fr>
7 * Derived from omapimage.c:
10 * Linaro LTD, www.linaro.org
11 * Author: John Rigby <john.rigby@linaro.org>
12 * Based on TI's signGP.c
15 * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
18 * Marvell Semiconductor <www.marvell.com>
19 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
21 * SPDX-License-Identifier: GPL-2.0+
24 #include "imagetool.h"
29 * NAND page 0 boot header
32 struct nand_page_0_boot_header
{
38 * Default ICC (interface configuration data [sic]) if none specified
42 #ifndef LPC32XX_BOOT_ICR
43 #define LPC32XX_BOOT_ICR 0x00000096
47 * Default boot NAND page size if none specified in board config
50 #ifndef LPC32XX_BOOT_NAND_PAGESIZE
51 #define LPC32XX_BOOT_NAND_PAGESIZE 2048
55 * Default boot NAND pages per sector if none specified in board config
58 #ifndef LPC32XX_BOOT_NAND_PAGES_PER_SECTOR
59 #define LPC32XX_BOOT_NAND_PAGES_PER_SECTOR 64
63 * Maximum size for boot code is 56K unless defined in board config
66 #ifndef LPC32XX_BOOT_CODESIZE
67 #define LPC32XX_BOOT_CODESIZE (56*1024)
70 /* signature byte for a readable block */
72 #define LPC32XX_BOOT_BLOCK_OK 0xaa
74 static struct nand_page_0_boot_header lpc32xximage_header
;
76 static int lpc32xximage_check_image_types(uint8_t type
)
78 if (type
== IH_TYPE_LPC32XXIMAGE
)
83 static int lpc32xximage_verify_header(unsigned char *ptr
, int image_size
,
84 struct image_tool_params
*params
)
86 struct nand_page_0_boot_header
*hdr
=
87 (struct nand_page_0_boot_header
*)ptr
;
89 /* turn image size from bytes to NAND pages, page 0 included */
90 int image_size_in_pages
= ((image_size
- 1)
91 / LPC32XX_BOOT_NAND_PAGESIZE
);
93 if (hdr
->data
[0] != (0xff & LPC32XX_BOOT_ICR
))
95 if (hdr
->data
[1] != (0xff & ~LPC32XX_BOOT_ICR
))
97 if (hdr
->data
[2] != (0xff & LPC32XX_BOOT_ICR
))
99 if (hdr
->data
[3] != (0xff & ~LPC32XX_BOOT_ICR
))
101 if (hdr
->data
[4] != (0xff & image_size_in_pages
))
103 if (hdr
->data
[5] != (0xff & ~image_size_in_pages
))
105 if (hdr
->data
[6] != (0xff & image_size_in_pages
))
107 if (hdr
->data
[7] != (0xff & ~image_size_in_pages
))
109 if (hdr
->data
[8] != (0xff & image_size_in_pages
))
111 if (hdr
->data
[9] != (0xff & ~image_size_in_pages
))
113 if (hdr
->data
[10] != (0xff & image_size_in_pages
))
115 if (hdr
->data
[11] != (0xff & ~image_size_in_pages
))
117 if (hdr
->data
[12] != LPC32XX_BOOT_BLOCK_OK
)
119 if (hdr
->data
[128] != LPC32XX_BOOT_BLOCK_OK
)
124 static void print_hdr_byte(struct nand_page_0_boot_header
*hdr
, int ofs
)
126 printf("header[%d] = %02x\n", ofs
, hdr
->data
[ofs
]);
129 static void lpc32xximage_print_header(const void *ptr
)
131 struct nand_page_0_boot_header
*hdr
=
132 (struct nand_page_0_boot_header
*)ptr
;
135 for (ofs
= 0; ofs
<= 12; ofs
++)
136 print_hdr_byte(hdr
, ofs
);
137 print_hdr_byte(hdr
, 128);
140 static void lpc32xximage_set_header(void *ptr
, struct stat
*sbuf
, int ifd
,
141 struct image_tool_params
*params
)
143 struct nand_page_0_boot_header
*hdr
=
144 (struct nand_page_0_boot_header
*)ptr
;
146 /* turn image size from bytes to NAND pages, page 0 included */
147 int image_size_in_pages
= ((sbuf
->st_size
148 + LPC32XX_BOOT_NAND_PAGESIZE
- 1)
149 / LPC32XX_BOOT_NAND_PAGESIZE
);
151 /* fill header -- default byte value is 0x00, not 0xFF */
152 memset((void *)hdr
, 0, sizeof(*hdr
));
153 hdr
->data
[0] = (hdr
->data
[2] = 0xff & LPC32XX_BOOT_ICR
);
154 hdr
->data
[1] = (hdr
->data
[3] = 0xff & ~LPC32XX_BOOT_ICR
);
155 hdr
->data
[4] = (hdr
->data
[6] = (hdr
->data
[8]
156 = (hdr
->data
[10] = 0xff & image_size_in_pages
)));
157 hdr
->data
[5] = (hdr
->data
[7] = (hdr
->data
[9]
158 = (hdr
->data
[11] = 0xff & ~image_size_in_pages
)));
159 hdr
->data
[12] = (hdr
->data
[128] = LPC32XX_BOOT_BLOCK_OK
);
163 * lpc32xximage parameters
167 "LPC32XX Boot Image",
168 sizeof(lpc32xximage_header
),
169 (void *)&lpc32xximage_header
,
171 lpc32xximage_verify_header
,
172 lpc32xximage_print_header
,
173 lpc32xximage_set_header
,
175 lpc32xximage_check_image_types
,