summaryrefslogtreecommitdiff
path: root/avr
diff options
context:
space:
mode:
authorLeo C2015-01-21 04:07:19 +0100
committerLeo C2015-01-21 04:07:19 +0100
commitc748023ede9e7d8bdbf81ce8c8be2a437607a9e4 (patch)
treeafb7994e11bf67ff8f370c6da67892acd2d8df4d /avr
parentce47d431da8ca00d52caffebaafd7ddb817d7b26 (diff)
downloadz180-stamp-c748023ede9e7d8bdbf81ce8c8be2a437607a9e4.zip
Support for Peter Danneggers fboot.
Diffstat (limited to 'avr')
-rw-r--r--avr/command_tbl.c5
-rw-r--r--avr/con-utils.c29
-rw-r--r--avr/debug.c13
-rw-r--r--avr/main.c27
-rw-r--r--avr/print-utils.c7
5 files changed, 67 insertions, 14 deletions
diff --git a/avr/command_tbl.c b/avr/command_tbl.c
index d4ff6f2..cbd2382 100644
--- a/avr/command_tbl.c
+++ b/avr/command_tbl.c
@@ -61,6 +61,11 @@ CMD_TBL_ITEM(
"address [count]"
),
CMD_TBL_ITEM(
+ !mdf, 3, 1, do_dump_mem,
+ "FLASH dump",
+ "address [count]"
+),
+CMD_TBL_ITEM(
!cpe, 4, 0, do_eep_cp,
"EEPROM copy",
"source target count"
diff --git a/avr/con-utils.c b/avr/con-utils.c
index f20dbfe..5ee1ff1 100644
--- a/avr/con-utils.c
+++ b/avr/con-utils.c
@@ -4,9 +4,11 @@
* SPDX-License-Identifier: GPL-2.0+
*/
-#include <string.h>
#include "common.h"
+#include <string.h>
+#include <avr/wdt.h>
+#include "config.h"
#include "serial.h"
#include "background.h"
#include "con-utils.h"
@@ -26,6 +28,31 @@ int my_getchar(uint_fast8_t waitforchar)
c = serial_getc();
} while ((c < 0) && waitforchar);
+#ifdef CONFIG_SYS_FBOOTSIG
+ if (c < 0)
+ return c;
+
+ static const FLASH unsigned char bootsig[] = {CONFIG_SYS_FBOOTSIG};
+ static uint8_t pb;
+ unsigned char uc = c;
+
+
+ if (bootsig[pb] == 0) {
+ if (uc == 0xff) {
+ wdt_enable(WDTO_15MS);
+ for(;;)
+ ;
+ } else
+ pb = 0;
+
+ } else {
+ if (bootsig[pb] == uc)
+ pb++;
+ else
+ pb = 0;
+ }
+#endif
+
return c;
}
diff --git a/avr/debug.c b/avr/debug.c
index 251ef26..d4ae1f4 100644
--- a/avr/debug.c
+++ b/avr/debug.c
@@ -49,12 +49,19 @@ command_ret_t do_dump_mem(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg
uint32_t addr;
uint32_t length = 128;
- if (strchr(argv[0],'r') != NULL)
+ switch (argv[0][3]) {
+ case 'r':
readhow = ram_read_buf;
- else if (strchr(argv[0],'e') != NULL)
+ break;
+ case 'e':
readhow = eeprom_read_buf;
- else
+ break;
+ case 'f':
+ readhow = flash_read_buf;
+ break;
+ default:
return CMD_RET_USAGE;
+ }
/* Address is specified since argc > 1 */
addr = strtoul(argv[1], NULL, 16);
diff --git a/avr/main.c b/avr/main.c
index 8bffef9..f4d4c6f 100644
--- a/avr/main.c
+++ b/avr/main.c
@@ -7,6 +7,7 @@
#include "common.h"
#include <avr/interrupt.h>
+#include <avr/wdt.h>
#include <stdlib.h>
#include <stdio.h>
@@ -24,11 +25,9 @@
#include "time.h"
#include "rtc.h"
-static uint8_t mcusr;
+uint8_t mcusr __attribute__ ((section (".noinit")));
-/*--------------------------------------------------------------------------*/
#if DEBUG
-
__attribute__ ((naked)) __attribute__ ((section (".init3")))
void preset_ram (void)
{
@@ -36,6 +35,21 @@ void preset_ram (void)
*p = 0xdd;
}
+#endif
+
+__attribute__ ((naked)) __attribute__ ((section (".init3")))
+void get_mcusr (void)
+{
+ /* save and clear reset reason(s) */
+ /* TODO: move to init section? */
+ mcusr = MCUSR;
+ MCUSR = 0;
+
+ wdt_disable();
+}
+
+/*--------------------------------------------------------------------------*/
+#if DEBUG
static const FLASH char * const FLASH rreasons[] = {
FSTR("Power on"),
@@ -77,13 +91,6 @@ ISR(INT6_vect)
static
void setup_avr(void)
{
- /* save and clear reset reason(s) */
- /* TODO: move to init section? */
- mcusr = MCUSR;
- MCUSR = 0;
-
- /* WD */
-
/* CPU */
/* Disable JTAG Interface regardless of the JTAGEN fuse setting. */
diff --git a/avr/print-utils.c b/avr/print-utils.c
index 3f48620..9ce3e50 100644
--- a/avr/print-utils.c
+++ b/avr/print-utils.c
@@ -5,6 +5,7 @@
*/
#include "common.h"
+#include <stdint.h>
#include <stdio.h>
#include <ctype.h>
#include "con-utils.h"
@@ -28,6 +29,12 @@ void ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
*buf++ = *(uint8_t *) (size_t) addr++;
}
+void flash_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
+{
+ while (count--)
+ *buf++ = *(const __memx uint8_t *) (__uint24) addr++;
+}
+
int dump_mem(uint32_t address, uint32_t offset, uint32_t len,
void (*readfkt)(uint8_t *, uint32_t, uint8_t), char *title)
{