Commit 74cfefd6 authored by Alexander Potashev's avatar Alexander Potashev

RT77744. lpc4350-eval: Add header to the U-Boot image

 * This 16-byte header is required to boot U-Boot to the Hitex LPC4350 Eval
board over USB0. The same header is required to make the Boot ROM
bootloader boot images larger than 16KBytes from NOR flash.
 * The header will be automatically added to `u-boot.bin` if
CONFIG_LPC18XX_BOOTHEADER is enabled in the U-Boot configuration.
parent b79aa072
......@@ -313,6 +313,10 @@ ifeq ($(CONFIG_LPC178X_FCG),y)
$(obj)tools/lpc178x_fcg $(obj)u-boot.bin $(obj)u-boot-lpc.bin
mv $(obj)u-boot-lpc.bin $(obj)u-boot.bin
endif
ifeq ($(CONFIG_LPC18XX_BOOTHEADER),y)
$(obj)tools/lpc18xx_bootheader $(obj)u-boot.bin $(obj)u-boot-bootheader.bin
mv $(obj)u-boot-bootheader.bin $(obj)u-boot.bin
endif
$(obj)u-boot.upgrade: $(obj)u-boot.bin
split -b 32768 -a 1 -d u-boot.bin u-boot.bin-
......@@ -3798,7 +3802,8 @@ clean:
$(obj)tools/gen_eth_addr $(obj)tools/img2srec \
$(obj)tools/mkimage $(obj)tools/mpc86x_clk \
$(obj)tools/ncb $(obj)tools/ubsha1 \
$(obj)tools/lpc178x_fcg
$(obj)tools/lpc178x_fcg \
$(obj)tools/lpc18xx_bootheader
@rm -f $(obj)board/cray/L1/{bootscript.c,bootscript.image} \
$(obj)board/netstar/{eeprom,crcek,crcit,*.srec,*.bin} \
$(obj)board/trab/trab_fkt $(obj)board/voiceblue/eeprom \
......
......@@ -42,6 +42,12 @@
*/
#define CONFIG_SYS_LPC18XX
/*
* Add header to the U-Boot image to pass necessary information
* to the Boot ROM bootloader.
*/
#define CONFIG_LPC18XX_BOOTHEADER
/*
* Enable GPIO driver
*/
......
......@@ -9,4 +9,5 @@
/ubsha1
/inca-swap-bytes
/lpc178x_fcg
/lpc18xx_bootheader
/*.exe
......@@ -65,6 +65,7 @@ BIN_FILES-y += mkimage$(SFX)
BIN_FILES-$(CONFIG_NETCONSOLE) += ncb$(SFX)
BIN_FILES-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1$(SFX)
BIN_FILES-$(CONFIG_LPC178X_FCG) += lpc178x_fcg$(SFX)
BIN_FILES-$(CONFIG_LPC18XX_BOOTHEADER) += lpc18xx_bootheader$(SFX)
# Source files which exist outside the tools directory
EXT_OBJ_FILES-y += common/env_embedded.o
......@@ -89,6 +90,7 @@ OBJ_FILES-$(CONFIG_NETCONSOLE) += ncb.o
NOPED_OBJ_FILES-y += os_support.o
OBJ_FILES-$(CONFIG_SHA1_CHECK_UB_IMG) += ubsha1.o
OBJ_FILES-$(CONFIG_LPC178X_FCG) += lpc178x_fcg.o
OBJ_FILES-$(CONFIG_LPC18XX_BOOTHEADER) += lpc18xx_bootheader.o
# Don't build by default
#ifeq ($(ARCH),ppc)
......@@ -197,6 +199,9 @@ $(obj)ubsha1$(SFX): $(obj)os_support.o $(obj)sha1.o $(obj)ubsha1.o
$(obj)lpc178x_fcg$(SFX): $(obj)lpc178x_fcg.o
$(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
$(obj)lpc18xx_bootheader$(SFX): $(obj)lpc18xx_bootheader.o
$(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^
# Some of the tool objects need to be accessed from outside the tools directory
$(obj)%.o: $(SRCTREE)/common/%.c
$(HOSTCC) -g $(HOSTCFLAGS_NOPED) -c -o $@ $<
......
/*
* (C) Copyright 2012
* Emcraft Systems, <www.emcraft.com>
* Alexander Potashev <aspotashev@emcraft.com>
*
* Header generator for the NXP LPC18xx/43xx Boot ROM bootloader.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
/*
* The header format is described in section "5.3.3 Boot image format"
* in the LPC43xx User Manual.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
long f_size; /* Input file size */
long blocks; /* Number of 512-byte blocks in image */
long out_size; /* Image data size round up to 512-byte blocks */
FILE *in, *out;
unsigned char header[16];
unsigned char *buf;
if (argc != 3) {
printf("Usage: lpc18xx_bootheader [in-file] [out-file]\n");
return 1;
}
/* Get file size */
in = fopen(argv[1], "rb");
if (!in) {
printf("Cannot open input file: %s\n", argv[1]);
return 2;
}
fseek(in, 0, SEEK_END);
f_size = ftell(in);
rewind(in);
/* Round up to an integer number of 512-byte blocks */
blocks = (f_size + 511) / 512;
out_size = blocks * 512;
/* Number of blocks in limited to 2**16 = 65536 = 32 MBytes */
if (blocks >> 16) {
printf("Number of blocks is too large: %ld\n", blocks);
return 3;
}
/* Read image data */
buf = malloc(out_size);
if (!buf) {
printf("Could not allocate %ld bytes of memory\n", f_size);
return 4;
}
if (fread(buf, f_size, 1, in) != 1) {
printf("Could not read file contents: %s\n", argv[1]);
return 5;
}
fclose(in);
/* Zero the padding bytes after actual image data ends */
memset(buf + f_size, 0, out_size - f_size);
/* Generate header */
memset(header, 0, sizeof(header));
header[0] = 0x1A; /* AES encryption not active */
header[0] |= (3 << 6); /* no hash is used */
header[1] = 0x3F; /* Reserved, must be 6 binary 1s */
header[2] = blocks & 0xFF; /* Little endian: LSB */
header[3] = (blocks >> 8) & 0xFF; /* Little endian: MSB */
header[12] = 0xFF; /* Reserved */
header[13] = 0xFF; /* Reserved */
header[14] = 0xFF; /* Reserved */
header[15] = 0xFF; /* Reserved */
/* Write output file */
out = fopen(argv[2], "wb");
if (!out) {
printf("Cannot open output file: %s\n", argv[2]);
return 6;
}
if (fwrite(header, sizeof(header), 1, out) != 1) {
printf("Could not write header to file: %s\n", argv[2]);
return 7;
}
if (fwrite(buf, out_size, 1, out) != 1) {
printf("Could not write image data to file: %s\n", argv[2]);
return 8;
}
fclose(out);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment