Skip to content

Commit

Permalink
RT #73025. ea-lpc1788: install the checksum into u-boot image.
Browse files Browse the repository at this point in the history
The checksum at predefined offset is required for execution of images
from the LPC178X eNVM. This patch automates the creation of this
checksum, the resulted images are u-boot-lpc.bin and u-boot-lpc.hex.
  • Loading branch information
sposelenov-emcraft committed Nov 25, 2011
1 parent 4d817fa commit 3dcddc0
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
/u-boot.dis
/u-boot.lds
/u-boot.ubl
/u-boot-lpc.hex

#
# Generated files
Expand Down
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ NAND_SPL = nand_spl
U_BOOT_NAND = $(obj)u-boot-nand.bin
endif

ifeq ($(CONFIG_LPC178X_FCG),y)
U_BOOT_LPC178X_FCG = $(obj)u-boot-lpc.hex
endif

ifeq ($(CONFIG_ONENAND_U_BOOT),y)
ONENAND_IPL = onenand_ipl
U_BOOT_ONENAND = $(obj)u-boot-onenand.bin
Expand All @@ -293,7 +297,7 @@ __LIBS := $(subst $(obj),,$(LIBS)) $(subst $(obj),,$(LIBBOARD))
#########################################################################

# Always append ALL so that arch config.mk's can add custom ones
ALL += $(obj)u-boot.srec $(obj)u-boot.bin $(obj)System.map $(U_BOOT_NAND) $(U_BOOT_ONENAND)
ALL += $(obj)u-boot.srec $(obj)u-boot.bin $(obj)System.map $(U_BOOT_NAND) $(U_BOOT_ONENAND) $(U_BOOT_LPC178X_FCG)

all: $(ALL)

Expand All @@ -306,6 +310,12 @@ $(obj)u-boot.srec: $(obj)u-boot
$(obj)u-boot.bin: $(obj)u-boot
$(OBJCOPY) ${OBJCFLAGS} -O binary $< $@

$(obj)u-boot-lpc.bin: $(obj)u-boot.bin
$(obj)tools/lpc178x_fcg $(obj)u-boot.bin $(obj)u-boot-lpc.bin

$(obj)u-boot-lpc.hex: $(obj)u-boot-lpc.bin
$(OBJCOPY) ${OBJCFLAGS} -O ihex $< $@ -I binary

$(obj)u-boot.upgrade: $(obj)u-boot.bin
split -b 32768 -a 1 -d u-boot.bin u-boot.bin-
scp u-boot.bin-* yota:~/
Expand Down Expand Up @@ -3768,7 +3778,8 @@ clean:
$(obj)tools/gdb/{astest,gdbcont,gdbsend} \
$(obj)tools/gen_eth_addr $(obj)tools/img2srec \
$(obj)tools/mkimage $(obj)tools/mpc86x_clk \
$(obj)tools/ncb $(obj)tools/ubsha1
$(obj)tools/ncb $(obj)tools/ubsha1 \
$(obj)tools/lpc178x_fcg
@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 \
Expand Down
6 changes: 6 additions & 0 deletions include/configs/ea-lpc1788.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
*/
#define CONFIG_SYS_LPC178X

/*
* Embed the calculated checksum into the U-Boot image
* (needed for execution of images from LPC178x eNVM).
*/
#define CONFIG_LPC178X_FCG

/*
* Enable GPIO driver
*/
Expand Down
1 change: 1 addition & 0 deletions tools/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
/ncp
/ubsha1
/inca-swap-bytes
/lpc178x_fcg
/*.exe
5 changes: 5 additions & 0 deletions tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ BIN_FILES-$(CONFIG_INCA_IP) += inca-swap-bytes$(SFX)
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)

# Source files which exist outside the tools directory
EXT_OBJ_FILES-y += common/env_embedded.o
Expand All @@ -87,6 +88,7 @@ NOPED_OBJ_FILES-y += mkimage.o
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

# Don't build by default
#ifeq ($(ARCH),ppc)
Expand Down Expand Up @@ -192,6 +194,9 @@ $(obj)ncb$(SFX): $(obj)ncb.o
$(obj)ubsha1$(SFX): $(obj)os_support.o $(obj)sha1.o $(obj)ubsha1.o
$(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $^

$(obj)lpc178x_fcg$(SFX): $(obj)lpc178x_fcg.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 $@ $<
Expand Down
130 changes: 130 additions & 0 deletions tools/lpc178x_fcg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* Copyright (C) 2011 by NXP Semiconductors
* All rights reserved.
*
* @Author: Kevin Wells
* @Descr: Inserts checksum into FLASH image for LPC17xx devices
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

/*
* This LPC1788 requires a checksum of the first 7 words in FLASH to boot
* a user program. All this program does is compute the 2's complement
* checksum on the first 7 32-bit words and inserts it into the 8th 32-bit
* word - overwriting what is there.
*
* Note that some LPC1788 FLASH burners may already generate the checksum
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

/*
* Works for LPC1787and LPC1788, but adjust for other parts
*/
#define MAX_FLASH_SIZE (512 * 1024)

int main(int argc, char *argv[])
{
FILE *fp = NULL;
char *filename, *nfilename;
unsigned int cksum, *buff;
size_t fsize;
int i, ret = 0;

if (argc != 3)
{
printf("Usage: %s infile outfile\n", argv[0]);
return 1;
}

/* Enough for a 512K image to burn */
buff = (unsigned int *) malloc(MAX_FLASH_SIZE);
if (!buff) {
printf("Error allocating memory for buffer\n");
return 1;
}

filename = (char *) argv[1];
fp = fopen((const char *) filename, "r");
if (!fp) {
printf("Error opening file %s\n", filename);
ret = 1;
goto free_buff;
}

/* Load file and save file size */
fsize = fread((void *) buff, 1, MAX_FLASH_SIZE, fp);

if (ferror(fp)) {
printf("Error loading file %s\n", filename);
ret = 1;
goto close_file;
}


if (!feof(fp)) {
printf("File %s is too large. The maximum size is "
"limited by FLASH (%d bytes)\n", filename,
MAX_FLASH_SIZE);
ret = 1;
goto close_file;
}

printf("File %s loaded with size %d bytes\n", filename, (int) fsize);

fclose(fp);

nfilename = (char *) argv[2];

/* Open new file for writing */
fp = fopen(nfilename, "w");
if (!fp) {
printf("Error creating new file %s\n", nfilename);
ret = 1;
goto free_buff;
}

/* Compute 2's complement checksum */
cksum = 0;
for (i = 0; i < 7; i++) {
cksum += buff[i];
printf("Word %d: 0x%08x\n", i, buff[i]);
}

buff[7] = 0xFFFFFFFF - cksum + 1;
printf("Word 7: 0x%08x (cksum total: 0x%08x)\n", buff[7],
(cksum + buff[7]));

/* Write data back to file */
if (fwrite(buff, 1, fsize, fp) != fsize) {
printf("Error writing new file %s\n", nfilename);
ret = 1;
goto close_file;
}
printf("File %s created with size %d bytes\n", nfilename,
(int) fsize);

close_file:
fclose(fp);

free_buff:
free(buff);

return ret;
}

0 comments on commit 3dcddc0

Please sign in to comment.