Comments (3)
Do you mean a some sort watchdog timer?
from sboot_stm32.
Software watchdog. I am thinking more like taking a timestamp after every transaction. Return a bool indicating 'something happened' from the poll functions, the mainline loop could take the timestamp on first entry, and for every 'true' response from poll. If the timestamp varies by more than the the configured timeout, then reboot, check the application image, and if it is ok, boot the App, otherwise, in effect, continue in DFU mode.
One use case is the application can request to reboot into dfu mode, and if nothing happens after, lets say, a minute, it returns to the application. This way a hacker, or some unhappy accident, could not get in and DOS the application by injecting a reboot into dfu mode.
from sboot_stm32.
Something like this should work, but lacks the ability to be consistent timebase because each mcu clocks it differently:
diff --git a/src/bootloader.c b/src/bootloader.c
index 6299daf..b412b7b 100644
--- a/src/bootloader.c
+++ b/src/bootloader.c
@@ -74,6 +74,9 @@ static struct dfu_data_s {
uint8_t interface;
uint8_t bStatus;
uint8_t bState;
+#if defined(DFU_WATCHDOG)
+ uint32_t counter;
+#endif
} dfu_data;
/** Processing DFU_SET_IDLE request */
@@ -100,6 +103,27 @@ static usbd_respond dfu_set_idle(void) {
extern void System_Reset(void);
+static inline void heartbeat(void) {
+#if defined(DFU_WATCHDOG)
+ dfu_data.counter = 0;
+ SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
+ SysTick->VAL = SysTick->LOAD = (1ULL << 24) - 1;
+ SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
+#endif
+}
+
+static inline void watchdog(void) {
+#if defined(DFU_WATCHDOG)
+ if (SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) {
+ dfu_data.counter++;
+ }
+ if ((((uint64_t)dfu_data.counter << 24)
+ | (~SysTick->VAL & ((1ULL << 24) - 1))) > DFU_WATCHDOG) {
+ System_Reset();
+ }
+#endif
+}
+
static usbd_respond dfu_err_badreq(void) {
dfu_data.bState = USB_DFU_STATE_DFU_ERROR;
dfu_data.bStatus = USB_DFU_STATUS_ERR_STALLEDPKT;
@@ -223,6 +247,7 @@ static void dfu_reset(usbd_device *dev, uint8_t ev, uint8_t ep) {
}
static usbd_respond dfu_control (usbd_device *dev, usbd_ctlreq *req, usbd_rqc_callback *callback) {
+ heartbeat();
(void)callback;
if ((req->bmRequestType & (USB_REQ_TYPE | USB_REQ_RECIPIENT)) == (USB_REQ_STANDARD | USB_REQ_INTERFACE)) {
switch (req->bRequest) {
@@ -287,6 +312,7 @@ static usbd_respond dfu_control (usbd_device *dev, usbd_ctlreq *req, usbd_rqc_ca
static usbd_respond dfu_config(usbd_device *dev, uint8_t config) {
+ heartbeat();
switch (config) {
case 0:
usbd_reg_event(dev, usbd_evt_reset, 0);
@@ -313,7 +339,9 @@ static void dfu_init (void) {
int main (void) {
dfu_init();
+ heartbeat();
while(1) {
usbd_poll(&dfu);
+ watchdog();
}
}
from sboot_stm32.
Related Issues (20)
- Build fails with linker errors HOT 2
- Unable programm if rdp>0 HOT 14
- Generating empty elf in openstm32 - system workbench HOT 1
- Error "sorry - this program has been built without plugin support" HOT 9
- User firmware stuck or not starting after reset. HOT 5
- Firmware stuck at start when using MX_USB_DEVICE_Init(); in user firmware. HOT 5
- Compiling bootloader for stm32f103x8 HOT 1
- User code in bootloader HOT 6
- Multiple Memory Overflow Vulnerabilities In dfu_control HOT 3
- Supports STM32F103xC/D/E devices with 2Kbytes pages HOT 1
- Support for STM32H7 family HOT 1
- README.md spell correction
- Use HSI48+CRS on L0 HOT 5
- Checksum documentation HOT 4
- Clear FLASH_SR in stm32f0xx.S HOT 1
- Compilation with -Werror HOT 2
- Support multiple DFU transports? USART? HOT 2
- Need a checksum only feature in fwcrypt HOT 2
- stm32g491 support? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sboot_stm32.