aboutsummaryrefslogtreecommitdiff
path: root/flashstub
diff options
context:
space:
mode:
authorGareth McMullin2015-03-08 15:02:38 -0700
committerGareth McMullin2015-03-19 21:49:09 -0700
commit8ddb186b35267e90832deb2db4b0c58f77de4b87 (patch)
tree58f6cf40b653374df7086cf6a4cff236a9eacd2c /flashstub
parent437aedda11a112407af7b3f7884090023944faef (diff)
Allow stub to return an error code.
Diffstat (limited to 'flashstub')
-rw-r--r--flashstub/stm32f1.c9
-rw-r--r--flashstub/stm32f1.stub2
-rw-r--r--flashstub/stub.h30
3 files changed, 39 insertions, 2 deletions
diff --git a/flashstub/stm32f1.c b/flashstub/stm32f1.c
index 8370114..2268eee 100644
--- a/flashstub/stm32f1.c
+++ b/flashstub/stm32f1.c
@@ -18,6 +18,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "libopencm3/stm32/flash.h"
+#include "stub.h"
+
+#define SR_ERROR_MASK 0x14
void __attribute__((naked))
stm32f1_flash_write_stub(uint16_t *dest, uint16_t *src, uint32_t size)
@@ -29,6 +32,10 @@ stm32f1_flash_write_stub(uint16_t *dest, uint16_t *src, uint32_t size)
while (FLASH_SR & FLASH_SR_BSY)
;
}
- asm("bkpt");
+
+ if (FLASH_SR & SR_ERROR_MASK)
+ stub_exit(1);
+
+ stub_exit(0);
}
diff --git a/flashstub/stm32f1.stub b/flashstub/stm32f1.stub
index 97d2a5e..428dbb0 100644
--- a/flashstub/stm32f1.stub
+++ b/flashstub/stm32f1.stub
@@ -1 +1 @@
-0x4613, 0xE010, 0x4A09, 0x2401, 0x6014, 0x4602, 0x1C90, 0x460C, 0x1CA1, 0x8824, 0x8014, 0x3B02, 0xBF00, 0x4A05, 0x6812, 0xF002, 0x0201, 0x2A00, 0xD1F9, 0x2B00, 0xD1EC, 0xBE00, 0x2010, 0x4002, 0x200C, 0x4002, \ No newline at end of file
+0x4613, 0xE010, 0x4A0D, 0x2401, 0x6014, 0x4602, 0x1C90, 0x460C, 0x1CA1, 0x8824, 0x8014, 0x3B02, 0xBF00, 0x4A09, 0x6812, 0xF002, 0x0201, 0x2A00, 0xD1F9, 0x2B00, 0xD1EC, 0x4B05, 0x681B, 0xF003, 0x0314, 0x2B00, 0xD000, 0xBE01, 0xBE00, 0xBF00, 0x2010, 0x4002, 0x200C, 0x4002, \ No newline at end of file
diff --git a/flashstub/stub.h b/flashstub/stub.h
new file mode 100644
index 0000000..d279cf3
--- /dev/null
+++ b/flashstub/stub.h
@@ -0,0 +1,30 @@
+/*
+ * This file is part of the Black Magic Debug project.
+ *
+ * Copyright (C) 2015 Black Sphere Technologies Ltd.
+ * Written by Gareth McMullin <gareth@blacksphere.co.nz>
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef __STUB_H
+#define __STUB_H
+
+static inline __attribute__((always_inline))
+stub_exit(const int code)
+{
+ asm("bkpt %0"::"i"(code));
+}
+
+#endif
+