summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2012-03-29 10:40:00 +0200
committerSylvain Munaut <tnt@246tNt.com>2012-03-29 10:40:00 +0200
commit3b3b41d2ba4cdf4fe339b1c2c4e0679280dbc292 (patch)
tree3759a3a494a68020df4b8d450ed9dd96bbcce601
parente3a39f0d8b3174ea4d266069f13c40485ea7e16c (diff)
board/osmo-sdr: Add DFU support for the startup code
DFU mode will be entered if: - 0xDFDFDFDF magic is at AT91C_IRAM - Button is pressed - No valid firmware seem to be present (start addr = 0xffffffff) Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
-rw-r--r--boards/osmo-sdr/board_cstartup_gnu.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/boards/osmo-sdr/board_cstartup_gnu.c b/boards/osmo-sdr/board_cstartup_gnu.c
index 66a433b..e170cfc 100644
--- a/boards/osmo-sdr/board_cstartup_gnu.c
+++ b/boards/osmo-sdr/board_cstartup_gnu.c
@@ -33,6 +33,7 @@
#include "board.h"
#include "exceptions.h"
#include "board_lowlevel.h"
+#include <usb/device/dfu/dfu.h>
//------------------------------------------------------------------------------
// External Variables
@@ -121,6 +122,20 @@ IntFunc exception_table[] = {
IrqHandlerNotUsed // 30 not used
};
+#if defined(BOARD_USB_DFU) && !defined(dfu)
+static void BootIntoApp(void)
+{
+ unsigned int *pSrc;
+ void (*appReset)(void);
+
+ pSrc = (unsigned int *) ((unsigned char *)AT91C_IFLASH0 + BOARD_DFU_BOOT_SIZE);
+ if (pSrc[1] == 0xffffffff)
+ return;
+ AT91C_BASE_NVIC->NVIC_VTOFFR = ((unsigned int)(pSrc)) | (0x0 << 7);
+ appReset = pSrc[1];
+ appReset();
+}
+#endif
//------------------------------------------------------------------------------
/// This is the code that gets called on processor reset. To initialize the
@@ -131,6 +146,24 @@ void ResetException(void)
unsigned int *pSrc, *pDest;
LowLevelInit();
+
+#if defined(BOARD_USB_DFU) && !defined(dfu)
+#ifdef BOARD_DFU_BTN_PIOA
+ /* There is a PIO button that can be used to enter DFU */
+ AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;
+ AT91C_BASE_PIOA->PIO_PPUER = (1 << BOARD_DFU_BTN_PIOA);
+ AT91C_BASE_PIOA->PIO_ODR = (1 << BOARD_DFU_BTN_PIOA);
+ AT91C_BASE_PIOA->PIO_PER = (1 << BOARD_DFU_BTN_PIOA);
+
+ if (AT91C_BASE_PIOA->PIO_PDSR & (1 << BOARD_DFU_BTN_PIOA) &&
+#else /* BOARD_DFU_BTN_PIOA */
+ if (1 &&
+#endif /* BOARD_DFU_BTN_PIOA */
+ *((unsigned long *)USB_DFU_MAGIC_ADDR) != USB_DFU_MAGIC) {
+ BootIntoApp();
+ }
+#endif
+
#if defined(psram)
pDest = &_vect_start;
pSrc = &_svectorrelocate;
personal git repositories of Harald Welte. Your mileage may vary