logo elektroda
logo elektroda
X
logo elektroda

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

p.kaczmarek2 17520 419

TL;DR LABEL_AI_GENERATED

  • 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.
AI summary based on the discussion. May contain errors.
ADVERTISEMENT
Listen:
  • #391 21935670
    divadiow
    Level 38  
    Posts: 5215
    Help: 448
    Rate: 917
    thanks all :)


    Beken BK7231/BK7252 SPI flashing and recovery - new flasher tool and protocol specs Beken BK7231/BK7252 SPI flashing and recovery - new flasher tool and protocol specsScreenshot of BK7231 Easy UART Flasher showing a list of help links to forums and GitHub.

    Added after 13 [minutes]:

    but now I want to revise the links and wording on the Docs tab more 😈
  • ADVERTISEMENT
  • #392 21935713
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14763
    Help: 659
    Rate: 12896
    Can we merge what we have first?
    This empty place looked indeed better with more info, haha:
    Screenshot showing the message “eFuse read success!” on a green background.
    Helpful post? Buy me a coffee.
  • #393 21935750
    divadiow
    Level 38  
    Posts: 5215
    Help: 448
    Rate: 917
    <sigh> OK. It is back
  • #396 21937270
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14763
    Help: 659
    Rate: 12896
    Ok, however one PR requires conflicts resolve, also, what are stale KVs?
    Helpful post? Buy me a coffee.
  • Stale Tuya KVs still surface in extracted JSON

    #397 21937300
    divadiow
    Level 38  
    Posts: 5215
    Help: 448
    Rate: 917
    p.kaczmarek2 wrote:
    Ok, however one PR requires conflicts resolve

    fixed

    Added after 3 [minutes]:

    p.kaczmarek2 wrote:
    what are stale KVs?


    old Tuya key/value records that are still present in flash and still decrypt/CRC-check correctly, but are outside the active KVStorage window for the current config. They appear to be leftover records from previous storage pages/config writes, so the extractor code would merge them into the displayed JSON as if they were current live values.

    I checked 508 Tuya-named dumps. Of those, 491 produced valid Tuya config extractions, and 178 of those extracted JSON outputs were affected by this stale-KV surfacing.
  • ADVERTISEMENT
  • #400 21939017
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14763
    Help: 659
    Rate: 12896
    Great, merged. It seems we will need a separate topic guide/progress update for OPL soon.
    Helpful post? Buy me a coffee.
  • Non-Beken dumps can truncate KV extractions

    #401 21939254
    divadiow
    Level 38  
    Posts: 5215
    Help: 448
    Rate: 917
    bad test harness used when bulk testing PR 157. some non-Beken KV extractions are getting truncated extractions, so: https://github.com/openshwprojects/BK7231GUIFlashTool/pull/160

    divadiow wrote:
    there are 3 files in FlashDumps that contain config outside of the KV


    one of these is actually beken-crc but plain text.

    there are also 21 dumps where the pin mapping config is in the encrypted app. eg Tuya_Windows_Door_Vibration_(schemaID-e1kc5844)_ljwxe1cyevzjt8m2_CBU_1.0.3.bin

    Screenshot of BK7231 Easy UART Flasher showing Tuya configuration in JSON format
    Screenshot of BK7231 Easy UART Flasher showing Tuya config extraction, JSON data, and device configuration notes

    toying with added block to json output for these

    Screenshot of BK7231 Easy UART Flasher showing JSON config and extracted device pin details
  • #402 21939274
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14763
    Help: 659
    Rate: 12896
    Maybe more automatic tests are needed? Something that could run with each build?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #403 21939293
    divadiow
    Level 38  
    Posts: 5215
    Help: 448
    Rate: 917
    Good idea!
  • #404 21939813
    divadiow
    Level 38  
    Posts: 5215
    Help: 448
    Rate: 917
    Maybe after W800 custom stub. Just watchng Codex write, build and flash to a connected W800 at its own pace. Crazy

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


    Beken BK7231/BK7252 SPI flashing and recovery - new flasher tool and protocol specs
  • #405 21939833
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14763
    Help: 659
    Rate: 12896
    Is new stub faster than the current one?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #406 21939834
    divadiow
    Level 38  
    Posts: 5215
    Help: 448
    Rate: 917
    not sure yet, but it's more than that - efuse/rom read ability. compression. still in testing. not that there's anything particularly wrong with the current one.

    Added after 1 [minutes]:

    well, W806 read doesn't work with it, but I don't know if that's a stub problem or EF.
  • #407 21939948
    insmod
    Level 31  
    Posts: 1432
    Help: 168
    Rate: 455
    Why not port ECR stub?
  • #408 21939958
    divadiow
    Level 38  
    Posts: 5215
    Help: 448
    Rate: 917
    hmm dunno. it's not directly from ECR6600 stub code but it's been developed from the shared protocol conventions in all the other custom stubs, so effectively a port?
  • Miniz compression and hardware CRC speedup results

    #409 21940474
    divadiow
    Level 38  
    Posts: 5215
    Help: 448
    Rate: 917
    getting there I think. miniz too

    compressed 2mb W800 and 1mb W806 read
    Screenshot of BK7231 Easy UART Flasher showing “flash read success!” and a flash read log.

    accel crc too:
    Code: Text
    Log in, to see the code


    ROM read. W806 and W800 have identical ROMs
    Screenshot of BK7231 Easy UART Flasher showing “ROM read success!” and log output
  • #410 21940494
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14763
    Help: 659
    Rate: 12896
    That's a great result, what's currently the bottleneck? UART speed or CRC or compression/decompression? Can you show the current source?
    Helpful post? Buy me a coffee.
  • #411 21940497
    divadiow
    Level 38  
    Posts: 5215
    Help: 448
    Rate: 917
    hmm. dunno tbh. the 2mbps CH340N on my dev boards? I should do proper Upgrade Tools stub vs custom stub vs compressed tests but I'm away for the next couple of days.

    https://github.com/divadiow/w800_stub
    https://github.com/divadiow/BK7231GUIFlashTool/tree/w800stub

    Added after 8 [hours] 2 [minutes]:

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

    BK7258 efuse/rom/otp read
  • #412 21940556
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14763
    Help: 659
    Rate: 12896
    Thank you, merged.
    Helpful post? Buy me a coffee.
  • Compression halves BK7231 flash read and write times

    #413 21941637
    divadiow
    Level 38  
    Posts: 5215
    Help: 448
    Rate: 917
    divadiow wrote:
    Upgrade Tools stub vs custom stub vs compressed tests


    w800 currently (921600):
    OperationStub/modeTimeDifference vs original
    Read 2 MiBOriginal Upgrade Tools34.679 s / 34,679 msBaseline
    Read 2 MiBCustom, uncompressed33.992 s / 33,992 ms2.0% faster
    Read 2 MiBCustom, compressed16.011 s / 16,011 ms53.8% faster
    Write 2,088,960 bytesOriginal Upgrade Tools51.965 s / 51,965 msBaseline
    Write 2,088,960 bytesCustom, uncompressed58.081 s / 58,081 ms11.8% slower
    Write 2,088,960 bytesCustom, compressed25.764 s / 25,764 ms50.4% faster
    Erase writable flashOriginal Upgrade Tools4.184 s / 4,184 msBaseline
    Erase writable flashCustom12.996 s / 12,996 ms210.6% slower


    so compression is the obvious winner. I'll tweak stub more to at least match original stub for non-compressed operations.

    Added after 4 [hours] 2 [minutes]:

    OK. improved.

    OperationStub/modeUpdated timeDifference vs original
    Read 2 MiBOriginal Upgrade Tools35.263 s / 35,263 msBaseline
    Read 2 MiBCustom, uncompressed33.183 s / 33,183 ms5.9% faster
    Read 2 MiBCustom, compressed16.072 s / 16,072 ms54.4% faster
    Write 2,088,960 bytesOriginal Upgrade Tools50.669 s / 50,669 msBaseline
    Write 2,088,960 bytesCustom, uncompressed42.447 s / 42,447 ms16.2% faster
    Write 2,088,960 bytesCustom, compressed25.646 s / 25,646 ms49.4% faster
    Erase writable flashOriginal Upgrade Tools4.208 s / 4,208 msBaseline
    Erase writable flashCustom4.931 s / 4,931 ms17.2% slower


    A trace showed that corrupt XMODEM packets were detected and retried as intended. However, if the one-byte ACK or NAK response was lost, the stub waited approximately 10.02 seconds before retransmitting. This delay occurred in three of six successful baseline Easy Flasher reads; two other baseline attempts failed.
    The custom stub’s actual erase command takes approximately 1.35 seconds. The table measures the complete operation, including setup and uploading the 13.3 KiB custom stub, leaving it 0.723 seconds slower overall than the factory-loader operation. When the custom stub is already resident, the erase operation is substantially faster.

    Changes made:
    Mixed 4 KiB sector and 64 KiB block erasing.
    A full W800 writable-area erase now uses 14 sectors and 31 blocks.
    Raw writes erase the destination efficiently before XMODEM reception.
    Completely blank 0xFF pages are not unnecessarily programmed.
    Nonblank pages still receive immediate readback comparison.
    Easy Flasher still performs its final hardware CRC32 verification.
    XMODEM packet size and ACK/NAK protocol remain unchanged.
    The stub’s ACK-response timeout was reduced from approximately 10 seconds to approximately 2 seconds.
    Easy Flasher now requests retransmission after one second on W800 reads.
    The stub’s packet retry allowance was increased from 10 to 30.

    In final testing, 15/15 uncompressed and 10/10 compressed cold-upload reads completed with matching CRC32 values, without the 10-second delay or truncated transfers.
  • Proposal for automated Tuya config self-tests

    #414 21942290
    divadiow
    Level 38  
    Posts: 5215
    Help: 448
    Rate: 917
    p.kaczmarek2 wrote:
    Maybe more automatic tests are needed? Something that could run with each build?


    something like this? https://github.com/openshwprojects/BK7231GUIF...vadiow:BK7231GUIFlashTool:tuyaconfig-selftest

    it tests quite a lot, including matching human-readable output. tests would need updating if tweaks were made that affected anything. could be annoying, but it is more complete?

    Added after 2 [minutes]:

    test binaries are all real dumps but are all FF apart from KV/PSM areas. same offset as original. gzipped

    build.bat
    Code: Text
    Log in, to see the code


    Added after 5 [minutes]:


    Beken BK7231/BK7252 SPI flashing and recovery - new flasher tool and protocol specs
  • #415 21943539
    divadiow
    Level 38  
    Posts: 5215
    Help: 448
    Rate: 917
    >>21941637

    automated W800 tests with current code custom stub

    Screenshot with a table of read, erase, and write test results for multiple baud rates.

    lol. just realised the w800 was blank
  • Semantic Release proposed for sequential Easy Flasher versions

    #416 21944462
    divadiow
    Level 38  
    Posts: 5215
    Help: 448
    Rate: 917
    Update GitHub Actions for Node.js 24 https://github.com/openshwprojects/BK7231GUIFlashTool/pull/162

    Added after 9 [hours] 8 [minutes]:

    switch to Semantic Release so Easy Flasher release number is sequential rather than based on workflow number? So no more release number jumps like for eg v440 straight to v444.

    The repository’s old highest SemVer tag is v1.1.7 so start from v1.1.447.

    The current release being "BK7231GUIFlashTool build 446".

    GitHub Actions screenshot: “Build and Release” workflow succeeded with three steps.

    https://github.com/openshwprojects/BK7231GUIFlashTool/pull/164
  • #417 21945120
    divadiow
    Level 38  
    Posts: 5215
    Help: 448
    Rate: 917
    divadiow wrote:

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

    Added after 8 [hours] 49 [minutes]:

    couple of more tweaks. ive put lan scanner pr into draft for some more work to be done on it finished

    https://github.com/openshwprojects/BK7231GUIFlashTool/pull/166
  • #418 21945482
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14763
    Help: 659
    Rate: 12896
    Nice, but two suggestions/questions.
    1. Do we really need to check 1:1 human readable output? Maybe we do, but if someone formats it more, it will fail self test:
    Beken BK7231/BK7252 SPI flashing and recovery - new flasher tool and protocol specs
    Still, maybe it makes sense
    2. Do validation of json output checks existence of object fields, or does it blindly compare strings?
    Helpful post? Buy me a coffee.
  • Exact golden-output comparison for JSON validation

    #419 21945503
    divadiow
    Level 38  
    Posts: 5215
    Help: 448
    Rate: 917
    p.kaczmarek2 wrote:
    1. Do we really need to check 1:1 human readable output? Maybe we do, but if someone formats it more, it will fail self test:


    well, not sure. it does add complexity, but then it may also catch things. depends I guess how annoying it becomes to update when a change it made that requires self-test updates. Maybe it won't be frequent enough to be an issue...

    p.kaczmarek2 wrote:
    Do validation of json output checks existence of object fields, or does it blindly compare strings?


    It performs an exact golden-output comparison, ignoring only line ending differences. It doesn’t inspect fields individually, but missing, added, reordered, or changed fields will all fail because the complete output must match the known-good baseline.
  • Compiler-state generation of enabledFeatures.md

    #420 21948335
    divadiow
    Level 38  
    Posts: 5215
    Help: 448
    Rate: 917
    divadiow wrote:


    reworked this.

    more accurate, simpler output file.
    enabledFeatures.md
    is now generated from the compiler state of every real platform and variant build. Previously, js attempted to reproduce the build rules and infer which features should be enabled. The new method records which macros are actually active during compilation, so platform-, SDK- and variant-specific settings are included automatically.

    It does create temporary manifest artefacts before the
    enabledFeatures.md
    is generated, but these are deleted before completion.

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

    rehearsal run https://github.com/divadiow/OpenBK7231T_App/actions/runs/30686747902
    rehearsal enabledFeatures https://github.com/divadiow/OpenBK7231T_App/blob/main/docs/enabledFeatures.md

    Added after 27 [minutes]:

    a little snag. cleanup can't be performed when pr builds are built before merge in upstream eg: https://github.com/openshwprojects/OpenBK7231T_App/actions/runs/30687368843

    so skip cleanup if no write access, set retention on manifest files to 1 day. https://github.com/openshwprojects/OpenBK7231T_App/actions/runs/30687969003
Listen:

Topic summary

LABEL_AI_GENERATED
The discussion centers on BK7231/BK7252 SPI flashing and recovery using BK7231GUIFlashTool v98+, which adds a new SPI-based flashing method requiring only a CH341 SPI programmer. The method is intended for recovering bricked Beken devices with overwritten bootloaders and also works as a general SPI flasher for external flash chips. Participants test and debug the new SPI mode, including COM-port handling, CH341 DLL loading, verify behavior, and Linux/Mono compatibility. The thread then expands into broader flasher development: UART and SPI improvements, flash-size detection, unprotect logic, retry mechanisms, baud-rate limits, and support for additional platforms such as RTL8720D, RTLZ/RTLZ2, BL602, LN882H, W600/W800, ECR6600, and remote flashing over TCP-to-UART. Several fixes are merged, including backup restore, erase/write handling, config read/write, and improved detection and logging.
AI summary based on the discussion. May contain errors.

FAQ LABEL_AI_GENERATED

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]
AI summary based on the discussion. May contain errors.
ADVERTISEMENT