changeset 658:0da2cf5a999c

target-utils: libload eliminated
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 03 Mar 2020 06:06:17 +0000
parents 742c99c1ff52
children 761e8b0c65b0
files target-utils/Makefile target-utils/libcommon/Makefile target-utils/libcommon/cmd_crc32.c target-utils/libcommon/hexstrings.c target-utils/libload/Makefile target-utils/libload/amdflash.c target-utils/libload/cmd_blankchk.c target-utils/libload/cmd_crc32.c target-utils/libload/cmd_memload.c target-utils/libload/hexstrings.c target-utils/libload/intelflash.c target-utils/loadagent/Makefile target-utils/loadagent/amdflash.c target-utils/loadagent/cmd_blankchk.c target-utils/loadagent/cmd_memload.c target-utils/loadagent/intelflash.c
diffstat 16 files changed, 457 insertions(+), 473 deletions(-) [+]
line wrap: on
line diff
--- a/target-utils/Makefile	Tue Mar 03 00:19:30 2020 +0000
+++ b/target-utils/Makefile	Tue Mar 03 06:06:17 2020 +0000
@@ -1,7 +1,7 @@
 INSTPROGS=	buzplayer calversion compalstage c139explore dspdump \
 		flash-boot-wa loadagent pirexplore simtest
 ALLPROGS=	${INSTPROGS} c139-lldbg flash-boot-test helloapp tf-breakin
-LIBS=		libbase libc libcommon libload libprintf libtiffs
+LIBS=		libbase libc libcommon libprintf libtiffs
 SUBDIR=		${ALLPROGS} ${LIBS}
 
 INSTALL_PREFIX=	/opt/freecalypso
@@ -16,7 +16,7 @@
 dspdump:		libbase libc libcommon libprintf
 flash-boot-test:	libbase libc libcommon libprintf
 helloapp:		libbase libc libcommon libprintf
-loadagent:		libbase libc libcommon libload libprintf
+loadagent:		libbase libc libcommon libprintf
 pirexplore:		libbase libc libcommon libprintf libtiffs
 simtest:		libbase libc libcommon libprintf
 
--- a/target-utils/libcommon/Makefile	Tue Mar 03 00:19:30 2020 +0000
+++ b/target-utils/libcommon/Makefile	Tue Mar 03 06:06:17 2020 +0000
@@ -5,9 +5,9 @@
 RANLIB=	arm-elf-ranlib
 
 OBJS=	abbcmd.o buzzer.o cmdentry.o defgetchar.o dispatch.o hexarg.o \
