bootloader_support: Adds API to detect Factory reset has happened
Closes https://github.com/espressif/esp-idf/issues/10753
This commit is contained in:
@@ -173,7 +173,7 @@ esp_err_t bootloader_common_check_chip_validity(const esp_image_header_t* img_hd
|
||||
*/
|
||||
void bootloader_common_vddsdio_configure(void);
|
||||
|
||||
#if defined( CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP ) || defined( CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC )
|
||||
#if CONFIG_BOOTLOADER_RESERVE_RTC_MEM
|
||||
/**
|
||||
* @brief Returns partition from rtc_retain_mem
|
||||
*
|
||||
@@ -223,6 +223,21 @@ void bootloader_common_reset_rtc_retain_mem(void);
|
||||
*/
|
||||
uint16_t bootloader_common_get_rtc_retain_mem_reboot_counter(void);
|
||||
|
||||
/**
|
||||
* @brief Returns True if Factory reset has happened
|
||||
*
|
||||
* Reset the status after reading it.
|
||||
*
|
||||
* @return True: Factory reset has happened
|
||||
* False: No Factory reset
|
||||
*/
|
||||
bool bootloader_common_get_rtc_retain_mem_factory_reset_state(void);
|
||||
|
||||
/**
|
||||
* @brief Sets Factory reset status
|
||||
*/
|
||||
void bootloader_common_set_rtc_retain_mem_factory_reset_state(void);
|
||||
|
||||
/**
|
||||
* @brief Returns rtc_retain_mem
|
||||
*
|
||||
@@ -233,7 +248,7 @@ uint16_t bootloader_common_get_rtc_retain_mem_reboot_counter(void);
|
||||
*/
|
||||
rtc_retain_mem_t* bootloader_common_get_rtc_retain_mem(void);
|
||||
|
||||
#endif
|
||||
#endif // CONFIG_BOOTLOADER_RESERVE_RTC_MEM
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -47,7 +47,14 @@ typedef enum {
|
||||
typedef struct {
|
||||
esp_partition_pos_t partition; /*!< Partition of application which worked before goes to the deep sleep. */
|
||||
uint16_t reboot_counter; /*!< Reboot counter. Reset only when power is off. */
|
||||
uint16_t reserve; /*!< Reserve */
|
||||
union {
|
||||
struct {
|
||||
uint8_t factory_reset_state : 1; /* True when Factory reset has occurred */
|
||||
uint8_t reserve : 7; /* Reserve */
|
||||
};
|
||||
uint8_t val;
|
||||
} flags;
|
||||
uint8_t reserve; /*!< Reserve */
|
||||
#ifdef CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC
|
||||
uint8_t custom[CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE]; /*!< Reserve for custom propose */
|
||||
#endif
|
||||
@@ -57,6 +64,8 @@ typedef struct {
|
||||
|
||||
ESP_STATIC_ASSERT(offsetof(rtc_retain_mem_t, crc) == sizeof(rtc_retain_mem_t) - sizeof(uint32_t), "CRC field must be the last field of rtc_retain_mem_t structure");
|
||||
|
||||
#ifdef CONFIG_BOOTLOADER_RESERVE_RTC_MEM
|
||||
|
||||
#ifdef CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC
|
||||
ESP_STATIC_ASSERT(CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE % 4 == 0, "CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE must be a multiple of 4 bytes");
|
||||
/* The custom field must be the penultimate field */
|
||||
@@ -64,19 +73,16 @@ ESP_STATIC_ASSERT(offsetof(rtc_retain_mem_t, custom) == sizeof(rtc_retain_mem_t)
|
||||
"custom field in rtc_retain_mem_t structure must be the field before the CRC one");
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP) || defined(CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC)
|
||||
ESP_STATIC_ASSERT(CONFIG_BOOTLOADER_RESERVE_RTC_SIZE % 4 == 0, "CONFIG_BOOTLOADER_RESERVE_RTC_SIZE must be a multiple of 4 bytes");
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC
|
||||
#define ESP_BOOTLOADER_RESERVE_RTC (CONFIG_BOOTLOADER_RESERVE_RTC_SIZE + CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC_SIZE)
|
||||
#elif defined(CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP)
|
||||
#else
|
||||
#define ESP_BOOTLOADER_RESERVE_RTC (CONFIG_BOOTLOADER_RESERVE_RTC_SIZE)
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP) || defined(CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC)
|
||||
ESP_STATIC_ASSERT(sizeof(rtc_retain_mem_t) <= ESP_BOOTLOADER_RESERVE_RTC, "Reserved RTC area must exceed size of rtc_retain_mem_t");
|
||||
#endif
|
||||
#endif // CONFIG_BOOTLOADER_RESERVE_RTC_MEM
|
||||
|
||||
/**
|
||||
* @brief Verify an app image.
|
||||
|
||||
Reference in New Issue
Block a user