From: Leo C Date: Wed, 21 Jan 2015 03:07:19 +0000 (+0100) Subject: Support for Peter Danneggers fboot. X-Git-Tag: hexrel-6~1^2 X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/commitdiff_plain/c748023ede9e7d8bdbf81ce8c8be2a437607a9e4 Support for Peter Danneggers fboot. --- 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 @@ -60,6 +60,11 @@ CMD_TBL_ITEM( "EEPROM dump", "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", 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 #include "common.h" +#include +#include +#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 +#include #include #include @@ -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 #include #include #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) { diff --git a/include/config.h b/include/config.h index f51ebe9..e40d016 100644 --- a/include/config.h +++ b/include/config.h @@ -40,6 +40,8 @@ #define CONFIG_SYS_PROMPT "=> " #define CONFIG_ESC_CHAR ('^'-0x40) +#define CONFIG_SYS_FBOOTSIG "Peda" + /* TODO: */ //#define CONFIG_CMDLINE_EDITING 1 diff --git a/include/print-utils.h b/include/print-utils.h index 8acf975..7d48287 100644 --- a/include/print-utils.h +++ b/include/print-utils.h @@ -19,5 +19,6 @@ void dump_ram(uint8_t *addr, size_t offset, unsigned int len, char *title); void eeprom_read_buf(uint8_t *buf, uint32_t addr, uint8_t count); void ram_read_buf(uint8_t *buf, uint32_t addr, uint8_t count); +void flash_read_buf(uint8_t *buf, uint32_t addr, uint8_t count); #endif /* PRINT_UTILS_H */