Reboot to DFU?

Posted on
  • I’m looking for a way to reboot into DFU mode without having to hold the button.

    Is this possible? I’ve tried poking various 32-bit values into the address that should be GPREGRET, but it immediately reboots with all three LEDs on, and then back into espruino.

    0x4000051c is the address I’ve been using, but I’m not so sure that’s correct.

  • I've not tried/done it from espruino... but in my nrf code the steps to get to DFU are:

    1. disable softdevice
    2. disable interrupts (NVIC->ICER & NVIC->ICPR [0&1] = 0xffffffff)
    3. write 0x57 into GPREGRET
    4. call NVIC_SystemReset()
  • I'm not 100% sure if the bootloader in Espruino supports looking at that register but it's worth a try...

    There's nothing built in to Espruino though I'm afraid, but if it works maybe we should add it!

  • There's nothing built in to Espruino though I'm afraid, but if it works maybe we should add it!

    Well, I proposed that previously but so far your argument was that it is dangerous - someone with access to console can remotely update your device so something physical (holding button) to enter DFU is safer.

    Some watches uses also value 1 in GPREGRET to trigger DFU so in my custom builds I have one liner

    --- a/targets/nrf5x_dfu/main.c
    +++ b/targets/nrf5x_dfu/main.c
    @@ -149,18 +153,19 @@ bool nrf_dfu_enter_check(void) {
     bool dfu_enter_check(void) {
     [#endif](https://forum.espruino.com/sear­ch/?q=%23endif)
       bool dfu_start;
    +  if (NRF_POWER->GPREGRET == 1) { NRF_POWER->GPREGRET=0; return true; }
     [#ifdef](https://forum.espruino.com/sear­ch/?q=%23ifdef) BTN1_PININDEX
       dfu_start = get_btn1_state();
     [#else](https://forum.espruino.com/searc­h/?q=%23else)
    

    but I agree that it is somewhat dangerous.
    With that one liner in bootloader you enter DFU by poke32(0x4000051c,1), with softdevice enabled it automatically reboots (into DFU)

  • If it’s not enabled by default, I think it should definitely be behind an ifdef, or maybe enabled some other way. Maybe a DFU update that flips a byte flag somewhere?

    It’s hard though, because you’re trying to secure functionality through a repl console that should ultimately be password protected by the user… I get what you’re saying though

  • but so far your argument was that it is dangerous - someone with access to console can remotely update your device so something physical (holding button) to enter DFU is safer.

    Yes, I know... I'm just getting worn down over time :)

    I guess there's an argument that it is now possible via the CLI to actually rewrite the bootloader from Espruino (once you disable the write-protect), so in a way if you really wanted to screw it up from the REPL you could.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Reboot to DFU?

Posted by Avatar for DanTheMan827 @DanTheMan827

Actions