Skip to content

eeprom_stub - CDX replacement stub to allow interacting with EEPROM over UART#27

Open
m-kozlowski wants to merge 2 commits intoAsmageddon:masterfrom
m-kozlowski:eeprom_tool
Open

eeprom_stub - CDX replacement stub to allow interacting with EEPROM over UART#27
m-kozlowski wants to merge 2 commits intoAsmageddon:masterfrom
m-kozlowski:eeprom_tool

Conversation

@m-kozlowski
Copy link

Standalone firmware replacing the CDX slot (+host side: eeprom_tool.py).
Provides binary framed protocol over USART3 for EEPROM read/write/erase,
plus native bootloader Q/R frame compatibility for resmed_flash.py

  • Basic Read/Write/Erase operations (full/partial)
  • FAT12 filesystem access (requires pyfatfs)
  • Header checksum fixing
  • auto baud negotiation

Designed to be used as a CDX image, so it can be flashed using the original bootloader.
It preserves the original memory layout and basic compatibility with the ResMed protocol, so reverting to standard firmware can also be done conveniently using the UART flasher.

…ver UART

Standalone firmware replacing the CDX slot (+host side: eeprom_tool.py).
Provides binary framed protocol over USART3 for EEPROM read/write/erase,
plus native bootloader Q/R frame compatibility for resmed_flash.py

- Basic Read/Write/Erase operations (full/partial)
- FAT12 filesystem access (requires pyfatfs)
- Header checksum fixing
- auto baud negotiation
@m-kozlowski
Copy link
Author

empeka@jarvis:~/src/airbreak-plus$ make eeprom_stub
...
EEPROM stub built:
  build/eeprom_stub_nocrc.bin  (raw, for patched bootloader)
  build/eeprom_stub_full.bin   (768KB + CRC, for stock bootloader)
   text    data     bss     dec     hex filename
   5260       0    1564    6824    1aa8 build/eeprom_stub.elf

empeka@jarvis:~/src/airbreak-plus$ ./python/resmed_flash.py -p /dev/ttyACM0 --block cdx -f build/eeprom_stub_full.bin
...
============================================================
  Block: CDX (Firmware)
  Flash: 0x08040000 - 0x08100000
  Data:  786,432 bytes (trimmed from 786,432)
============================================================

[*] Erasing CDX (attempt 1)...
[*] Waiting for erase completion...
    Erase done [R]: P F *CDX (63 ACKs)

[*] Writing 786,432 bytes @ 460800 baud...
    786,432/786,432 (100%) in 26.1s, 3146 frames
...
[+] Flash complete!

empeka@jarvis:~/src/airbreak-plus$ ./python/eeprom_tool.py read -p /dev/ttyACM0 /tmp/eeprom.bin
Connected: eeprom_stub 2.1
Switched to 2000000 baud
Reading 262144 bytes from 0x00000...
Read 262144 bytes in 1.51s (169.8 KiB/s)
Saved to: /tmp/eeprom.bin

empeka@jarvis:~/src/airbreak-plus$ ./python/eeprom_tool.py write -p /dev/ttyACM0 /tmp/eeprom.bin
Connected: eeprom_stub 2.1
Switched to 2000000 baud
Writing 262144 bytes...
  100% (1024/1024)
Done: 3.09s (82.8 KiB/s)

empeka@jarvis:~/src/airbreak-plus$ ./python/resmed_flash.py -p /dev/ttyACM0 --block cdx -f stm32_patched.bin
[*] Loaded: /home/empeka/airbreak-plus/stm32_patched.bin (1,048,576 bytes)
[*] Image bootloader: SX577-0200

[*] Flash plan (SX577-0200 layout):
    CDX (Firmware): 786,432 bytes @ 0x08040000

[*] CRC validation:
    [+] CDX: stored=0x1F91 computed=0x1F91 OK
...
[*] Writing 786,432 bytes @ 460800 baud...
    786,432/786,432 (100%) in 26.8s, 3146 frames
...
[+] Flash complete!

@m-kozlowski
Copy link
Author

While it's possible to flash it with openocd, the preferred and best tested method is the flasher from #22

make eeprom_stub generates two images: eeprom_stub_full.bin to preserve compatibility with the bootloader's CRC16 verification, and eeprom_stub_nocrc.bin - a few kilobytes only, for super fast flashing. The latter requires a bootloader with checksum verification disabled (#26).

Add spin delays before and after the WREN transaction in eeprom_wren()
to guarantee both CS gaps: wait_ready->WREN and WREN->WRITE.

Fixes #9
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