Skip to content

Embassy boot and dfu flashing#877

Draft
Schievel1 wants to merge 15 commits into
HaoboGu:mainfrom
Schievel1:embassy-boot
Draft

Embassy boot and dfu flashing#877
Schievel1 wants to merge 15 commits into
HaoboGu:mainfrom
Schievel1:embassy-boot

Conversation

@Schievel1

@Schievel1 Schievel1 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

This PR adds DFU (Device Firmware Upgrade) support via embassy-boot for RP2040-based keyboards. Once set up, firmware updates can be done over USB with dfu-util — no need to press BOOTSEL or use a debug probe.

What's implemented

rmk crate — new dfu_rp feature gate:

  • dfu.rs: init_flash() initializes the blocking flash with configurable partition offsets and returns a storage partition for RMK's keymap storage
  • set_led() / mark_booted() — optional DFU activity LED and boot-success signaling to prevent bootloader rollback
  • register_dfu_interface() — registers a USB DFU class (embassy-usb-dfu) with a handler that blinks the LED during transfers
  • DfuLock (behind dfu_lock feature) — physical key unlock for DFU: pressing the configured matrix keys unlocks DFU for 10 s, with Morse "DFU" LED blinking
  • Automatic DFU interface registration in UsbTransport::new() when the manager is initialized

