為了查這個(gè)問題我把加解密算法過了一遍,真的是,哎
報(bào)錯(cuò):
E (47079) esp_encrypted_img: failed
! mbedtls_pk_decrypt returned -0x4100
直接說結(jié)果,實(shí)際原因是ESP32得BLE-OTA組件預(yù)加密OTA時(shí)候,給緩存區(qū)寫入得數(shù)據(jù)量少了,導(dǎo)致最終報(bào)加密錯(cuò)誤。
錯(cuò)誤代碼及位置如下:
if (SLIST_NEXT(om, om_next) != NULL) {
struct os_mbuf *temp2 = SLIST_NEXT(om, om_next);
pargs.data_in_len += temp2->om_len;
}

image.png
將以上代碼塊改為如下內(nèi)容即可:
struct os_mbuf *last;
last = om;
while (SLIST_NEXT(last, om_next) != NULL) {
struct os_mbuf *temp2 = SLIST_NEXT(last, om_next);
pargs.data_in_len += temp2->om_len;
last = SLIST_NEXT(last, om_next);
temp2 = NULL;
}