Environment
- Board: T1-3S (BK7238)
- Platform: libretiny 1.12.1
- Framework: framework-beken-bdk 3.0.78
- Flash: 2MB
Problem
On BK7238, enabling BLE causes flash sector 0 (the bootloader) to be
erased on every boot, requiring the bootloader to be re-flashed each time.
Root Cause
cores/beken-72xx/base/wraps/BkDriverFlash.c defines a local partition
table with only 5 entries (indices 0–4).
BK_PARTITION_BLE_BONDING_FLASH has enum value 7 (with CFG_SUPPORT_MATTER=0),
so bk7231_partitions[7] is zero-initialized → partition_start_addr = 0x00000000.
In app_sec_init() (ble_5_2/ble_pub/app/src/app_sec.c line 167), when
BLE bonding CRC validation fails on first boot (nothing written yet):
flash_ctrl(CMD_FLASH_ERASE_SECTOR,
&app_sec_env.flash_bond_ptr->partition_start_addr); // = 0x0 !
This erases the bootloader sector on every boot.
Fix
Add BK_PARTITION_BLE_BONDING_FLASH to the partition table in
cores/beken-72xx/base/wraps/BkDriverFlash.c:
#if (CFG_SOC_NAME == SOC_BK7238)
[BK_PARTITION_BLE_BONDING_FLASH] =
{
.partition_owner = BK_FLASH_EMBEDDED,
.partition_description = "ble bonding info",
.partition_start_addr = 0x1F0000,
.partition_length = 0x1000,
.partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
},
#endif
0x1F0000 is inside the userdata region (0x1EC000–0x200000) defined
in boards/_base/beken-7238-tuya.json, so it does not overlap any other partition.
---
Environment
Problem
On BK7238, enabling BLE causes flash sector 0 (the bootloader) to be
erased on every boot, requiring the bootloader to be re-flashed each time.
Root Cause
cores/beken-72xx/base/wraps/BkDriverFlash.cdefines a local partitiontable with only 5 entries (indices 0–4).
BK_PARTITION_BLE_BONDING_FLASHhas enum value 7 (with CFG_SUPPORT_MATTER=0),so
bk7231_partitions[7]is zero-initialized →partition_start_addr = 0x00000000.In
app_sec_init()(ble_5_2/ble_pub/app/src/app_sec.c line 167), whenBLE bonding CRC validation fails on first boot (nothing written yet):