Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear flash CMP bit, add new SR size #24

Merged
merged 1 commit into from
Nov 1, 2024
Merged

Conversation

mokap13
Copy link
Contributor

@mokap13 mokap13 commented Nov 1, 2024

Problem: MCU bk7238, firmware changed bit CMP to 1 and i can't program memory from bk7231tools.

I added new SR size(for my flash) and CMP zero init, it's work for me now.

@kuba2k2
Copy link
Member

kuba2k2 commented Nov 1, 2024

Thanks for the fix. Could you explain in which scenarios does it not work before applying this fix?

I'm trying to understand if this PR will fix an unprotection issue we've been seeing for a long time, where writing wouldn't work if the device was in a boot loop.

@mokap13
Copy link
Contributor Author

mokap13 commented Nov 1, 2024

bk7231tools can't erase memory if CMP bit was previously set to 1.

bk7231tools write_flash ~/firmware -B -d /dev/tty.usbserial-B003BKOO -b 2000000
Unknown bootloader CRC - 0x6BEB0924 - please report this on GitHub issues!
Reading 4k page at 0x011000 (0.00%)
BK72xx connected - protocol: FULL, chip: BK7238, bootloader: None, chip ID: 0x7238, boot version: None
Connected! Chip info: BK7238 / Flash ID: 85 20 15 / Flash size: 0x200000 / Protocol: FULL
Writing 1314315 bytes to 0x0
Trying to unprotect flash memory...
Erasing and writing at 0x0 (0.00%)
 - Checking block pre-erase @ 0x0
 - Trying to erase block @ 0x0
 - Checking block post-erase @ 0x0
Erasing failure @ 0x0 (Erase failed - flash protected; found non-0xFF bytes @ 0x0), retrying (attempt 0)
 - Checking block pre-erase @ 0x0
 - Trying to erase block @ 0x0
 - Checking block post-erase @ 0x0
Erasing failure @ 0x0 (Erase failed - flash protected; found non-0xFF bytes @ 0x0), retrying (attempt 1)
 - Checking block pre-erase @ 0x0
 - Trying to erase block @ 0x0
 - Checking block post-erase @ 0x0
Erasing failure @ 0x0 (Erase failed - flash protected; found non-0xFF bytes @ 0x0), retrying (attempt 2)
 - Checking block pre-erase @ 0x0
 - Trying to erase block @ 0x0
 - Checking block post-erase @ 0x0
Erasing failure @ 0x0 (Erase failed - flash protected; found non-0xFF bytes @ 0x0), retrying (attempt 3)
Traceback (most recent call last):
  File "/Users/user/projects/py-scripts/.venv/bin/bk7231tools", line 8, in <module>
    sys.exit(cli())
             ~~~^^
  File "/Users/user/projects/py-scripts/.venv/lib/python3.13/site-packages/bk7231tools/__main__.py", line 626, in cli
    args.handler(device, args)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/Users/user/projects/py-scripts/.venv/lib/python3.13/site-packages/bk7231tools/__main__.py", line 470, in write_flash
    for _ in device.program_flash(
             ~~~~~~~~~~~~~~~~~~~~^
        io=fs,
        ^^^^^^
    ...<3 lines>...
        dry_run=False,
        ^^^^^^^^^^^^^^
    ):
    ^
  File "/Users/user/projects/py-scripts/.venv/lib/python3.13/site-packages/bk7231tools/serial/cmd_hl_flash.py", line 187, in program_flash
    self.flash_erase_block(
    ~~~~~~~~~~~~~~~~~~~~~~^
        addr,
        ^^^^^
        EraseSize.SECTOR_4K,
        ^^^^^^^^^^^^^^^^^^^^
        dry_run=dry_run,
        ^^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/user/projects/py-scripts/.venv/lib/python3.13/site-packages/bk7231tools/serial/cmd_ll_flash.py", line 229, in flash_erase_block
    do_erase_verify()
    ~~~~~~~~~~~~~~~^^
  File "/Users/user/projects/py-scripts/.venv/lib/python3.13/site-packages/bk7231tools/serial/cmd_ll_flash.py", line 209, in do_erase_verify
    raise ValueError(
    ...<2 lines>...
    )
ValueError: Erase failed - flash protected; found non-0xFF bytes @ 0x0

@kuba2k2
Copy link
Member

kuba2k2 commented Nov 1, 2024

Thanks. Could you also attach a stock firmware dump from the device? It could help with further support for this chip.

@kuba2k2 kuba2k2 changed the title add cmp zero init and new flash chip Clear flash CMP bit, add new SR size Nov 1, 2024
@kuba2k2 kuba2k2 merged commit 38ef9c9 into tuya-cloudcutter:main Nov 1, 2024
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.

2 participants