changeset 659:761e8b0c65b0

loadagent: first step in implementation of binary flash programming
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 03 Mar 2020 17:55:20 +0000
parents 0da2cf5a999c
children b34384991094
files target-utils/loadagent/amdflash.c target-utils/loadagent/intelflash.c
diffstat 2 files changed, 73 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/target-utils/loadagent/amdflash.c	Tue Mar 03 06:06:17 2020 +0000
+++ b/target-utils/loadagent/amdflash.c	Tue Mar 03 17:55:20 2020 +0000
@@ -88,3 +88,39 @@
 		}
 	}
 }
+
+amdflash_binary_prog(offset, nwords, data)
+	u32 offset;
+	unsigned nwords;
+	u16 *data;
+{
+	volatile u16 *flashptr;
+	int i;
+
+	flashptr = (volatile u16 *)(base_addr + offset);
+	while (nwords) {
+		if (*flashptr != 0xFFFF) {
+			serial_out(0x15);	/* NAK */
+			printf("ERROR: flash not blank at %08X\n",
+				(u_long) flashptr);
+			return(-1);
+		}
+		*(volatile u16 *)(base_addr + 0xAAA) = 0xAA;
+		*(volatile u16 *)(base_addr + 0x554) = 0x55;
+		*(volatile u16 *)(base_addr + 0xAAA) = 0xA0;
+		*flashptr = *data;
+		for (i = 10000; i; i--)
+			if (*flashptr == *data)
+				break;
+		if (!i) {
+			serial_out(0x15);	/* NAK */
+			printf("ERROR: flash write timeout at %08X\n",
+				(u_long) flashptr);
+			return(-1);
+		}
+		flashptr++;
+		data++;
+		nwords--;
+	}
+	return(0);
+}
--- a/target-utils/loadagent/intelflash.c	Tue Mar 03 06:06:17 2020 +0000
+++ b/target-utils/loadagent/intelflash.c	Tue Mar 03 17:55:20 2020 +0000
@@ -80,6 +80,43 @@
 	}
 }
 
+intelflash_binary_prog(offset, nwords, data)
+	u32 offset;
+	unsigned nwords;
+	u16 *data;
+{
+	volatile u16 *flashptr;
+	u16 stat;
+	int i;
+
+	flashptr = (volatile u16 *)(base_addr + offset);
+	while (nwords) {
+		*flashptr = 0x40;
+		*flashptr = *data;
+		for (i = 10000; i; i--) {
+			stat = *flashptr;
+			if (stat & 0x80)
+				break;
+		}
+		if (!i) {
+			serial_out(0x15);	/* NAK */
+			printf("ERROR: flash write timeout at %08X\n",
+				(u_long) flashptr);
+			return(-1);
+		}
+		if (stat & 0x10) {
+			serial_out(0x15);	/* NAK */
+			printf("ERROR: program operation failed at %08X\n",
+				(u_long) flashptr);
+			return(-1);
+		}
+		flashptr++;
+		data++;
+		nwords--;
+	}
+	return(0);
+}
+
 void
 cmd_intel_rewrite_sector(argbulk)
 	char *argbulk;