commit a4c06c2900eb71209506de477bd9abe9473b57bb
parent 6fae5d5a00b6cd1b240e6ae1c943f837cd2e530f
Author: Brian Swetland <swetland@frotz.net>
Date: Sat, 13 Jun 2015 19:39:15 -0700
agent-lpc15xx: flash agent for lpc15xx parts
Diffstat:
3 files changed, 114 insertions(+), 0 deletions(-)
diff --git a/agent-lpc15xx/header.S b/agent-lpc15xx/header.S
@@ -0,0 +1,18 @@
+
+.section .vectors
+.syntax unified
+.globl _start
+
+_start:
+ .long 0x42776166 // magic
+ .long 0x00010000 // version
+ .long 0x00000001 // flags
+ .long _start
+ .long 0x02001000 // data addr
+ .long 0x00001000 // data size
+ .long 0x00000000 // flash addr
+ .long 0x00010000 // flash size
+ .long flash_agent_setup + 1
+ .long flash_agent_erase + 1
+ .long flash_agent_write + 1
+ .long flash_agent_ioctl + 1
diff --git a/agent-lpc15xx/main.c b/agent-lpc15xx/main.c
@@ -0,0 +1,89 @@
+// agent-lpc15xx/main.c
+//
+// Copyright 2015 Brian Swetland <swetland@frotz.net>
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include <agent/flash.h>
+
+#define LPC_IAP_FUNC 0x03000201
+#define LPC_IAP_PREPARE 50
+#define LPC_IAP_WRITE 51
+#define LPC_IAP_ERASE 52
+
+void (*romcall)(u32 *param, u32 *status) = (void*) LPC_IAP_FUNC;
+
+int flash_agent_setup(flash_agent *agent) {
+ return ERR_NONE;
+}
+
+int flash_agent_erase(u32 flash_addr, u32 length) {
+ u32 p[5];
+ u32 page = flash_addr >> 12;
+ u32 last = page + ((length - 1) >> 12);
+ if (flash_addr & 0xFFF) {
+ return ERR_ALIGNMENT;
+ }
+
+ p[0] = LPC_IAP_PREPARE;
+ p[1] = page;
+ p[2] = last;
+ romcall(p,p);
+ if (p[0]) {
+ return ERR_FAIL;
+ }
+
+ p[0] = LPC_IAP_ERASE;
+ p[1] = page;
+ p[2] = last;
+ p[3] = 0x2ee0;
+ romcall(p,p);
+ if (p[0]) {
+ return ERR_FAIL;
+ }
+ return ERR_NONE;
+}
+
+int flash_agent_write(u32 flash_addr, const void *data, u32 length) {
+ u32 p[5];
+ u32 page = flash_addr >> 12;
+ if (flash_addr & 0xFFF) {
+ return ERR_ALIGNMENT;
+ }
+
+ p[0] = LPC_IAP_PREPARE;
+ p[1] = page;
+ p[2] = page;
+ romcall(p,p);
+ if (p[0]) {
+ return ERR_FAIL;
+ }
+
+ p[0] = LPC_IAP_WRITE;
+ p[1] = flash_addr;
+ p[2] = (u32) data;
+ p[3] = 0x1000;
+ p[4] = 0x2ee0;
+ romcall(p,p);
+ if (p[0]) {
+ return ERR_FAIL;
+ }
+
+ return ERR_NONE;
+}
+
+int flash_agent_ioctl(u32 op, void *ptr, u32 arg0, u32 arg1) {
+ return ERR_INVALID;
+}
+
+
diff --git a/agent-lpc15xx/module.mk b/agent-lpc15xx/module.mk
@@ -0,0 +1,7 @@
+
+M_NAME := agent-lpc15xx
+M_CHIP := lpc1547-agt
+M_START := agent-lpc15xx/header.o
+M_OBJS := agent-lpc15xx/main.o
+$(call build-target-executable)
+