mirror of
git://projects.qi-hardware.com/antorcha.git
synced 2025-04-21 12:27:27 +03:00
RESET protocol to jump from application to boot loader without power cycling
This commit is contained in:
@@ -30,7 +30,7 @@ OBJCOPY = $(AVR_PREFIX)objcopy
|
||||
#OBJDUMP = $(AVR_PREFIX)objdump
|
||||
SIZE = $(AVR_PREFIX)size
|
||||
|
||||
OBJS = $(NAME).o dispatch.o hash.o $(COMMON_OBJS)
|
||||
OBJS = $(NAME).o dispatch.o hash.o reset.o $(COMMON_OBJS)
|
||||
BOOT_OBJS = boot.o flash.o fw.o $(COMMON_OBJS)
|
||||
COMMON_OBJS = rf.o spi.o
|
||||
|
||||
@@ -87,7 +87,7 @@ clean:
|
||||
rm -f version.c version.d version.o
|
||||
|
||||
nosecrets:
|
||||
rm -f unlock-secret.inc image-secret.inc
|
||||
rm -f unlock-secret.inc reset-secret.inc image-secret.inc
|
||||
|
||||
# ----- Build version ---------------------------------------------------------
|
||||
|
||||
@@ -129,10 +129,14 @@ SECRET = { dd if=$(RANDOM) iflag=fullblock bs=$(1) count=1 status=noxfer | \
|
||||
unlock-secret.inc:
|
||||
$(BUILD) $(call SECRET,64) >$@ || { rm -f $@; exit 1; }
|
||||
|
||||
reset-secret.inc:
|
||||
$(BUILD) $(call SECRET,64) >$@ || { rm -f $@; exit 1; }
|
||||
|
||||
image-secret.inc:
|
||||
$(BUILD) $(call SECRET,128) >$@ || { rm -f $@; exit 1; }
|
||||
|
||||
fw.o: unlock-secret.inc
|
||||
reset.o: unlock-secret.inc
|
||||
|
||||
# ----- Dependencies ----------------------------------------------------------
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
#include "dispatch.h"
|
||||
|
||||
|
||||
|
||||
static const struct handler *protos[] = {
|
||||
&reset_handler,
|
||||
NULL
|
||||
};
|
||||
|
||||
@@ -39,12 +39,6 @@ int main(void)
|
||||
* It has also brought up RF and the underlying SPI.
|
||||
*/
|
||||
|
||||
while (1) {
|
||||
SET(LED_B8);
|
||||
_delay_ms(100);
|
||||
CLR(LED_B8);
|
||||
_delay_ms(100);
|
||||
}
|
||||
while (1) {
|
||||
got = rf_recv(buf, sizeof(buf));
|
||||
if (got > 2)
|
||||
|
||||
12
fw/boot.c
12
fw/boot.c
@@ -57,9 +57,19 @@ int main(void)
|
||||
PORTD = 0;
|
||||
DDRD = 0xff;
|
||||
|
||||
/* disable pull-ups */
|
||||
/* Disable pull-ups */
|
||||
MCUCR |= 1 << PUD;
|
||||
|
||||
/*
|
||||
* Disable the watchdog timer, in case the boot loader has been
|
||||
* entered by a watchdog reset commanded by the application.
|
||||
*/
|
||||
|
||||
MCUSR = 0; /* Remove override */
|
||||
WDTCSR |= 1 << WDCE; /* Enable change */
|
||||
WDTCSR = 1 << WDCE; /* Disable watchdog while still enabling
|
||||
change */
|
||||
|
||||
rf_init();
|
||||
|
||||
/*
|
||||
|
||||
@@ -26,6 +26,8 @@ struct handler {
|
||||
};
|
||||
|
||||
|
||||
extern struct handler reset_handler;
|
||||
|
||||
bool dispatch(const uint8_t *buf, uint8_t len, const struct handler **protos);
|
||||
|
||||
#endif /* !PROTO_H */
|
||||
|
||||
6
fw/fw.c
6
fw/fw.c
@@ -15,6 +15,9 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#define F_CPU 8000000UL
|
||||
#include <util/delay.h>
|
||||
|
||||
#include "io.h"
|
||||
#include "flash.h"
|
||||
#include "proto.h"
|
||||
@@ -54,8 +57,9 @@ bool fw_packet(const uint8_t *buf, uint8_t len)
|
||||
static uint8_t limit;
|
||||
uint8_t ack[] = { FIRMWARE+1, buf[1], buf[2] };
|
||||
|
||||
/* short (barely visible) flash to indicate reception */
|
||||
/* short flash to indicate reception */
|
||||
SET(LED_B7);
|
||||
_delay_ms(1);
|
||||
CLR(LED_B7);
|
||||
|
||||
/* Check packet for formal validity */
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
enum pck_type {
|
||||
PING = 0, /* version query */
|
||||
PONG = 1, /* version response */
|
||||
RESET = 2, /* reset to boot loader */
|
||||
FIRMWARE = 4, /* firmware upload */
|
||||
FIRMWARE_ACK = 5, /* firmware upload acknowledgement */
|
||||
IMAGE = 6, /* image upload */
|
||||
|
||||
Reference in New Issue
Block a user