rmk-config crate — new [dfu] TOML section:

  • flash_size, page_size — auto-calculate partition addresses using the bootymcbootface formula (state at 0x6000, active at 0x7000, DFU slot follows) (bootymcbootface (https://codeberg.org/Schievel/bootymcbootface/) is the matching bootloader for this, but people could roll their own and use whatever partitioning suits them)
  • led — optional GPIO pin for DFU activity
  • unlock_keys — matrix positions for dfu_lock
  • Manual override of state_offset, state_size, dfu_offset, dfu_size for custom layouts

Examples:

  • examples/use_rust/rp2040_embassy_boot/ — full Rust-API example
  • Example configs updated for use_config path

Documentation:

  • New user_guide/flash_firmware/use_embassy_boot.mdx with setup guide (bootymcbootface, compilation, step-by-step flashing, DFU usage, dfu_lock, LED behavior)
  • RP2040 + embassy-boot section in configuration/chip_config.mdx with partition table and TOML/Rust tabs

Feature flags

  • dfu — base DFU support (USB DFU interface)
  • dfu_rp — RP2040-specific DFU with embassy-boot (implies dfu + rp2040)
  • dfu_lock — physical key unlock for DFU (implies dfu_rp + host_security)

Usage flow

  1. Flash bootymcbootface (once, via UF2 or probe-rs)
  2. Compile RMK with dfu_rp feature and matching flash size
  3. Flash RMK firmware (via UF2 or probe-rs)
  4. All future updates: cargo make bin && dfu-util -D firmware.bin

Perspective

Since embassy-boot is agnostic towards how the updated firmware gets into the DFU partition, this PR lays the foundation for future features like flashing via bluetooth or flashing the peripheral from the central using the serial connection between them.

Needs:

Schievel1 added 4 commits June 9, 2026 00:19
Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
rename embassy-boot flag to dfu/ dfu-rp flag

Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
Signed-off-by: Pascal Jäger <pascal.jaeger@leimstift.de>
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Size Report

Example main PR Diff .text .data .bss
use_config/nrf52832_ble 372.1 KiB 372.1 KiB +0.00% 0 0 0
use_config/nrf52840_ble 421.7 KiB 421.7 KiB +0.00% ⬆️ +20 0 0
use_config/nrf52840_ble_split (central) 497.2 KiB 497.2 KiB +0.00% ⬆️ +4 0 0
use_config/nrf52840_ble_split (peripheral) 322.3 KiB 322.2 KiB +0.00% ⬇️ -8 0 0
use_config/pi_pico_w_ble 659.3 KiB 659.3 KiB +0.00% ⬇️ -4 0 0
use_config/rp2040 147.2 KiB 147.2 KiB +0.00% 0 0 0
use_config/rp2040_split (central) 160.5 KiB 160.4 KiB +0.00% ⬇️ -4 0 0
use_config/rp2040_split (peripheral) 27.4 KiB 27.4 KiB -0.01% ⬇️ -4 0 0
use_config/stm32f1 62.6 KiB 62.6 KiB +0.00% 0 0 0
use_config/stm32h7 99.8 KiB 99.8 KiB +0.00% 0 0 0
use_rust/nrf52832_ble 359.6 KiB 359.6 KiB +0.00% ⬆️ +12 0 0
use_rust/nrf52840_ble 417.8 KiB 417.8 KiB +0.00% ⬆️ +20 0 0
use_rust/nrf52840_ble_split (central) 506.6 KiB 506.6 KiB +0.00% ⬇️ -8 0 0
use_rust/nrf52840_ble_split (peripheral) 319.0 KiB 319.0 KiB +0.00% ⬇️ -4 0 0
use_rust/pi_pico_w_ble 659.9 KiB 659.9 KiB +0.00% ⬇️ -4 0 0
use_rust/rp2040 147.2 KiB 147.2 KiB +0.00% ⬆️ +4 0 0
use_rust/rp2040_split (central) 159.6 KiB 159.6 KiB +0.00% ⬇️ -4 0 0
use_rust/rp2040_split (peripheral) 27.8 KiB 27.8 KiB +0.00% 0 0 0
use_rust/stm32f1 62.7 KiB 62.6 KiB -0.01% ⬇️ -12 0 0
use_rust/stm32h7 121.2 KiB 121.2 KiB +0.00% ⬆️ +8 0 0
use_config/nrf52832_ble — 372.1 KiB → 372.1 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 341428	   5256	  34376	 381060	  5d084	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 341428	   5256	  34376	 381060	  5d084	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +89  [ = ]       0    .debug_info
  +0.0%     +24  [ = ]       0    .strtab
  -1.9%      -1  [ = ]       0    [Unmapped]
  -0.0%      -2  [ = ]       0    .debug_line
  -0.0% -1.07Ki  [ = ]       0    .debug_str
  -0.0%    -984  [ = ]       0    TOTAL
use_config/nrf52840_ble — 421.7 KiB → 421.7 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 375412	   5264	  51176	 431852	  696ec	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 375392	   5264	  51176	 431832	  696d8	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0% +1.56Ki  [ = ]       0    .debug_str
  +0.0%     +64  [ = ]       0    .symtab
  +0.1%     +36  [ = ]       0    .debug_frame
  +0.0%     +33  [ = ]       0    .strtab
  +0.0%     +32  [ = ]       0    .debug_ranges
  +0.0%     +20  +0.0%     +20    .text
  +0.0%     +16  [ = ]       0    .debug_aranges
 -32.8%     -21  [ = ]       0    [Unmapped]
  -0.6%     -52  [ = ]       0    .debug_abbrev
  -0.1%    -212  [ = ]       0    .debug_line
  -0.1% -1.02Ki  [ = ]       0    .debug_loc
  -0.1% -2.59Ki  [ = ]       0    .debug_info
  -0.0% -2.14Ki  +0.0%     +20    TOTAL
use_config/nrf52840_ble_split (central) — 497.2 KiB → 497.2 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 455564	   6588	  46992	 509144	  7c4d8	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 455560	   6588	  46992	 509140	  7c4d4	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
   +80%     +33  [ = ]       0    [Unmapped]
  +0.0%      +6  [ = ]       0    .strtab
  +0.0%      +4  +0.0%      +4    .text
  -0.2%     -17  [ = ]       0    .debug_abbrev
  -0.0%     -42  [ = ]       0    .debug_loc
  -0.0%     -61  [ = ]       0    .debug_line
  -0.0%    -649  [ = ]       0    .debug_info
  -0.0% -1.56Ki  [ = ]       0    .debug_str
  -0.0% -2.27Ki  +0.0%      +4    TOTAL
use_config/nrf52840_ble_split (peripheral) — 322.3 KiB → 322.2 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 296548	   5920	  27512	 329980	  508fc	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 296556	   5920	  27512	 329988	  50904	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1% +1.57Ki  [ = ]       0    .debug_str
  +0.0%    +426  [ = ]       0    .debug_info
  +0.0%     +22  [ = ]       0    .debug_loc
   +29%     +10  [ = ]       0    [Unmapped]
  +0.0%      +9  [ = ]       0    .strtab
  -0.0%      -8  -0.0%      -8    .text
  -0.0%     -99  [ = ]       0    .debug_line
  +0.0% +1.92Ki  -0.0%      -8    TOTAL
use_config/pi_pico_w_ble — 659.3 KiB → 659.3 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 619524	      0	  55572	 675096	  a4d18	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 619528	      0	  55572	 675100	  a4d1c	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +393  [ = ]       0    .debug_str
  +0.0%     +16  [ = ]       0    .strtab
  +7.1%      +3  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  -0.0%     -14  [ = ]       0    .debug_line
  -0.2%     -24  [ = ]       0    .debug_abbrev
  -0.0%    -234  [ = ]       0    .debug_info
  +0.0%    +136  -0.0%      -4    TOTAL
use_config/rp2040 — 147.2 KiB → 147.2 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 135336	      0	  15372	 150708	  24cb4	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 135336	      0	  15372	 150708	  24cb4	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +113  [ = ]       0    .debug_str
  +0.0%     +32  [ = ]       0    .debug_loc
  +0.0%     +10  [ = ]       0    .strtab
  -0.0%     -55  [ = ]       0    .debug_line
  -0.0%    -120  [ = ]       0    .debug_info
  -0.0%     -20  [ = ]       0    TOTAL
use_config/rp2040_split (central) — 160.5 KiB → 160.4 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 148116	      0	  16184	 164300	  281cc	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 148120	      0	  16184	 164304	  281d0	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +5  [ = ]       0    .strtab
  -4.9%      -3  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  -0.0%     -21  [ = ]       0    .debug_line
  -0.0%     -32  [ = ]       0    .debug_loc
  -0.0%     -47  [ = ]       0    .debug_str
  -0.0%    -178  [ = ]       0    .debug_info
  -0.0%    -280  -0.0%      -4    TOTAL
use_config/rp2040_split (peripheral) — 27.4 KiB → 27.4 KiB (-0.01% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  25252	     60	   2764	  28076	   6dac	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  25256	     60	   2764	  28080	   6db0	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +14  [ = ]       0    .debug_str
   +21%      +9  [ = ]       0    [Unmapped]
  +0.0%      +1  [ = ]       0    .strtab
  -0.1%      -4  -0.1%      -4    .rodata
  +0.0%     +20  -0.0%      -4    TOTAL
use_config/stm32f1 — 62.6 KiB → 62.6 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  56596	     28	   7504	  64128	   fa80	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  56596	     28	   7504	  64128	   fa80	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +127  [ = ]       0    .debug_info
  +0.0%      +7  [ = ]       0    .debug_str
  +0.0%      +5  [ = ]       0    .debug_line
  +1.6%      +1  [ = ]       0    [Unmapped]
  +0.0%    +140  [ = ]       0    TOTAL
use_config/stm32h7 — 99.8 KiB → 99.8 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  92140	    268	   9736	 102144	  18f00	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  92140	    268	   9736	 102144	  18f00	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%      +7  [ = ]       0    .debug_line
  +0.0%      +6  [ = ]       0    .debug_info
  +0.0%      +4  [ = ]       0    .debug_str
  -1.7%      -1  [ = ]       0    [Unmapped]
  +0.0%     +16  [ = ]       0    TOTAL
use_rust/nrf52832_ble — 359.6 KiB → 359.6 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 329560	   5264	  33368	 368192	  59e40	rmk-nrf52832

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 329548	   5264	  33368	 368180	  59e34	rmk-nrf52832

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +212  [ = ]       0    .debug_info
  +0.0%     +12  +0.0%     +12    .text
  +0.0%      +5  [ = ]       0    .strtab
  -0.0%     -10  [ = ]       0    .debug_loc
 -19.6%     -10  [ = ]       0    [Unmapped]
  -0.4%     -35  [ = ]       0    .debug_abbrev
  -0.1%    -225  [ = ]       0    .debug_line
  -0.0%    -685  [ = ]       0    .debug_str
  -0.0%    -736  +0.0%     +12    TOTAL
use_rust/nrf52840_ble — 417.8 KiB → 417.8 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 375896	   5264	  46656	 427816	  68728	rmk-nrf52840

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 375876	   5264	  46656	 427796	  68714	rmk-nrf52840

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +32  [ = ]       0    .debug_ranges
  +0.0%     +32  [ = ]       0    .symtab
  +0.0%     +20  [ = ]       0    .debug_frame
  +0.0%     +20  +0.0%     +20    .text
  +0.0%      +8  [ = ]       0    .debug_aranges
  +0.0%      +8  [ = ]       0    .strtab
 -30.6%     -19  [ = ]       0    [Unmapped]
  -0.0%    -239  [ = ]       0    .debug_str
  -0.1%    -368  [ = ]       0    .debug_line
  -0.1% -1.04Ki  [ = ]       0    .debug_loc
  -0.1% -2.00Ki  [ = ]       0    .debug_info
  -0.0% -3.53Ki  +0.0%     +20    TOTAL
use_rust/nrf52840_ble_split (central) — 506.6 KiB → 506.6 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 459444	   6588	  52728	 518760	  7ea68	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 459452	   6588	  52728	 518768	  7ea70	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +148  [ = ]       0    .debug_line
  +0.3%     +22  [ = ]       0    .debug_abbrev
   +25%     +13  [ = ]       0    [Unmapped]
  +0.0%      +6  [ = ]       0    .strtab
  -0.0%      -8  -0.0%      -8    .text
  -0.0%     -51  [ = ]       0    .debug_str
  -0.0%    -390  [ = ]       0    .debug_info
  -0.0%    -260  -0.0%      -8    TOTAL
use_rust/nrf52840_ble_split (peripheral) — 319.0 KiB → 319.0 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 294992	   5360	  26272	 326624	  4fbe0	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 294996	   5360	  26272	 326628	  4fbe4	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +505  [ = ]       0    .debug_str
  +0.0%    +264  [ = ]       0    .debug_info
  +0.0%     +32  [ = ]       0    .debug_loc
  +0.0%     +10  [ = ]       0    .strtab
  +0.0%      +2  [ = ]       0    .debug_line
  -2.2%      -1  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  +0.0%    +808  -0.0%      -4    TOTAL
use_rust/pi_pico_w_ble — 659.9 KiB → 659.9 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 619972	      0	  55716	 675688	  a4f68	rmk-pi-pico-w

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 619976	      0	  55716	 675692	  a4f6c	rmk-pi-pico-w

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +538  [ = ]       0    .debug_str
  +0.0%     +16  [ = ]       0    .strtab
  +2.3%      +1  [ = ]       0    [Unmapped]
  -0.0%      -4  -0.0%      -4    .text
  -0.0%     -15  [ = ]       0    .debug_line
  -0.0%     -44  [ = ]       0    .debug_loc
  -0.0%    -268  [ = ]       0    .debug_info
  +0.0%    +224  -0.0%      -4    TOTAL
use_rust/rp2040 — 147.2 KiB → 147.2 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 135520	      0	  15252	 150772	  24cf4	rmk-rp2040

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 135516	      0	  15252	 150768	  24cf0	rmk-rp2040

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +42  [ = ]       0    .debug_loc
  +0.0%     +35  [ = ]       0    .debug_str
  +0.0%     +10  [ = ]       0    .strtab
  +0.0%      +4  +0.0%      +4    .text
  +2.0%      +1  [ = ]       0    [Unmapped]
  -0.0%     -27  [ = ]       0    .debug_line
  -0.0%    -269  [ = ]       0    .debug_info
  -0.0%    -204  +0.0%      +4    TOTAL
use_rust/rp2040_split (central) — 159.6 KiB → 159.6 KiB (+0.00% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 147484	      0	  15964	 163448	  27e78	central

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 147488	      0	  15964	 163452	  27e7c	central

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
   +17%      +8  [ = ]       0    [Unmapped]
  +0.0%      +6  [ = ]       0    .debug_info
  +0.0%      +6  [ = ]       0    .strtab
  -0.0%      -4  -0.0%      -4    .text
  -0.0%     -10  [ = ]       0    .debug_loc
  -0.0%     -28  [ = ]       0    .debug_line
  -0.0%    -422  [ = ]       0    .debug_str
  -0.0%    -444  -0.0%      -4    TOTAL
use_rust/rp2040_split (peripheral) — 27.8 KiB → 27.8 KiB (+0.00%)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  25372	     60	   3028	  28460	   6f2c	peripheral

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  25372	     60	   3028	  28460	   6f2c	peripheral

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +11  [ = ]       0    .debug_str
  +1.7%      +1  [ = ]       0    [Unmapped]
  +0.0%     +12  [ = ]       0    TOTAL
use_rust/stm32f1 — 62.7 KiB → 62.6 KiB (-0.01% ⬇️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
  56636	     28	   7480	  64144	   fa90	rmk-stm32f1

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
  56648	     28	   7480	  64156	   fa9c	rmk-stm32f1

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +306  [ = ]       0    .debug_str
   +23%     +11  [ = ]       0    [Unmapped]
  +0.0%      +4  [ = ]       0    .debug_line
  -0.0%     -12  -0.0%     -12    .text
  -0.0%    -181  [ = ]       0    .debug_info
  +0.0%    +128  -0.0%     -12    TOTAL
use_rust/stm32h7 — 121.2 KiB → 121.2 KiB (+0.00% ⬆️)

cargo size (PR):

   text	   data	    bss	    dec	    hex	filename
 108260	    324	  15524	 124108	  1e4cc	rmk-stm32h7

cargo size (main):

   text	   data	    bss	    dec	    hex	filename
 108252	    324	  15524	 124100	  1e4c4	rmk-stm32h7

Bloaty diff (PR vs main):

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.1%    +170  [ = ]       0    .debug_line
  +0.0%      +8  +0.0%      +8    .text
  +0.0%      +6  [ = ]       0    .strtab
  -8.9%      -4  [ = ]       0    [Unmapped]
  -0.0%    -247  [ = ]       0    .debug_info
  -0.0%    -509  [ = ]       0    .debug_str
  -0.0%    -576  +0.0%      +8    TOTAL

when firmware is big enough and storage_start address is defined in [storage].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant