changeset 404:7daea2476062

loadagent: Intel flash support added, compiles
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 16 Jun 2014 01:15:17 +0000
parents 7602443edf0d
children a212b4968b29
files target-utils/libload/Makefile target-utils/libload/intelflash.c target-utils/loadagent/cmdtab.c
diffstat 3 files changed, 82 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/target-utils/libload/Makefile	Sun Jun 15 22:06:46 2014 +0000
+++ b/target-utils/libload/Makefile	Mon Jun 16 01:15:17 2014 +0000
@@ -5,7 +5,7 @@
 RANLIB=	arm-elf-ranlib
 
 OBJS=	cmd_blankchk.o cmd_crc32.o cmd_memdump_human.o cmd_memdump_machine.o \
-	cmd_memload.o amdflash.o hexstrings.o
+	cmd_memload.o amdflash.o hexstrings.o intelflash.o
 
 all:	libload.a
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/libload/intelflash.c	Mon Jun 16 01:15:17 2014 +0000
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ */
+
+#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;
+		}
+	}
+}
--- a/target-utils/loadagent/cmdtab.c	Sun Jun 15 22:06:46 2014 +0000
+++ b/target-utils/loadagent/cmdtab.c	Mon Jun 16 01:15:17 2014 +0000
@@ -2,6 +2,8 @@
 
 extern void cmd_AMFB();
 extern void cmd_AMFW();
+extern void cmd_INFB();
+extern void cmd_INFW();
 extern void cmd_abbr();
 extern void cmd_abbw();
 extern void cmd_blankchk();
@@ -26,6 +28,8 @@
 	{"AMFB", cmd_AMFB},
 	{"AMFW", cmd_AMFW},
 	{"DUMP", cmd_memdump_machine},
+	{"INFB", cmd_INFB},
+	{"INFW", cmd_INFW},
 	{"ML", cmd_memload},
 	{"abbinit", abb_init},
 	{"abbr", cmd_abbr},