logo elektroda
logo elektroda
X
logo elektroda

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

p.kaczmarek2 8637 268
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.
  • ADVERTISEMENT
  • #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
  • #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.
  • #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.
  • ADVERTISEMENT
  • #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.
  • ADVERTISEMENT
  • #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).
  • #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.
Summary generated by the language model.
ADVERTISEMENT