更新 OTA 位置,移除测试文件
This commit is contained in:
@@ -12,6 +12,7 @@ list(APPEND incs "lib-out")
|
||||
|
||||
list(APPEND srcs "app_main.c")
|
||||
list(APPEND srcs "app_info.c")
|
||||
list(APPEND srcs "ota.c")
|
||||
list(APPEND srcs "console.c")
|
||||
list(APPEND srcs "drivers/data_port/sb_data_port.c")
|
||||
list(APPEND srcs "drivers/data_port/uart/uart_port.c")
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <string.h>
|
||||
|
||||
/* 配置 */
|
||||
#include "ota.h"
|
||||
#include "config/board_config.h"
|
||||
#include "config/app_config.h"
|
||||
|
||||
@@ -50,6 +51,9 @@ void work_app_main(void *arg)
|
||||
board_cfg_init(); // 板级配置
|
||||
app_cfg_init(); // 应用配置
|
||||
|
||||
/* 初始化 OTA 功能*/
|
||||
ota_partition_check();
|
||||
|
||||
/* 初始化其他优先级的工作队列 */
|
||||
_init_work_q();
|
||||
|
||||
@@ -87,9 +91,9 @@ static void _init_work_q(void)
|
||||
static void _init_ws2812(void)
|
||||
{
|
||||
#if (CONFIG_LED_STRIP_MAX_LEDS)
|
||||
ws2812_spi_led_strip_init(SPI2_HOST, CONFIG_LED_STRIP_MAX_LEDS);
|
||||
ws2812_spi_led_strip_init(g_cfg_board->led_spi.spi_id, CONFIG_LED_STRIP_MAX_LEDS);
|
||||
#else
|
||||
ws2812_spi_led_strip_init(SPI2_HOST, 10);
|
||||
ws2812_spi_led_strip_init(g_cfg_board->led_spi.spi_id, 10);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
75
app/ota.c
Normal file
75
app/ota.c
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "ota.h"
|
||||
|
||||
#include "esp_partition.h"
|
||||
#include "esp_ota_ops.h"
|
||||
#include "esp_flash_partitions.h"
|
||||
|
||||
#define CONFIG_SYS_LOG_LEVEL SYS_LOG_LEVEL_WRN
|
||||
#define SYS_LOG_DOMAIN "OTA"
|
||||
#define CONS_ABORT()
|
||||
#include "sys_log.h"
|
||||
|
||||
#define HASH_LEN 32 /* SHA-256 digest length */
|
||||
static void _print_sha256(const uint8_t *image_hash, const char *label)
|
||||
{
|
||||
char hash_print[HASH_LEN * 2 + 1];
|
||||
hash_print[HASH_LEN * 2] = 0;
|
||||
for (int i = 0; i < HASH_LEN; ++i)
|
||||
{
|
||||
sprintf(&hash_print[i * 2], "%02x", image_hash[i]);
|
||||
}
|
||||
SYS_LOG_INF("%s %s", label, hash_print);
|
||||
}
|
||||
|
||||
void ota_partition_check()
|
||||
{
|
||||
uint8_t sha_256[HASH_LEN] = {0};
|
||||
esp_partition_t partition;
|
||||
|
||||
// get sha256 digest for the partition table
|
||||
partition.address = ESP_PARTITION_TABLE_OFFSET;
|
||||
partition.size = ESP_PARTITION_TABLE_MAX_LEN;
|
||||
partition.type = ESP_PARTITION_TYPE_DATA;
|
||||
esp_partition_get_sha256(&partition, sha_256);
|
||||
_print_sha256(sha_256, "SHA-256 for the partition table:");
|
||||
|
||||
// get sha256 digest for bootloader
|
||||
partition.address = ESP_BOOTLOADER_OFFSET;
|
||||
partition.size = ESP_PARTITION_TABLE_OFFSET;
|
||||
partition.type = ESP_PARTITION_TYPE_APP;
|
||||
esp_partition_get_sha256(&partition, sha_256);
|
||||
_print_sha256(sha_256, "SHA-256 for bootloader: ");
|
||||
|
||||
// get sha256 digest for running partition
|
||||
esp_partition_get_sha256(esp_ota_get_running_partition(), sha_256);
|
||||
_print_sha256(sha_256, "SHA-256 for current firmware: ");
|
||||
|
||||
const esp_partition_t *running = esp_ota_get_running_partition();
|
||||
esp_ota_img_states_t ota_state;
|
||||
if (esp_ota_get_state_partition(running, &ota_state) == ESP_OK)
|
||||
{
|
||||
if (ota_state == ESP_OTA_IMG_PENDING_VERIFY)
|
||||
{
|
||||
// run diagnostic function ...
|
||||
bool diagnostic_is_ok = true; // diagnostic();
|
||||
if (diagnostic_is_ok)
|
||||
{
|
||||
SYS_LOG_INF("Diagnostics completed successfully! Continuing execution ...");
|
||||
esp_ota_mark_app_valid_cancel_rollback();
|
||||
}
|
||||
else
|
||||
{
|
||||
SYS_LOG_ERR("Diagnostics failed! Start rollback to the previous version ...");
|
||||
esp_ota_mark_app_invalid_rollback_and_reboot();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SYS_LOG_INF("");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SYS_LOG_INF("");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user