logo elektroda
logo elektroda
X
logo elektroda
Dostępna jest polska wersja

Czy wolisz polską wersję strony elektroda?

Nie, dziękuję Przekieruj mnie tam

Beken BK7231/BK7252 SPI flashing and recovery - new flasher tool and protocol specs

p.kaczmarek2 10449 298

TL;DR

  • BK7231GUIFlashTool v98+ adds CH341-based SPI flashing and recovery for Beken BK7231/BK7252 chips, including bricked devices with overwritten bootloaders.
  • The tool uses CH341 DLL C# bindings to toggle CEN via D2, reset the chip, send 0xD2, then flash Beken chips like generic SPI memory.
  • Connections use P20, P21, P22, and P23 for SCK, CSN, SI, and SO, with CEN wired to D2 and the CH341 jumper set to I2C mode.
  • A sample read identifies JEDEC ID FF-EF-40-16 and a 4096 KB flash, and the same tool can Read, Write, Verify, and Erase firmware.
  • If CH341 is not detected or CEN toggle fails, check driver configuration, jumper position, SPI wiring, and power before trying Beken SPI mode again.
Generated by the language model.
ADVERTISEMENT
📢 Listen (AI):
  • #271 21855421
    DeDaMrAz
    Level 22  
    @divadiow

    Can you see what you can find from this dump
    Attachments:
    • readResult_BK7238_QIO_T1UHL_63A_breaker_2026-05-3-20-23-51.bin (2 MB) You must be logged in to download this attachment.
  • ADVERTISEMENT
  • #272 21855433
    divadiow
    Level 38  
    DeDaMrAz wrote:
    Can you see what you can find from this dump


    what beyond the usual boot log and kv extraction are you after?

    Code: Text
    Log in, to see the code


    Code: JSON
    Log in, to see the code


    Code: Text
    Log in, to see the code
  • #273 21855435
    p.kaczmarek2
    Moderator Smart Home
    @divadiow nice, but is it really more stable? Futhermore, I remember i tried to add retry on beken, and bk7231 chips didn't cooperate. It's different on RTL?
    Helpful post? Buy me a coffee.
  • #274 21855437
    divadiow
    Level 38  
    >>21855435

    it's always completes for me and file comparisons are identical. It's had lots of testing. Previous flasher would not begin read for me usually. This behaves more like PGTool for timings and connection.

    Added after 1 [minutes]:

    it allowed this user to backup/flash and it has improved since then https://www.elektroda.com/rtvforum/topic4166319.html#21853518
  • #275 21855439
    DeDaMrAz
    Level 22  
    divadiow wrote:
    [01-01 00:00:00 ty N][43ed][device_config_load.c:1100] product have measure , chip is 3 vol is 2200  res is 0


    What is this related to?

    On this device ADC pin is connected, but will have to investigate more, looks like an NTC/PTC is attached there.
  • ADVERTISEMENT
  • #276 21855494
    divadiow
    Level 38  
    divadiow wrote:
    more like PGTool for timings and connection

    but it goes way beyond what LT/PGTool does for retries, checks, resiliency

    Added after 9 [hours] 20 [minutes]:

    to illustrate with some extremes:

    20cm cables, 1.5m baud
    animated. some retries, recoveries, completion
    Screenshot of BK7231 Easy UART Flasher with COM52 selected and status “Doing nothing..”

    30cm cables with join at 20cm, 1.5m baud.
    took 19 mins so no gif, but resultant file was identical to one above. speed because baud was auto dropped to 115200 after failures
    Code: Text
    Log in, to see the code
  • #277 21856291
    divadiow
    Level 38  
    insmod wrote:
    Z2 flasher, use dump words instead of dump bytes for faster read times?


    switched

    DumpBytes - r24 - Read
    ~2min 26s - 921600
    ~1min 36s - 3000000

    DumpWords - r25 - Read
    ~2min 6s - 921600
    ~1min 19s - 3000000

    14%-18% speed improvement

    Added after 8 [minutes]:

    r26 - fixed a little bug

    2min 2s - 921600 - no retries
    1min 18s- 3000000 - 7 retries

    Added after 15 [minutes]:

    got a working TR6260 waiting in the wings too

    Screenshot of BK7231 Easy UART Flasher showing “Write done” and a TR6260 flashing log
  • ADVERTISEMENT
  • #278 21857508
    divadiow
    Level 38  
    I believe Easyflash for TR6260 requires GRAN=32 so have built WinEF_GRAN32_x64.dll and WinEF_GRAN32_x86.dll - that correct @insmod ?

    Screenshot of Visual Studio showing Output window after a successful build of WinEF project
  • #279 21857810
    p.kaczmarek2
    Moderator Smart Home
    Ok so how is the state of "make resilient Realtek Z2 read/write, add erase, update erase all text content" PR? Is it ready to merge?
    Helpful post? Buy me a coffee.
  • #280 21857816
    divadiow
    Level 38  
    sure. I would say yes. I've done a ton of testing.

    Added after 2 [hours] 57 [minutes]:

    thanks for merging! hope it's all good. felt good.
  • #281 21857991
    p.kaczmarek2
    Moderator Smart Home
    Thank you for contribution. If you are interested, maybe you can also help a bit with https://github.com/openshwprojects/EasyGUIFlashTool ? At least make it usable for basic, most common cases
    Helpful post? Buy me a coffee.
  • #282 21858002
    divadiow
    Level 38  
    could have a go. I think TR6260 for classic tool is almost good too, so will finish that today I think

    Added after 6 [hours] 24 [minutes]:

    TR6260 is done I believe.
    -read/erase assumes flash is 1mb
    -erase whole flash support. erases before write operations
    -read/write backups and OpenTR6260 release (including bootloader and partition file)
    -supports OBK config read/write - GRAN32 implemented without EF dlls

    animated
    Screenshot of BK7231 Easy UART Flasher with TR6260 and COM46 selected, status “Doing nothing..”
    Screenshot of BK7231 Easy UART Flasher set to COM46 and TR6260; status reads “Doing nothing..”

    bauds not seen in utpmain are blocked
    Screenshot of BK7231 Easy UART Flasher showing “Unsupported baud” at 230400

    https://github.com/openshwprojects/BK7231GUIFlashTool/pull/112
  • #284 21863357
    p.kaczmarek2
    Moderator Smart Home
    Nice, you're going fast. What are the speeds? Still, need to resolve a conflict with current main first.
    Helpful post? Buy me a coffee.
  • #285 21864040
    divadiow
    Level 38  
    p.kaczmarek2 wrote:
    What are the speeds?

    the supported XR806 speeds? I think in total it's 110, 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600

    fixed merged conflict and a couple of other bits. I think it's good to go. Revisions, fixes, PRs to anything 'I' create always welcome.

    Added after 1 [minutes]:

    divadiow wrote:
    the supported XR806 speeds? 115200, 230400, 460800, 921600

    this is despite the bauds available in PhoenixMC. BROM <= 1 (XR809) has a stub

    Added after 12 [minutes]:

    divadiow wrote:
    this is despite the bauds available in PhoenixMC.

    that's the analysis from the Linux PhoenixMC anyway. Maybe it can do higher. Windows GUI shows higher

    Dropdown menu with numeric options, highlighting “921600”

    Added after 1 [hours] 38 [minutes]:

    XR806 can be faster/better and I am looking at what next, but current PR works.

    Added after 10 [hours] 1 [minutes]:

    divadiow wrote:
    the supported XR806 speeds?

    PhoenixMC.exe response.

    PhoenixMC dialog showing “Support bauds” list of baud rates and an OK button

    but timings, sector size, chunks etc don't change so not much to be gained.

    got latest EF XR806 2mb whole-flash read speed to ~47s @921600
  • #286 21865624
    divadiow
    Level 38  
    XR806 Pt2 is better.

    - Support 'upgrade' command for firmware with Console code enabled (seen in OpenXR872)
    - Reads BROM version (no longer complains about non-BROM 3 detection - WXU is BROM 4 and devboard is BROM 3)
    - Reads flash ID
    - Logs flash size

    - Full flash read (2mb 41s @921600, 37s @3000000)
    - Custom-offset read
    - Chunked read transfer with retry / recovery handling

    - Full-chip erase
    - Explicitly full-chip-only behaviour for XR806

    - Main firmware write from .img file
    - Main full-flash restore from raw .bin file
    - Custom-offset raw write from .bin file
    - Backup-then-flash workflow
    - Chunked write transfer with retry / recovery handling

    .img on main write path:
    - Parsed as XR image layout
    - Validated before programming
    - Written from base flash offset 0x000000
    .bin on main write path:
    - Treated as raw flash data
    - Written from base flash offset 0x000000
    - Not truncated to image partition/layout size
    .bin on custom write path:
    - Treated as raw bytes only
    - Written to the user-selected offset
    - No image-layout parsing

    XR image validation:
    - AWIH header validation
    - Header checksum validation
    - Section data checksum validation
    - Section-chain walking
    - Effective image size calculation
    - Image layout logging

    XR image safety checks:
    - Rejects invalid AWIH magic
    - Rejects bad header checksum
    - Rejects bad data checksum
    - Rejects next-section pointers that fall inside the current section
    - Rejects next-section pointers outside file range
    - Rejects non-header targets in the section chain
    - Rejects section data that overruns the file
    - Rejects overlapping, looping, or non-advancing section chains

    Safety and resilience:
    - Initial sync retries before failure
    - Session recovery and reconnect logic on read/write failures
    - Flash-range bounds checking before write
    - BROM response payload sanity checking
    - Progress and policy logging for key operations

    operational behaviour:
    - Main write path performs full-chip erase before programming
    - Custom raw write path does not erase first
    - Backup-and-flash in one session
    - Firmware is not run/device not rebooted after flash write

    Screenshot of BK7231 Easy UART Flasher showing checksum error logs and the status “Doing nothing..”

    https://github.com/openshwprojects/BK7231GUIFlashTool/pull/114

    Added after 5 [minutes]:

    appears to work fine for XR872 too, because it's BROM2+, so XR872 should be easy adaptation next

    Added after 8 [hours] 52 [minutes]:

    a couple of tweaks. flush after erase, added chip type response.
    example with erase operation:
    Screenshot of BK7231 Easy UART Flasher showing “Erase complete” and an XR806 log on COM52

    Added after 8 [hours] 46 [minutes]:

    -add XR872, same abilities as XR806
    -sort chip list alphabetically
    -make log box auto-scroll instead of only catching-up on newline
    -update readme
    -set BK7231N as default chip (was BK7231T, alphabet sort made index 0 default to BK7231M)
    -set 115200 as default baud (was 230400)

    erase
    Screenshot of BK7231 Easy UART Flasher showing “Erase complete” for XR872 on COM3
    flash OpenXR872 (to 1mb XF16)
    Screenshot of BK7231 Easy UART Flasher showing “Write complete” and a flashing operation log.
    read at 1.5m baud (resync/retries are expected - PhoenixMC drops to 115200 for this XF16)
    Screenshot of BK7231 Easy UART Flasher showing XR872 flash read log and “Read complete”
    read at 115200
    Screenshot of BK7231 Easy UART Flasher showing “Read complete” and a flash read log for XR872.
    EF/PhoenixMC dumps are identical

    auto-scroll behaviour (animated):
    Screenshot of BK7231 Easy UART Flasher showing “Interrupted by user.”

    https://github.com/openshwprojects/BK7231GUIFlashTool/pull/115

    Added after 7 [minutes]:

    sorted chip list

    Screenshot of BK7231 Easy UART Flasher with chip-type dropdown open and “Write success!” message
  • #287 21867006
    p.kaczmarek2
    Moderator Smart Home
    Almost perfect, however, I would think twice about changing enumeration order. Are we really sure it's not saved anywhere as index? But maybe not...
    Helpful post? Buy me a coffee.
  • #288 21867012
    divadiow
    Level 38  
    ah, I did check. it's purely display order. nothing seems to index them numerically. References are to BKType rather than a positional index.

    Added after 1 [hours] 38 [minutes]:

    @p.kaczmarek2 also make scan status box resize proportional to main window (@dedamraz request) + add subnet picker from local machine network interfaces
    https://github.com/openshwprojects/BK7231GUIFlashTool/pull/116

    Two BK7231 Easy UART Flasher windows with empty LAN scan list and Start IP/End IP fields
    Screenshot of BK7231 Easy UART Flasher showing subnet dropdown, IP range fields, and Start button
  • #290 21867079
    p.kaczmarek2
    Moderator Smart Home
    Hmm okay, I guess it's acceptable, then. Thanks.

    Are XR flashing protocols much different?
    Helpful post? Buy me a coffee.
  • #291 21867145
    divadiow
    Level 38  
    yay, thanks for merging!

    p.kaczmarek2 wrote:
    Are XR flashing protocols much different?


    mostly the same. but with BROM < 2 (eg XR809) although it supports the same basic BROM-direct commands like
    GetFlashID 0x18
    , it requires stub loader for erase/write/read operations.

    BROM >= 3 (BROM 4 seen on real WXU and BROM 3 seen on AllWinner XR806 dev board) support an alternate set of opcodes, I have not used these. Legacy family used for all our XRs. Not sure of the purpose/advantage of the newer family.

    legacy:
    GetFlashID 0x18
    ReadSector 0x1A
    EraseFlash 0x19
    WriteSector 0x1B

    alternate:
    GetFlashID 0x1C
    ReadSector 0x1E
    EraseFlash 0x1D
    WriteSector 0x1F

    Not entirely sure when and why alternate family gets used.
  • ADVERTISEMENT
  • #293 21868369
    p.kaczmarek2
    Moderator Smart Home
    Nice, thank you. What's now missing from main (old) Easy Flasher?
    Helpful post? Buy me a coffee.
  • #294 21868515
    divadiow
    Level 38  
    chip-wise? the rest of the ESPs I guess. Also BK7252 wrap-around still needs fixing.

    potentially TXW81X, but I hadn't really considered it. There's also the other RTLs, not sure if @insmod was going to do them one day or.. dunno.
  • #295 21869082
    insmod
    Level 31  
    XRs really need to be either merged together into one, or majority of the code to be moved to some base class, like XRBaseFlasher.

    Is there really a need to check for allowed baud?
    Since it's passed as a value and not as an index like on RTLB/D, perhaps it can be removed?

    Does XR809 support 230400-460800 baud?
    XR809 can erase by blocks. Do others support it too?

    Perhaps create alternate stub for all of them, using LN ramcode as a base?
  • #296 21869085
    divadiow
    Level 38  
    insmod wrote:
    XRs really need to be either merged together into one, or majority of the code to be moved to some base class, like XRBaseFlasher


    I guess that would make sense

    insmod wrote:
    XR809 can erase by blocks. Do others support it too?


    Yes

    I had a feeling XR wouldn't sync at bauds it didn't report as supported. Can check in morning

    Hadn't even considered custom stub for them all.

    Feel free to sort it all out!

    Added after 6 [hours] 50 [minutes]:

    insmod wrote:
    XR809 can erase by blocks. Do others support it too?


    there isn't custom erase function in EF so didn't look to implement. earlier XR806 builds erased whole chip in 64k sectors

    Added after 11 [hours] 34 [minutes]:

    I recall now. the restrictions in XR806 won't get hit anyway because the supported list includes all the EF baud options.

    XR809 fails the baud change command for 230400, 460800 and 2m
    Screenshot of BK7231 Easy UART Flasher showing “Interrupted by user” and a baud rate error log
    XR872 fails the baud change for 230400, 460800 but does have a go at 2m
    Screenshot of BK7231 Easy UART Flasher showing read log and baud rate change errors

    re XR809 the command sent for those unsupported bauds is sound.
    Table of baud-rate packets with hex payloads and PhoenixMC support marks

    PhoenixMC response for each:
    phoenixMC dialog “XR806 BROM3” showing supported baud rates list and an OK button. phoenixMC dialog “XR872 BROM2” listing supported baud rates, with an OK button phoenixMC warning dialog: “XR809 BROM1” with a list of supported baud rates

    restrictions removed test build: https://github.com/divadiow/BK7231GUIFlashTool/actions/runs/23495167292
  • #298 21876109
    p.kaczmarek2
    Moderator Smart Home
    Are there any regressions? Dumps that used to be decoded correctly but now fail?
    Helpful post? Buy me a coffee.
  • #299 21876232
    divadiow
    Level 38  
    hmm. some of the 'classic' jsons are different. not sure you'd call them regressions. tbh it'd be easier/cleaner if the classic was done away with completely

    Code: Text
    Log in, to see the code


    Code: Text
    Log in, to see the code


    Added after 3 [hours] 21 [minutes]:

    OK. PR now =

    313 files checked
    classic JSON: identical on every tested dump that extracted before
    enhanced JSON: identical on every tested dump that extracted before
    LN882H problem dump: no longer crashes, now cleanly lands in enhanced fallback
    the 2 known fromFile_failed files: unchanged (I know what one of these is (new KV type) and I'll look into the other one)
    6 ESP8266 dumps: improved from no_keys to enhanced_fallback
📢 Listen (AI):

Topic summary

✨ BK7231GUIFlashTool version 98 and later introduces a new SPI flashing method for Beken BK7231/BK7252 devices using only a CH341 SPI programmer. This method enables recovery of bricked devices with overwritten bootloaders and functions as a general-purpose SPI flasher supporting various memory chips. The approach builds on previous SPI programming techniques using Python and Banana Pi, adapting them for CH341 hardware and C# implementation. Required hardware includes a CH341 programmer and soldering tools for wire attachment. Recent user feedback on version 98 highlights issues such as the tool requiring a COM port selection in SPI mode, lack of CH341A detection warnings, and missing ch341dll.dll errors. The developer has addressed the COM port requirement and plans to add the missing DLL, requesting further debugging via Visual Studio to handle CH341 initialization exceptions.
Generated by the language model.

FAQ

TL;DR: New BK7231GUIFlashTool v98+ adds SPI flashing for Beken chips; sample 4,096 KB flash detected. “Only a CH341 SPI programmer is required.” Use CH341A D2 to toggle CEN, send 0xD2, then read/write like generic SPI. [Elektroda, p.kaczmarek2, post #21711721]

Why it matters: It lets you recover bricked BK7231/BK7252 devices without a working bootloader, using low‑cost tools.

Who this is for: DIYers, repair techs, and firmware engineers asking how to unbrick or mass‑flash Beken SoCs via SPI with a CH341A and the latest tool.

Quick Facts

What exactly is the new Beken SPI flashing method and what do I need?

The tool drives CH341A as an SPI master, resets BK via CEN on D2, sends 0xD2 to enter BK’s SPI-memory mode, then treats the chip like a standard SPI flash. You need a CH341A (jumper at I2C), 3.3 V power, and wiring for P20–P23 (SCK/CSN/SI/SO) plus CEN. Select “Beken SPI” in BK7231GUIFlashTool v98+. “Only a CH341 SPI programmer is required.” [Elektroda, p.kaczmarek2, post #21711721]

How do I wire CH341A to BK7231/BK7252 for SPI mode?

Connect CH341A SCK→P20, CS0→P21, MOSI→P22 (SI), MISO→P23 (SO), and D2→CEN. Keep MOSI→SI and MISO→SO mapping. Provide GND and target power. Some boards have pads labeled CE/TCK/TMS/TDI/TDO that map to CEN/SCK/CSN/SI/SO respectively. [Elektroda, p.kaczmarek2, post #21711721]

How do I reliably enter BK SPI mode? (3‑step)

  1. Use CH341 D2 to pull CEN low then high to reset the BK chip. 2. Stream 0xD2 bytes repeatedly over SPI. 3. Issue 0x9F and confirm a valid JEDEC response; then proceed to Read/Write/Erase. [Elektroda, p.kaczmarek2, post #21711721]

I get “Failed to open CH341 device” or “Failed to toggle CEN.” What should I check?

Confirm CH341A is jumpered to I2C, recognized by Windows, and the D2 wire is soldered to CEN. Re‑seat USB, power the target, and verify SPI lines. The tool logs these errors when CH341 isn’t detected or CEN can’t be driven; fix wiring or driver, then retry. [Elektroda, p.kaczmarek2, post #21711721]

The app says “missing ch341dll.dll” or quits in SPI mode—how do I fix that?

Place CH341DLL.DLL alongside the GitHub build, or build from source in Visual Studio. Earlier builds could exit if CH341A wasn’t present; recent fixes improved handling, but adding the DLL resolved missing‑library errors during testing. [Elektroda, divadiow, post #21712310]

Do I need to select a COM port for SPI flashing?

No. As of v99, SPI mode does not require a COM port. This was confirmed after fixes; previous v98 prompts were removed. Ensure CH341A is connected; SPI operations run without a serial port. [Elektroda, divadiow, post #21712310]

What does the Verify button do?

Verify compares flash contents against the firmware file currently selected in the tool. Use it after Write or Erase to confirm success. “Verify verifies against selected firmware.” [Elektroda, p.kaczmarek2, post #21712551]

Can this recover a bricked BK7252 camera?

Yes. After wiring CEN and SPI lines, use Beken SPI mode to read/erase/write. The author provides a BK7252 camera recovery example using this exact method with CH341A and the new flasher. [Elektroda, p.kaczmarek2, post #21711721]

Can I use CH341 Programmer or NeoProgrammer once SPI mode is active?

Yes. After the 0xD2 hand‑off, the BK behaves like a generic SPI flash. You can then operate with common SPI flash tools (CH341 Programmer or NeoProgrammer) if you prefer. [Elektroda, p.kaczmarek2, post #21711721]

Linux support: what baud rates are stable under mono?

Mono 6.12 worked for testers. They reported stable operation at 921,600 baud; 1,500,000 worked on Windows, but they lowered to 921,600 on Linux. LAN Scanner and release downloader also worked. [Elektroda, insmod, post #21712663]

The tool shows a 4,096 KB device. Is that normal for these chips?

Yes. A sample JEDEC ID FF‑EF‑40‑16 decoded to 4,096 KB and printed by the tool. That confirms JEDEC read and size decoding in SPI mode. Actual sizes vary by module; always check the tool’s detected flash size. [Elektroda, p.kaczmarek2, post #21711721]

How do I just switch a BK device into SPI mode without reading or writing?

Use the new “Detect” button. It performs a zero‑length custom operation to toggle CEN and send the 0xD2 sync, placing the chip in SPI mode for use with other SPI tools. [Elektroda, p.kaczmarek2, post #21731041]

I flashed many times and now erase fails. What should I try?

Expand Unprotect logic before erase, similar to AsProgrammer. A contributor noted needing stronger Unprotect after many BK7252 cycles. Add an Unprotect/Status-Register release step, then retry the erase/write. [Elektroda, p.kaczmarek2, post #21714737]

What is OpenBeken (OBK) in this context?

OpenBeken is an open‑source firmware used across supported Wi‑Fi MCUs in this ecosystem. The author uses OBK devices for testing and demos, including camera boards and remote flashing concepts. [Elektroda, p.kaczmarek2, post #21714427]

Can I flash a BK device over Wi‑Fi/TCP instead of USB?

Yes, a Wi‑Fi flasher demo proxies UART over TCP and controls CEN via an OBK device. It’s a separate utility that mirrors the BK UART routines, useful when PC‑to‑target wiring is hard. [Elektroda, p.kaczmarek2, post #21720013]

Any known edge cases or failure symptoms I should expect?

If CH341DLL is missing, some GitHub builds previously exited. On mono/Linux, 1,500,000 baud may fail while 921,600 works. Also, after heavy cycling, protection bits may block erase until Unprotect expands. Address each symptom as noted, then retry. [Elektroda, divadiow, post #21712310]
Generated by the language model.
ADVERTISEMENT