logo elektroda
logo elektroda
X
logo elektroda

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

p.kaczmarek2 11430 310

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):
  • #121 21777354
    p.kaczmarek2
    Moderator Smart Home
    Try to remove those binary arrays (make them empty), rebuild and recheck
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #123 21777450
    p.kaczmarek2
    Moderator Smart Home
    We need to pinpoint each change that breaks.

    Also, what about "encryption experiments" PR? Ready to merge?
    Helpful post? Buy me a coffee.
  • #124 21777517
    divadiow
    Level 38  
    p.kaczmarek2 wrote:
    Also, what about "encryption experiments" PR? Ready to merge?


    I used it a fair bit a few weeks ago and it was good. A couple of issues were ironed out and I would say yes

    Added after 7 [minutes]:

    p.kaczmarek2 wrote:
    We need to pinpoint each change that breaks.

    in the meantime though maybe a sticky topic in issues? I asked GPT to draft something after my conversation with it.

    Spoiler:
    Why Some Antivirus Products Flag BK7231GUIFlashTool (False Positives Explained)

    Proposed Body Text

    Several users have reported that recent builds of BK7231GUIFlashTool trigger warnings from certain antivirus engines. These detections often appear under generic names such as Trojan.MSILZilla.xxx, MSIL.Generic, or similar. This notice explains why this happens, what changed recently, and what you can safely expect from the tool’s behaviour.

    1. The short answer

    These antivirus alerts are false positives.
    BK7231GUIFlashTool is an open-source, C#/.NET WinForms application whose only functions are:

    Opening a serial port

    Communicating with supported MCUs

    Reading/writing flash memory

    Loading firmware files (optionally downloading them from GitHub)

    Displaying progress in a simple UI

    Nothing in the source code installs persistence, modifies the registry, injects into processes, or communicates with anything other than GitHub (when the “download latest firmware” option is used) and the serial port.

    2. Why AV engines sometimes flag the tool

    Modern antivirus products rely heavily on heuristic and reputation-based detection. A small, unsigned, niche hardware-flashing utility looks very similar—structurally—to the tools used by malware operators, even though the behaviour is entirely legitimate.

    The tool has several characteristics that mislead heuristic scanners:

    a) It is a .NET (MSIL) executable

    Many malware families are also written in .NET, so generic signatures tend to over-match.

    b) It performs “downloader-like” behaviour

    When you click “Download firmware from Web”, the application downloads a binary file from GitHub and saves it to disk.
    Heuristic engines sometimes classify any application that downloads executable files as a “downloader”, regardless of purpose.

    c) It interacts with hardware at a low level

    The program reads and writes flash memory over UART, sends stubs/loaders to the device, and transfers raw binary blocks. Tools doing this kind of I/O get flagged routinely, even though this is exactly what a flashing utility is supposed to do.

    d) It is not code-signed

    Unsigned executables with a small user base are automatically given lower reputation scores. This can increase false positives, especially immediately after a new release.

    e) Some recent releases introduced new stubs/loaders

    Binary blobs included inside the release package (e.g., RTL loader files, temporary loaders) can resemble obfuscated or “packed” resources to AV engines, which further increases the likelihood of a generic detection.

    3. What changed in v32 and earlier—did anything suspicious get added?

    No. Recent versions (v27–v32 and surrounding builds) include:

    RTL flashing improvements

    Flash ID read support

    Logging fixes

    A progress bar calculation fix

    CI packaging changes (adding the /loaders folder to the release ZIP)

    No networking changes, no system-level changes, and no code capable of malicious behaviour were introduced. The tool’s functionality has remained the same: serial-port flashing and firmware utility tasks.

    False positives became more common simply because the build output changed slightly, altering the internal structure enough for heuristic signatures to trigger.

    4. What you can do as a user

    If your antivirus flags the tool, you may safely trust / allow it provided you downloaded it from the official GitHub Releases page.

    You can also build the tool yourself from source using Visual Studio, which eliminates any doubt about the executable’s origin.

    Consider adding a local exclusion for the flashing tool if your security software interferes with its operation.

    If comfortable, you can submit the file to your AV vendor as a false positive—they typically whitelist legitimate tools once reviewed.

    5. What we (the maintainers) will continue to do

    Keep the tool fully open-source and transparent.

    Avoid unnecessary obfuscation or packing.

    Work with contributors to minimise false-positive triggers where feasible.

    Investigate code-signing options for future releases to reduce reputation-based alerts.

    6. Bottom line

    BK7231GUIFlashTool is safe, open, and does exactly what a flashing tool needs to do—and nothing more.
    AV detections are a side effect of heuristic scanning on a low-reputation, unsigned, hardware-flashing application, not an indication of malicious behaviour.

    If you have questions or encounter new detections, feel free to comment below.
  • #127 21778541
    divadiow
    Level 38  
    I've been playing with BK7252 2/4mb wrap-around and generally with BK7252U BK7231T/U it seems to give up some as soon as there's a read error, no retries /per sector crc check? Is this correct? It seems other tools are more resilient/forgiving. hmm

    “Reading failed” error in BK7231 Easy UART Flasher interface

    also, any change in detection with the AV experiments? https://github.com/openshwprojects/BK7231GUIFlashTool/pull/88
  • ADVERTISEMENT
  • #129 21779041
    p.kaczmarek2
    Moderator Smart Home
    i was rather expecting network scan tool and Process.Start to cause some alarms, but I haven't found anything meaningful yet. Strange.

    I wonder how would it behave if I were to rewrite, let's say, Beken flashing to C++?
    Helpful post? Buy me a coffee.
  • #131 21779170
    p.kaczmarek2
    Moderator Smart Home
    Haha, really? Nice! How did you come up with it? Even with bisecting approach, it would take me some time.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #132 21779175
    insmod
    Level 31  
    >>21779170
    Well, it started detecting in that commit, and continued even after i removed both z and z2 flashers.
    So, i took a guess and removed all combobox.add except for one. And it worked.
    How/why would it trigger av, i don't know.
  • #134 21781506
    p.kaczmarek2
    Moderator Smart Home
    Which changes did you make to improve extraction, any downsides?


    Any ideas for fixes for remaining AV detections?
    Helpful post? Buy me a coffee.
  • #135 21781521
    divadiow
    Level 38  
    p.kaczmarek2 wrote:
    Which changes did you make to improve extraction, any downsides?

    it's basically replacing

    Code: JSON
    Log in, to see the code


    with this

    Code: JSON
    Log in, to see the code


    tldr:
    Code: Text
    Log in, to see the code


    (t34 tweaks was a previous branch. got gpt to update after insmod sorted T34 module name because there were merge conflicts)

    downsides are that you get random junk at the end of extraction sometimes. I'm sure it could be nicer, but it's been v useful to know you get closer to getting all the infoz, including wifi credentials if stored, so there's that to consider filtering out. Users might blindly paste those about without noticing.
  • #136 21781899
    divadiow
    Level 38  
    divadiow wrote:
    I used it a fair bit a few weeks ago and it was good. A couple of issues were ironed out and I would say yes

    good to merge decryption experiments PR?
  • #139 21790069
    p.kaczmarek2
    Moderator Smart Home
    Well I guess it's acceptable.

    What about this - how did it gave two more AV detections? Maybe compression is suspicious?
    https://github.com/openshwprojects/BK7231GUIFlashTool/pull/94
    Helpful post? Buy me a coffee.
  • #141 21790087
    p.kaczmarek2
    Moderator Smart Home
    This is a legacy fix for HTTPS, maybe it got fixed along with NET SDK update, but it was required with older SDK. Without it, we wouldn't be able to download GitHub releases page and files.
    Helpful post? Buy me a coffee.
  • #142 21790110
    insmod
    Level 31  
    Updated, removed those lines, + changed setting up UseUnsafeHeaderParsing.
    Binaries are now stored as embedded resources (they're still gzip compressed).
    Only 2 detections: https://www.virustotal.com/gui/file/4cc4696dd...0b7c16715f5754e3dcc719f46a3fb53f1d783ab963f61
    (and they are the same as in first release)

    Added 3000000 baud, while it doesn't work for beken, it works for RTLs (i tested D and Z2).
    They can handle higher, but CH340 can't.
    (Or remove it, since it can be manually entered?)
  • #143 21790186
    p.kaczmarek2
    Moderator Smart Home
    I think those are good changes. We probably just need to verify if everything is still stable? Or did you do full tests?

    I am a bit careful with this flasher, but I still remember how I broke (which platform was that, RTL? BL602?), by adding addLog (calling slow Invoke) between UART calls - the addLog call was so slow, that the delay somehow made UART lose data.
    Helpful post? Buy me a coffee.
  • #144 21790195
    insmod
    Level 31  
    >>21790186
    I only tested RTLs and W800.
    They work fine.

    It was LN if i remember it correctly. But that was before custom ramcode.
  • Helpful post
    #145 21794374
    insmod
    Level 31  
    Updated BL and LN882H
    BL chip detection by bootrom version. BL602 - 1, BL702 - 0x7020001, BL616 - 0x6160001. Not known for BL704/706/618.
    Added BL702 and BL616 read. For some reason BL702 write is not working. Didn't bother to fix it. BL616 will read if BL602 or BL702 is selected and BL616 rom version is detected.
    Rewritten LN882H ramcode flash read to use xmodem-1k (for robustness).
    Added CRC check for LN882H.
  • Helpful post
    #146 21794410
    divadiow
    Level 38  
    sweet. LN read/OBK write first try without any issue

    BK7231 Easy UART Flasher screen showing completed memory read and hex data.Screenshot of BK7231 Easy UART Flasher showing successful firmware flashing

    BL602 seems OK too
    Screenshot of BK7231 Easy UART Flasher with successful BL602 flash read completed Firmware flashing process for OpenBL602 completed with Writing done message

    though I do get command time out half the time when writing
    Screenshot of BK7231 Easy UART Flasher with “Interrupted by user” message

    just noticed this. I wonder what that is
    Screenshot of debug log during BL602 chip flashing with error message highlighted

    Added after 53 [seconds]:


    Screenshot of BK7231 Easy UART Flasher showing errors during firmware flashing on BL602

    Added after 32 [minutes]:

    can be seen if successful write too though
    Screenshot of BK7231 Easy UART Flasher after successful firmware flashing
  • #147 21794420
    insmod
    Level 31  
    PD is for pending, OK is for when erase is done. But serial.Read(buf, 0, 2) somehow returns when only 1 byte is available and doesn't wait for second byte (it will be zero).
    Tried to fix it, please check.
    Plus try 2000000 baud on LN

    For BL702 it always times out on write for me
    BootROM version: 117571585 (7020001)
    OTP flags:
    00000000 00000000 00000000 00000000 
    10010011 00011101 00000100 00000000 
    00101101 00000000 00000000 00001000 
    00000000 00000000 00110110 00010001 
    Chip type: BL702
    
    Sending boot header...
    Sending segment header...
    Writing application to RAM...
    Checking...
    Jumping...
    Sync attempt 0/1000 ... OK!
    Flash ID: C2201480
    Flash size is 1MB
    Reading backups\readResult_BL702_test_2025-27-12-08-01-05.bin...
    Erasing from 0x0 to 0x100000
    Erase pending...
    Erase pending...
    Erase pending...
    Erase pending...
    Erase pending...
    Erase pending...
    Erase pending...
    Starting flash write 1048576
    .0x00.Command timed out!
    .0x1000.Command timed out!
    .0x2000.Command timed out!
    .0x3000.Command timed out!
    .0x4000.Command timed out!
    


    Do you have any other BL that is not BL602?

    Added after 24 [minutes]:

    On BL702 it works if i reduce buffer length to less that 915 (?) 914 works, but 916 doesn't. If 915, then one write succeeds (at 0x202B), but the rest fails.
    This is write with 512 buffer. Initial writes times out, but the rest is fine.
    Reading backups\readResult_BL702_test_2025-27-12-08-01-05.bin...
    Erasing from 0x0 to 0x100000
    Erase pending...
    Erase pending...
    Erase pending...
    Erase pending...
    Erase pending...
    Erase pending...
    Erase pending...
    Starting flash write 1048576
    .0x00.Command timed out!
    .0x200.Command timed out!
    .0x400.Command timed out!
    .0x600.Command timed out!
    .0x800.Command timed out!
    .0xA00.Command timed out!
    .0xC00.Command timed out!
    .0xE00.Command timed out!
    .0x1000.Command timed out!
    .0x1200..0x1400..0x1600..0x1800..0x1A00..0x1C00..0x1E00..0x2000..0x2200..0x2400..0x2600..0x2800..0x2A00..0x2C00..0x2E00..0x3000..0x3200..0x3400..0x3600..
    ...
    0xFFA00..0xFFC00..0xFFE00.
    Hash matches F5FB04AA5B882706B9309E885F19477261336EF76A150C3B4D3489DFAC3953EC!
    Done flash write 1048576
    
  • #148 21794442
    divadiow
    Level 38  
    insmod wrote:
    Tried to fix it, please check.

    921600. 6x no, 4x yes in 10 tests. board removed from power between each try. powered with BT button depressed each time before attempts

    BK7231 Easy UART Flasher interface with Interrupted by user message

    insmod wrote:
    Do you have any other BL that is not BL602?


    sadly no. @p.kaczmarek2 has BL702 though

    Added after 6 [minutes]:

    insmod wrote:
    Plus try 2000000 baud on LN

    nice. 10x success writing at 2mbs. speedy

    reading never succeeds

    Screenshot of BK7231 Easy UART Flasher showing Read error during flashing
  • Helpful post
    #149 21794502
    insmod
    Level 31  
    Did some additional fixes for BL, now write always succeeds for me on BL702 with 1024 buffer (and 4096 too).
  • ADVERTISEMENT
  • #150 21794505
    p.kaczmarek2
    Moderator Smart Home
    divadiow wrote:

    sadly no. @p.kaczmarek2 has BL702 though

    I am not sure about BL702 currently, it was a Zigbee module. I may not have it anymore, as I am often helping guys set up things and it made went to one of our users.
    On the other hand, I am confident that I have BL808, the one presented here:
    DIY Webcam/Aparat - M1S Dock - komunikacja pomiędzy dwoma rdzeniami BL808
    Pierwsze starcie z modułem SiPEED M1S DOCK - AI+IoT RTOS_Linux All-Round Module
    Do you think it could work with our flasher? OBK port would also be interesting, but I realize that there is a very little demand for that.

    Anyway, great job guys. I will try to post some kind of OBK summary today in Guides so people can enjoy your great good work. I also have this idea, maybe we can make platform names here links, each will link to forum topic:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/platforms.md

    On a side note, I'm finishing Shutters driver. And then... regarding flasher... I am thinking about looking into Web Serial. And... into something else:
    Spoiler:

    CP2102 USB-to-TTL adapter connected to a USB port of a black device

    I think I may give it a go after new year, but the downside is that supporting those kind of serials would mean rewriting stuff... and then potentially maintaining two codebasese... so I will probably just first go for Beken only.
    Helpful post? Buy me a coffee.
📢 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