app_update: fix inconsistency between bootloader and OTA code

This commit is contained in:
tzx 2016-12-01 10:06:33 +08:00 committed by Wu Jian Gang
parent 59f3684dee
commit 2092d14e45
2 changed files with 26 additions and 22 deletions

View File

@ -184,7 +184,7 @@ static esp_err_t rewrite_ota_seq(uint32_t seq, uint8_t sec_id, const esp_partiti
if (sec_id == 0 || sec_id == 1) { if (sec_id == 0 || sec_id == 1) {
s_ota_select[sec_id].ota_seq = seq; s_ota_select[sec_id].ota_seq = seq;
s_ota_select[sec_id].crc = ota_select_crc(&s_ota_select[sec_id]); s_ota_select[sec_id].crc = ota_select_crc(&s_ota_select[sec_id]);
ret = spi_flash_erase_range(ota_data_partition->address, SPI_FLASH_SEC_SIZE); ret = esp_partition_erase_range(ota_data_partition, sec_id * SPI_FLASH_SEC_SIZE, SPI_FLASH_SEC_SIZE);
if (ret != ESP_OK) { if (ret != ESP_OK) {
return ret; return ret;
} else { } else {
@ -305,7 +305,7 @@ esp_err_t esp_ota_set_boot_partition(const esp_partition_t *partition)
if (partition->subtype == ESP_PARTITION_SUBTYPE_APP_FACTORY) { if (partition->subtype == ESP_PARTITION_SUBTYPE_APP_FACTORY) {
find_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_OTA, NULL); find_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_OTA, NULL);
if (find_partition != NULL) { if (find_partition != NULL) {
return esp_partition_erase_range(find_partition, find_partition->address, find_partition->size); return esp_partition_erase_range(find_partition, 0, find_partition->size);
} else { } else {
return ESP_ERR_NOT_FOUND; return ESP_ERR_NOT_FOUND;
} }

View File

@ -273,6 +273,9 @@ void bootloader_main()
if(sa.ota_seq == 0xFFFFFFFF && sb.ota_seq == 0xFFFFFFFF) { if(sa.ota_seq == 0xFFFFFFFF && sb.ota_seq == 0xFFFFFFFF) {
// init status flash // init status flash
if (bs.factory.offset != 0) { // if have factory bin,boot factory bin
load_part_pos = bs.factory;
} else {
load_part_pos = bs.ota[0]; load_part_pos = bs.ota[0];
sa.ota_seq = 0x01; sa.ota_seq = 0x01;
sa.crc = ota_select_crc(&sa); sa.crc = ota_select_crc(&sa);
@ -293,6 +296,7 @@ void bootloader_main()
return; return;
} }
Cache_Read_Enable(0); Cache_Read_Enable(0);
}
//TODO:write data in ota info //TODO:write data in ota info
} else { } else {
if(ota_select_valid(&sa) && ota_select_valid(&sb)) { if(ota_select_valid(&sa) && ota_select_valid(&sb)) {