-	parseargs.o uartsel.o cmd_baud_switch.o cmd_dieid.o cmd_jump.o cmd_r8.o\
-	cmd_r16.o cmd_r32.o cmd_w8.o cmd_w16.o cmd_w32.o cmd_memdump_human.o \
-	cmd_memdump_machine.o
+	hexstrings.o parseargs.o uartsel.o cmd_baud_switch.o cmd_crc32.o \
+	cmd_dieid.o cmd_jump.o cmd_r8.o cmd_r16.o cmd_r32.o cmd_w8.o cmd_w16.o \
+	cmd_w32.o cmd_memdump_human.o cmd_memdump_machine.o
 
 all:	libcommon.a
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/libcommon/cmd_crc32.c	Tue Mar 03 06:06:17 2020 +0000
@@ -0,0 +1,100 @@
+/*
+ * The crc32 command is an integrity checking aid for flash dumps
+ * via loadtool.
+ */
+
+#include <sys/types.h>
+#include "types.h"
+
+/* This CRC-32 table has been computed for the LSB-first direction */
+
+static u32 crc32tab[256] = {
+	0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
+	0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
+	0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
+	0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
+	0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
+	0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
+	0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
+	0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
+	0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
+	0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
+	0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,
+	0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
+	0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,
+	0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
+	0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
+	0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
+	0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,
+	0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
+	0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
+	0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
+	0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
+	0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
+	0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,
+	0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
+	0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
+	0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
+	0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
+	0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
+	0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,
+	0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
+	0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
+	0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
+	0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
+	0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
+	0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
+	0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
+	0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,
+	0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
+	0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
+	0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
+	0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,
+	0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
+	0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,
+	0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
+	0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
+	0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
+	0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
+	0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
+	0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
+	0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
+	0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
+	0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
+	0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,
+	0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
+	0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
+	0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
+	0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
+	0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
+	0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,
+	0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
+	0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,
+	0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
+	0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
+	0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D,
+};
+
+void
+cmd_crc32(argbulk)
+	char *argbulk;
+{
+	char *argv[3];
+	u_long start, length;
+	u_long addr, crc;
+
+	if (parse_args(argbulk, 2, 2, argv, 0) < 0)
+		return;
+	if (parse_hexarg(argv[0], 8, &start) < 0) {
+		printf("ERROR: arg1 must be a valid 32-bit hex address\n");
+		return;
+	}
+	if (parse_hexarg(argv[1], 8, &length) < 0) {
+	    printf("ERROR: arg2 must be a valid 32-bit hex value (length)\n");
+		return;
+	}
+	crc = 0xFFFFFFFF;
+	for (addr = start; addr < start + length; addr++)
+		crc = crc32tab[crc & 0xFF ^ *(volatile u8 *)addr] ^ (crc >> 8);
+	printf("%08X\n", crc);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/libcommon/hexstrings.c	Tue Mar 03 06:06:17 2020 +0000
@@ -0,0 +1,33 @@
+/*
+ * The decode_hex_digits() function contained in this module
+ * will be used by the XRAM and flash loading commands
+ * which take SREC-like long hex string arguments.
+ */
+
+#include <ctype.h>
+#include "types.h"
+
+decode_hex_digits(str, ndigits, valp)
+	char *str;
+	int ndigits;
+	u32 *valp;
+{
+	u32 accum;
+	int i, c;
+
+	accum = 0;
+	for (i = 0; i < ndigits; i++) {
+		c = *str++;
+		if (!isxdigit(c))
+			return(-1);
+		accum <<= 4;
+		if (isdigit(c))
+			accum += c - '0';
+		else if (islower(c))
+			accum += c - 'a' + 10;
+		else
+			accum += c - 'A' + 10;
+	}
+	*valp = accum;
+	return(0);
+}
--- a/target-utils/libload/Makefile	Tue Mar 03 00:19:30 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-CC=	arm-elf-gcc
-CFLAGS=	-Os -fno-builtin
-CPPFLAGS=-I../include
-AR=	arm-elf-ar
-RANLIB=	arm-elf-ranlib
-
-OBJS=	cmd_blankchk.o cmd_crc32.o cmd_memload.o \
-	amdflash.o hexstrings.o intelflash.o
-
-all:	libload.a
-
-libload.a:	${OBJS}
-	${AR} cru $@ ${OBJS}
-	${RANLIB} $@
-
-clean:
-	rm -f *.[oa] *errs
--- a/target-utils/libload/amdflash.c	Tue Mar 03 00:19:30 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,90 +0,0 @@
-/*
- * This module implements the AMFB and AMFW commands for programming
- * AMD-style flash memories.  Syntax:
- *
- * AMFB <baseaddr>	-- sets the base address for subsequent AMFW commands
- * AMFW <offset> <hexstring>	-- the actual flash write operation
- *
- * The flash memory is assumed to be 16 bits wide.  The hex string
- * argument to the AMFW command is just data, with no header, address,
- * length, checksum or other additions.  The number of hex digits in the
- * string must be a multiple of 4, and the byte order is the same as
- * that of TI's *.m0 files: we interpret the string as consisting of
- * 16-bit words rather than bytes.
- *
- * The address to which each flash write is directed is the sum of the
- * base given to AMFB and the offset given to AMFW.  The fixed offsets
- * of 0xAAA and 0x554 (0x555 and 0x2AA in words) prescribed for the flash
- * programming command sequence are also made from the base set with AMFB.
- */
-
-#include <sys/types.h>
-#include "types.h"
-
-static u32 base_addr;
-
-void
-cmd_AMFB(argbulk)
-	char *argbulk;
-{
-	char *argv[2];
-	u_long addr;
-
-	if (parse_args(argbulk, 1, 1, argv, 0) < 0)
-		return;
-	if (parse_hexarg(argv[0], 8, &addr) < 0) {
-		printf("ERROR: argument must be a valid 32-bit hex address\n");
-		return;
-	}
-	if (addr & 1) {
-		printf("ERROR: odd address\n");
-		return;
-	}
-	base_addr = addr;
-}
-
-void
-cmd_AMFW(argbulk)
-	char *argbulk;
-{
-	char *argv[3], *s;
-	u_long offset;
-	volatile u16 *flashptr;
-	u32 datum;	/* needs to be u32 for decode_hex_digits() */
-	int i;
-
-	if (parse_args(argbulk, 2, 2, argv, 0) < 0)
-		return;
-	if (parse_hexarg(argv[0], 8, &offset) < 0) {
-	    printf("ERROR: offset argument must a valid 32-bit hex value\n");
-		return;
-	}
-	if (offset & 1) {
-		printf("ERROR: odd offset argument\n");
-		return;
-	}
-	flashptr = (volatile u16 *)(base_addr + offset);
-	for (s = argv[1]; *s; flashptr++, s += 4) {
-		if (decode_hex_digits(s, 4, &datum) < 0) {
-			printf("ERROR: bad AMFW hex string argument\n");
-			return;
-		}
-		if (*flashptr != 0xFFFF) {
-			printf("ERROR: flash not blank at %08X\n",
-				(u_long) flashptr);
-			return;
-		}
-		*(volatile u16 *)(base_addr + 0xAAA) = 0xAA;
-		*(volatile u16 *)(base_addr + 0x554) = 0x55;
-		*(volatile u16 *)(base_addr + 0xAAA) = 0xA0;
-		*flashptr = datum;
-		for (i = 10000; i; i--)
-			if (*flashptr == datum)
-				break;
-		if (!i) {
-			printf("ERROR: flash write timeout at %08X\n",
-				(u_long) flashptr);
-			return;
-		}
-	}
-}
--- a/target-utils/libload/cmd_blankchk.c	Tue Mar 03 00:19:30 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/*
- * Flash blank check command
- */
-
-#include <sys/types.h>
-#include "types.h"
-
-void
-cmd_blankchk(argbulk)
-	char *argbulk;
-{
-	char *argv[3];
-	u_long start, length;
-	u_long addr;
-	int c;
-
-	if (parse_args(argbulk, 2, 2, argv, 0) < 0)
-		return;
-	if (parse_hexarg(argv[0], 8, &start) < 0) {
-		printf("ERROR: arg1 must be a valid 32-bit hex address\n");
-		return;
-	}
-	if (parse_hexarg(argv[1], 8, &length) < 0) {
-	    printf("ERROR: arg2 must be a valid 32-bit hex value (length)\n");
-		return;
-	}
-	for (addr = start; addr < start + length; addr++) {
-		c = *(volatile u8 *)addr;
-		if (c != 0xFF) {
-			printf("Not blank: %02X at %08X\n", c, addr);
-			return;
-		}
-	}
-	printf("OK\n");
-}
--- a/target-utils/libload/cmd_crc32.c	Tue Mar 03 00:19:30 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,100 +0,0 @@
-/*
- * The crc32 command is an integrity checking aid for flash dumps
- * via loadtool.
- */
-
-#include <sys/types.h>
-#include "types.h"
-
-/* This CRC-32 table has been computed for the LSB-first direction */
-
-static u32 crc32tab[256] = {
-	0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
-	0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
-	0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
-	0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
-	0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
-	0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
-	0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
-	0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
-	0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
-	0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
-	0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,
-	0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
-	0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,
-	0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
-	0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
-	0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
-	0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,
-	0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
-	0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
-	0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
-	0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
-	0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
-	0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,
-	0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
-	0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
-	0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
-	0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
-	0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
-	0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,
-	0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
-	0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
-	0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
-	0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
-	0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
-	0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
-	0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
-	0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,
-	0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
-	0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
-	0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
-	0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,
-	0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
-	0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,
-	0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
-	0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
-	0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
-	0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
-	0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
-	0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
-	0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
-	0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
-	0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
-	0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,
-	0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
-	0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
-	0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
-	0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
-	0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
-	0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,
-	0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
-	0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,
-	0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
-	0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
-	0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D,
-};
-
-void
-cmd_crc32(argbulk)
-	char *argbulk;
-{
-	char *argv[3];
-	u_long start, length;
-	u_long addr, crc;
-
-	if (parse_args(argbulk, 2, 2, argv, 0) < 0)
-		return;
-	if (parse_hexarg(argv[0], 8, &start) < 0) {
-		printf("ERROR: arg1 must be a valid 32-bit hex address\n");
-		return;
-	}
-	if (parse_hexarg(argv[1], 8, &length) < 0) {
-	    printf("ERROR: arg2 must be a valid 32-bit hex value (length)\n");
-		return;
-	}
-	crc = 0xFFFFFFFF;
-	for (addr = start; addr < start + length; addr++)
-		crc = crc32tab[crc & 0xFF ^ *(volatile u8 *)addr] ^ (crc >> 8);
-	printf("%08X\n", crc);
-}
--- a/target-utils/libload/cmd_memload.c	Tue Mar 03 00:19:30 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-/*
- * This module implements the ML (memory load) command, which will be
- * used by fc-chainload.
- *
- * The sole argument to the ML command is the body of an S3 record
- * with the initial "S3" characters stripped, i.e., starting with the
- * "count" byte, followed by the address, data and checksum bytes
- * exactly as in the original S3 record.
- */
-
-#include "types.h"
-
-void
-cmd_memload(argbulk)
-	char *argbulk;
-{
-	char *argv[2], *s;
-	u8 srecbin[256], cksum;
-	int len, i, c;
-	u32 addr;
-
-	if (parse_args(argbulk, 1, 1, argv, 0) < 0)
-		return;
-	s = argv[0];
-	if (decode_hex_digits(s, 2, &len) < 0) {
-inv:		printf("ERROR: ML argument is invalid\n");
-		return;
-	}
-	s += 2;
-	if (len < 6)
-		goto inv;
-	srecbin[0] = len;
-	for (i = 1; i <= len; i++) {
-		if (decode_hex_digits(s, 2, &c) < 0)
-			goto inv;
-		s += 2;
-		srecbin[i] = c;
-	}
-	cksum = 0;
-	for (i = 0; i <= len; i++)
-		cksum += srecbin[i];
-	if (cksum != 0xFF) {
-		printf("ERROR: bad ML S-record checksum\n");
-		return;
-	}
-	len -= 5;
-	addr =  ((u32)srecbin[1] << 24) |
-		((u32)srecbin[2] << 16) |
-		((u32)srecbin[3] << 8) |
-		 (u32)srecbin[4];
-	memcpy(addr, srecbin + 5, len);
-}
--- a/target-utils/libload/hexstrings.c	Tue Mar 03 00:19:30 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-/*
- * The decode_hex_digits() function contained in this module
- * will be used by the XRAM and flash loading commands
- * which take SREC-like long hex string arguments.
- */
-
-#include <ctype.h>
-#include "types.h"
-
-decode_hex_digits(str, ndigits, valp)
-	char *str;
-	int ndigits;
-	u32 *valp;
-{
-	u32 accum;
-	int i, c;
-
-	accum = 0;
-	for (i = 0; i < ndigits; i++) {
-		c = *str++;
-		if (!isxdigit(c))
-			return(-1);
-		accum <<= 4;
-		if (isdigit(c))
-			accum += c - '0';
-		else if (islower(c))
-			accum += c - 'a' + 10;
-		else
-			accum += c - 'A' + 10;
-	}
-	*valp = accum;
-	return(0);
-}
--- a/target-utils/libload/intelflash.c	Tue Mar 03 00:19:30 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,139 +0,0 @@
-/*
- * This module implements the INFB and INFW commands for programming
- * Intel-style flash memories.  The syntax and operation are exactly
- * the same as the AMD flash counterparts AMFB and AMFW.
- *
- * The intel-rewrite-sector command (erase+program with a minimum of
- * vulnerability for brickable-boot Compal phones) is implemented
- * here as well.
- */
-
-#include <sys/types.h>
-#include "types.h"
-
-static u32 base_addr;
-
-void
-cmd_INFB(argbulk)
-	char *argbulk;
-{
-	char *argv[2];
-	u_long addr;
-
-	if (parse_args(argbulk, 1, 1, argv, 0) < 0)
-		return;
-	if (parse_hexarg(argv[0], 8, &addr) < 0) {
-		printf("ERROR: argument must be a valid 32-bit hex address\n");
-		return;
-	}
-	if (addr & 1) {
-		printf("ERROR: odd address\n");
-		return;
-	}
-	base_addr = addr;
-}
-
-void
-cmd_INFW(argbulk)
-	char *argbulk;
-{
-	char *argv[3], *s;
-	u_long offset;
-	volatile u16 *flashptr;
-	u32 datum;	/* needs to be u32 for decode_hex_digits() */
-	u16 stat;
-	int i;
-
-	if (parse_args(argbulk, 2, 2, argv, 0) < 0)
-		return;
-	if (parse_hexarg(argv[0], 8, &offset) < 0) {
-	    printf("ERROR: offset argument must a valid 32-bit hex value\n");
-		return;
-	}
-	if (offset & 1) {
-		printf("ERROR: odd offset argument\n");
-		return;
-	}
-	flashptr = (volatile u16 *)(base_addr + offset);
-	for (s = argv[1]; *s; flashptr++, s += 4) {
-		if (decode_hex_digits(s, 4, &datum) < 0) {
-			printf("ERROR: bad INFW hex string argument\n");
-			return;
-		}
-		*flashptr = 0x40;
-		*flashptr = datum;
-		for (i = 10000; i; i--) {
-			stat = *flashptr;
-			if (stat & 0x80)
-				break;
-		}
-		if (!i) {
-			printf("ERROR: flash write timeout at %08X\n",
-				(u_long) flashptr);
-			return;
-		}
-		if (stat & 0x10) {
-			printf("ERROR: program operation failed at %08X\n",
-				(u_long) flashptr);
-			return;
-		}
-	}
-}
-
-void
-cmd_intel_rewrite_sector(argbulk)
-	char *argbulk;
-{
-	char *argv[4];
-	u_long srcaddr, dstaddr, len;
-	const u16 *srcptr;
-	volatile u16 *flashptr;
-	u16 stat;
-
-	if (parse_args(argbulk, 3, 3, argv, 0) < 0)
-		return;
-	if (parse_hexarg(argv[0], 8, &srcaddr) < 0) {
-invarg:		printf("ERROR: invalid argument(s)\n");
-		return;
-	}
-	if (parse_hexarg(argv[1], 8, &dstaddr) < 0)
-		goto invarg;
-	if (parse_hexarg(argv[2], 8, &len) < 0)
-		goto invarg;
-	if (srcaddr & 1 || dstaddr & 1 || len & 1) {
-		printf("ERROR: all 3 arguments must be even\n");
-		return;
-	}
-	srcptr = (const u16 *) srcaddr;
-	flashptr = (volatile u16 *) dstaddr;
-	/* unlock the flash sector first */
-	*flashptr = 0x60;
-	*flashptr = 0xD0;
-	/* clear SR */
-	*flashptr = 0x50;
-	/* erase */
-	*flashptr = 0x20;
-	*flashptr = 0xD0;
-	/* wait for erase completion */
-	for (;;) {
-		stat = *flashptr;
-		if (stat & 0x80)
-			break;
-	}
-	if (stat & 0x30) {
-		printf("ERROR: erase operation failed!\n");
-		return;
-	}
-	/* now program the new content */
-	for (; len; len -= 2) {
-		*flashptr = 0x40;
-		*flashptr = *srcptr++;
-		for (;;) {
-			stat = *flashptr;
-			if (stat & 0x80)
-				break;
-		}
-		flashptr++;
-	}
-	printf("Operation complete, final SR: %02X\n", stat & 0xFF);
-}
--- a/target-utils/loadagent/Makefile	Tue Mar 03 00:19:30 2020 +0000
+++ b/target-utils/loadagent/Makefile	Tue Mar 03 06:06:17 2020 +0000
@@ -7,8 +7,9 @@
 INSTDIR=/opt/freecalypso/target-bin
 
 PROG=	loadagent
-OBJS=	crt0.o bindump.o binload.o cmdtab.o main.o serextra.o sertimeout.o
-LIBS=	../libload/libload.a ../libcommon/libcommon.a ../libprintf/libprintf.a \
+OBJS=	crt0.o amdflash.o bindump.o binload.o cmd_blankchk.o cmd_memload.o \
+	cmdtab.o intelflash.o main.o serextra.o sertimeout.o
+LIBS=	../libcommon/libcommon.a ../libprintf/libprintf.a \
 	../libbase/libbase.a ../libc/libc.a
 LIBGCC=	`${CC} -print-file-name=libgcc.a`
 LDS=	../env/iram.lds
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/loadagent/amdflash.c	Tue Mar 03 06:06:17 2020 +0000
@@ -0,0 +1,90 @@
+/*
+ * This module implements the AMFB and AMFW commands for programming
+ * AMD-style flash memories.  Syntax:
+ *
+ * AMFB <baseaddr>	-- sets the base address for subsequent AMFW commands
+ * AMFW <offset> <hexstring>	-- the actual flash write operation
+ *
+ * The flash memory is assumed to be 16 bits wide.  The hex string
+ * argument to the AMFW command is just data, with no header, address,
+ * length, checksum or other additions.  The number of hex digits in the
+ * string must be a multiple of 4, and the byte order is the same as
+ * that of TI's *.m0 files: we interpret the string as consisting of
+ * 16-bit words rather than bytes.
+ *
+ * The address to which each flash write is directed is the sum of the
+ * base given to AMFB and the offset given to AMFW.  The fixed offsets
+ * of 0xAAA and 0x554 (0x555 and 0x2AA in words) prescribed for the flash
+ * programming command sequence are also made from the base set with AMFB.
+ */
+
+#include <sys/types.h>
+#include "types.h"
+
+static u32 base_addr;
+
+void
+cmd_AMFB(argbulk)
+	char *argbulk;
+{
+	char *argv[2];
+	u_long addr;
+
+	if (parse_args(argbulk, 1, 1, argv, 0) < 0)
+		return;
+	if (parse_hexarg(argv[0], 8, &addr) < 0) {
+		printf("ERROR: argument must be a valid 32-bit hex address\n");
+		return;
+	}
+	if (addr & 1) {
+		printf("ERROR: odd address\n");
+		return;
+	}
+	base_addr = addr;
+}
+
+void
+cmd_AMFW(argbulk)
+	char *argbulk;
+{
+	char *argv[3], *s;
+	u_long offset;
+	volatile u16 *flashptr;
+	u32 datum;	/* needs to be u32 for decode_hex_digits() */
+	int i;
+
+	if (parse_args(argbulk, 2, 2, argv, 0) < 0)
+		return;
+	if (parse_hexarg(argv[0], 8, &offset) < 0) {
+	    printf("ERROR: offset argument must a valid 32-bit hex value\n");
+		return;
+	}
+	if (offset & 1) {
+		printf("ERROR: odd offset argument\n");
+		return;
+	}
+	flashptr = (volatile u16 *)(base_addr + offset);
+	for (s = argv[1]; *s; flashptr++, s += 4) {
+		if (decode_hex_digits(s, 4, &datum) < 0) {
+			printf("ERROR: bad AMFW hex string argument\n");
+			return;
+		}
+		if (*flashptr != 0xFFFF) {
+			printf("ERROR: flash not blank at %08X\n",
+				(u_long) flashptr);
+			return;
+		}
+		*(volatile u16 *)(base_addr + 0xAAA) = 0xAA;
+		*(volatile u16 *)(base_addr + 0x554) = 0x55;
+		*(volatile u16 *)(base_addr + 0xAAA) = 0xA0;
+		*flashptr = datum;
+		for (i = 10000; i; i--)
+			if (*flashptr == datum)
+				break;
+		if (!i) {
+			printf("ERROR: flash write timeout at %08X\n",
+				(u_long) flashptr);
+			return;
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/loadagent/cmd_blankchk.c	Tue Mar 03 06:06:17 2020 +0000
@@ -0,0 +1,35 @@
+/*
+ * Flash blank check command
+ */
+
+#include <sys/types.h>
+#include "types.h"
+
+void
+cmd_blankchk(argbulk)
+	char *argbulk;
+{
+	char *argv[3];
+	u_long start, length;
+	u_long addr;
+	int c;
+
+	if (parse_args(argbulk, 2, 2, argv, 0) < 0)
+		return;
+	if (parse_hexarg(argv[0], 8, &start) < 0) {
+		printf("ERROR: arg1 must be a valid 32-bit hex address\n");
+		return;
+	}
+	if (parse_hexarg(argv[1], 8, &length) < 0) {
+	    printf("ERROR: arg2 must be a valid 32-bit hex value (length)\n");
+		return;
+	}
+	for (addr = start; addr < start + length; addr++) {
+		c = *(volatile u8 *)addr;
+		if (c != 0xFF) {
+			printf("Not blank: %02X at %08X\n", c, addr);
+			return;
+		}
+	}
+	printf("OK\n");
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/loadagent/cmd_memload.c	Tue Mar 03 06:06:17 2020 +0000
@@ -0,0 +1,52 @@
+/*
+ * This module implements the ML (memory load) command, which will be
+ * used by fc-chainload.
+ *
+ * The sole argument to the ML command is the body of an S3 record
+ * with the initial "S3" characters stripped, i.e., starting with the
+ * "count" byte, followed by the address, data and checksum bytes
+ * exactly as in the original S3 record.
+ */
+
+#include "types.h"
+
+void
+cmd_memload(argbulk)
+	char *argbulk;
+{
+	char *argv[2], *s;
+	u8 srecbin[256], cksum;
+	int len, i, c;
+	u32 addr;
+
+	if (parse_args(argbulk, 1, 1, argv, 0) < 0)
+		return;
+	s = argv[0];
+	if (decode_hex_digits(s, 2, &len) < 0) {
+inv:		printf("ERROR: ML argument is invalid\n");
+		return;
+	}
+	s += 2;
+	if (len < 6)
+		goto inv;
+	srecbin[0] = len;
+	for (i = 1; i <= len; i++) {
+		if (decode_hex_digits(s, 2, &c) < 0)
+			goto inv;
+		s += 2;
+		srecbin[i] = c;
+	}
+	cksum = 0;
+	for (i = 0; i <= len; i++)
+		cksum += srecbin[i];
+	if (cksum != 0xFF) {
+		printf("ERROR: bad ML S-record checksum\n");
+		return;
+	}
+	len -= 5;
+	addr =  ((u32)srecbin[1] << 24) |
+		((u32)srecbin[2] << 16) |
+		((u32)srecbin[3] << 8) |
+		 (u32)srecbin[4];
+	memcpy(addr, srecbin + 5, len);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/loadagent/intelflash.c	Tue Mar 03 06:06:17 2020 +0000
@@ -0,0 +1,139 @@
+/*
+ * This module implements the INFB and INFW commands for programming
+ * Intel-style flash memories.  The syntax and operation are exactly
+ * the same as the AMD flash counterparts AMFB and AMFW.
+ *
+ * The intel-rewrite-sector command (erase+program with a minimum of
+ * vulnerability for brickable-boot Compal phones) is implemented
+ * here as well.
+ */
+
+#include <sys/types.h>
+#include "types.h"
+
+static u32 base_addr;
+
+void
+cmd_INFB(argbulk)
+	char *argbulk;
+{
+	char *argv[2];
+	u_long addr;
+
+	if (parse_args(argbulk, 1, 1, argv, 0) < 0)
+		return;
+	if (parse_hexarg(argv[0], 8, &addr) < 0) {
+		printf("ERROR: argument must be a valid 32-bit hex address\n");
+		return;
+	}
+	if (addr & 1) {
+		printf("ERROR: odd address\n");
+		return;
+	}
+	base_addr = addr;
+}
+
+void
+cmd_INFW(argbulk)
+	char *argbulk;
+{
+	char *argv[3], *s;
+	u_long offset;
+	volatile u16 *flashptr;
+	u32 datum;	/* needs to be u32 for decode_hex_digits() */
+	u16 stat;
+	int i;
+
+	if (parse_args(argbulk, 2, 2, argv, 0) < 0)
+		return;
+	if (parse_hexarg(argv[0], 8, &offset) < 0) {
+	    printf("ERROR: offset argument must a valid 32-bit hex value\n");
+		return;
+	}
+	if (offset & 1) {
+		printf("ERROR: odd offset argument\n");
+		return;
+	}
+	flashptr = (volatile u16 *)(base_addr + offset);
+	for (s = argv[1]; *s; flashptr++, s += 4) {
+		if (decode_hex_digits(s, 4, &datum) < 0) {
+			printf("ERROR: bad INFW hex string argument\n");
+			return;
+		}
+		*flashptr = 0x40;
+		*flashptr = datum;
+		for (i = 10000; i; i--) {
+			stat = *flashptr;
+			if (stat & 0x80)
+				break;
+		}
+		if (!i) {
+			printf("ERROR: flash write timeout at %08X\n",
+				(u_long) flashptr);
+			return;
+		}
+		if (stat & 0x10) {
+			printf("ERROR: program operation failed at %08X\n",
+				(u_long) flashptr);
+			return;
+		}
+	}
+}
+
+void
+cmd_intel_rewrite_sector(argbulk)
+	char *argbulk;
+{
+	char *argv[4];
+	u_long srcaddr, dstaddr, len;
+	const u16 *srcptr;
+	volatile u16 *flashptr;
+	u16 stat;
+
+	if (parse_args(argbulk, 3, 3, argv, 0) < 0)
+		return;
+	if (parse_hexarg(argv[0], 8, &srcaddr) < 0) {
+invarg:		printf("ERROR: invalid argument(s)\n");
+		return;
+	}
+	if (parse_hexarg(argv[1], 8, &dstaddr) < 0)
+		goto invarg;
+	if (parse_hexarg(argv[2], 8, &len) < 0)
+		goto invarg;
+	if (srcaddr & 1 || dstaddr & 1 || len & 1) {
+		printf("ERROR: all 3 arguments must be even\n");
+		return;
+	}
+	srcptr = (const u16 *) srcaddr;
+	flashptr = (volatile u16 *) dstaddr;
+	/* unlock the flash sector first */
+	*flashptr = 0x60;
+	*flashptr = 0xD0;
+	/* clear SR */
+	*flashptr = 0x50;
+	/* erase */
+	*flashptr = 0x20;
+	*flashptr = 0xD0;
+	/* wait for erase completion */
+	for (;;) {
+		stat = *flashptr;
+		if (stat & 0x80)
+			break;
+	}
+	if (stat & 0x30) {
+		printf("ERROR: erase operation failed!\n");
+		return;
+	}
+	/* now program the new content */
+	for (; len; len -= 2) {
+		*flashptr = 0x40;
+		*flashptr = *srcptr++;
+		for (;;) {
+			stat = *flashptr;
+			if (stat & 0x80)
+				break;
+		}
+		flashptr++;
+	}
+	printf("Operation complete, final SR: %02X\n", stat & 0xFF);
+}