2021-05-09 22:56:51 -04:00
|
|
|
/*
|
2022-01-17 21:32:56 -05:00
|
|
|
* SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
|
2021-05-09 22:56:51 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2017-01-29 22:29:50 -05:00
|
|
|
|
2018-04-16 11:35:41 -04:00
|
|
|
#pragma once
|
2019-03-14 10:03:04 -04:00
|
|
|
#include "esp_flash_partitions.h"
|
2018-10-05 08:29:07 -04:00
|
|
|
#include "esp_image_format.h"
|
2018-04-23 08:19:04 -04:00
|
|
|
|
2019-06-25 21:02:15 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2022-07-21 07:14:26 -04:00
|
|
|
// Type of hold a GPIO in low state
|
2018-04-23 08:19:04 -04:00
|
|
|
typedef enum {
|
|
|
|
GPIO_LONG_HOLD = 1, /*!< The long hold GPIO */
|
|
|
|
GPIO_SHORT_HOLD = -1, /*!< The short hold GPIO */
|
|
|
|
GPIO_NOT_HOLD = 0 /*!< If the GPIO input is not low */
|
|
|
|
} esp_comm_gpio_hold_t;
|
2017-01-29 22:29:50 -05:00
|
|
|
|
2019-10-11 05:05:22 -04:00
|
|
|
typedef enum {
|
|
|
|
ESP_IMAGE_BOOTLOADER,
|
|
|
|
ESP_IMAGE_APPLICATION
|
|
|
|
} esp_image_type;
|
|
|
|
|
2018-04-16 11:35:41 -04:00
|
|
|
/**
|
2018-10-22 11:11:10 -04:00
|
|
|
* @brief Calculate crc for the OTA data select.
|
2017-01-29 22:29:50 -05:00
|
|
|
*
|
2018-10-22 11:11:10 -04:00
|
|
|
* @param[in] s The OTA data select.
|
2018-04-16 11:35:41 -04:00
|
|
|
* @return Returns crc value.
|
2017-01-29 22:29:50 -05:00
|
|
|
*/
|
2018-04-16 11:35:41 -04:00
|
|
|
uint32_t bootloader_common_ota_select_crc(const esp_ota_select_entry_t *s);
|
2017-01-29 22:29:50 -05:00
|
|
|
|
2018-04-16 11:35:41 -04:00
|
|
|
/**
|
2018-10-22 11:11:10 -04:00
|
|
|
* @brief Verifies the validity of the OTA data select
|
2018-04-16 11:35:41 -04:00
|
|
|
*
|
2018-10-22 11:11:10 -04:00
|
|
|
* @param[in] s The OTA data select.
|
2018-04-16 11:35:41 -04:00
|
|
|
* @return Returns true on valid, false otherwise.
|
|
|
|
*/
|
|
|
|
bool bootloader_common_ota_select_valid(const esp_ota_select_entry_t *s);
|
2018-04-23 08:19:04 -04:00
|
|
|
|
2018-10-22 11:11:10 -04:00
|
|
|
/**
|
|
|
|
* @brief Returns true if OTADATA is not marked as bootable partition.
|
|
|
|
*
|
|
|
|
* @param[in] s The OTA data select.
|
|
|
|
* @return Returns true if OTADATA invalid, false otherwise.
|
|
|
|
*/
|
|
|
|
bool bootloader_common_ota_select_invalid(const esp_ota_select_entry_t *s);
|
|
|
|
|
2018-04-23 08:19:04 -04:00
|
|
|
/**
|
2021-06-14 21:18:33 -04:00
|
|
|
* @brief Check if a GPIO input is held low for a long period, short period, or not
|
|
|
|
* at all.
|
|
|
|
*
|
|
|
|
* This function will configure the specified GPIO as an input with internal pull-up enabled.
|
2018-04-23 08:19:04 -04:00
|
|
|
*
|
|
|
|
* If the GPIO input is held low continuously for delay_sec period then it is a long hold.
|
|
|
|
* If the GPIO input is held low for less period then it is a short hold.
|
|
|
|
*
|
|
|
|
* @param[in] num_pin Number of the GPIO input.
|
|
|
|
* @param[in] delay_sec Input must be driven low for at least this long, continuously.
|
2021-06-14 21:18:33 -04:00
|
|
|
* @return esp_comm_gpio_hold_t Type of low level hold detected, if any.
|
2018-04-23 08:19:04 -04:00
|
|
|
*/
|
2021-06-14 21:18:33 -04:00
|
|
|
esp_comm_gpio_hold_t bootloader_common_check_long_hold_gpio(uint32_t num_pin, uint32_t delay_sec);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Check if a GPIO input is held low or high for a long period, short period, or not
|
|
|
|
* at all.
|
|
|
|
*
|
|
|
|
* This function will configure the specified GPIO as an input with internal pull-up enabled.
|
|
|
|
*
|
|
|
|
* If the GPIO input is held at 'level' continuously for delay_sec period then it is a long hold.
|
|
|
|
* If the GPIO input is held at 'level' for less period then it is a short hold.
|
|
|
|
*
|
|
|
|
* @param[in] num_pin Number of the GPIO input.
|
|
|
|
* @param[in] delay_sec Input must be driven to 'level' for at least this long, continuously.
|
|
|
|
* @param[in] level Input pin level to trigger on hold
|
|
|
|
* @return esp_comm_gpio_hold_t Type of hold detected, if any.
|
|
|
|
*/
|
|
|
|
esp_comm_gpio_hold_t bootloader_common_check_long_hold_gpio_level(uint32_t num_pin, uint32_t delay_sec, bool level);
|
|
|
|
|
2018-04-23 08:19:04 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Erase the partition data that is specified in the transferred list.
|
|
|
|
*
|
|
|
|
* @param[in] list_erase String containing a list of cleared partitions. Like this "nvs, phy". The string must be null-terminal.
|
|
|
|
* @param[in] ota_data_erase If true then the OTA data partition will be cleared (if there is it in partition table).
|
|
|
|
* @return Returns true on success, false otherwise.
|
|
|
|
*/
|
|
|
|
bool bootloader_common_erase_part_type_data(const char *list_erase, bool ota_data_erase);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Determines if the list contains the label
|
|
|
|
*
|
|
|
|
* @param[in] list A string of names delimited by commas or spaces. Like this "nvs, phy, data". The string must be null-terminated.
|
|
|
|
* @param[in] label The substring that will be searched in the list.
|
|
|
|
* @return Returns true if the list contains the label, false otherwise.
|
|
|
|
*/
|
|
|
|
bool bootloader_common_label_search(const char *list, char *label);
|
2018-05-30 05:08:00 -04:00
|
|
|
|
2019-05-27 02:29:43 -04:00
|
|
|
/**
|
|
|
|
* @brief Configure default SPI pin modes and drive strengths
|
|
|
|
*
|
|
|
|
* @param drv GPIO drive level (determined by clock frequency)
|
|
|
|
*/
|
|
|
|
void bootloader_configure_spi_pins(int drv);
|
|
|
|
|
2018-05-30 05:08:00 -04:00
|
|
|
/**
|
|
|
|
* @brief Calculates a sha-256 for a given partition or returns a appended digest.
|
|
|
|
*
|
|
|
|
* This function can be used to return the SHA-256 digest of application, bootloader and data partitions.
|
|
|
|
* For apps with SHA-256 appended to the app image, the result is the appended SHA-256 value for the app image content.
|
|
|
|
* The hash is verified before returning, if app content is invalid then the function returns ESP_ERR_IMAGE_INVALID.
|
|
|
|
* For apps without SHA-256 appended to the image, the result is the SHA-256 of all bytes in the app image.
|
|
|
|
* For other partition types, the result is the SHA-256 of the entire partition.
|
|
|
|
*
|
|
|
|
* @param[in] address Address of partition.
|
|
|
|
* @param[in] size Size of partition.
|
|
|
|
* @param[in] type Type of partition. For applications the type is 0, otherwise type is data.
|
|
|
|
* @param[out] out_sha_256 Returned SHA-256 digest for a given partition.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK: In case of successful operation.
|
|
|
|
* - ESP_ERR_INVALID_ARG: The size was 0 or the sha_256 was NULL.
|
|
|
|
* - ESP_ERR_NO_MEM: Cannot allocate memory for sha256 operation.
|
|
|
|
* - ESP_ERR_IMAGE_INVALID: App partition doesn't contain a valid app image.
|
|
|
|
* - ESP_FAIL: An allocation error occurred.
|
|
|
|
*/
|
|
|
|
esp_err_t bootloader_common_get_sha256_of_partition(uint32_t address, uint32_t size, int type, uint8_t *out_sha_256);
|
2018-10-05 08:29:07 -04:00
|
|
|
|
2018-10-22 11:11:10 -04:00
|
|
|
/**
|
|
|
|
* @brief Returns the number of active otadata.
|
|
|
|
*
|
|
|
|
* @param[in] two_otadata Pointer on array from two otadata structures.
|
|
|
|
*
|
|
|
|
* @return The number of active otadata (0 or 1).
|
|
|
|
* - -1: If it does not have active otadata.
|
|
|
|
*/
|
|
|
|
int bootloader_common_get_active_otadata(esp_ota_select_entry_t *two_otadata);
|
|
|
|
|
2019-02-13 04:32:23 -05:00
|
|
|
/**
|
|
|
|
* @brief Returns the number of active otadata.
|
|
|
|
*
|
|
|
|
* @param[in] two_otadata Pointer on array from two otadata structures.
|
|
|
|
* @param[in] valid_two_otadata Pointer on array from two bools. True means select.
|
|
|
|
* @param[in] max True - will select the maximum ota_seq number, otherwise the minimum.
|
|
|
|
*
|
|
|
|
* @return The number of active otadata (0 or 1).
|
|
|
|
* - -1: If it does not have active otadata.
|
|
|
|
*/
|
|
|
|
int bootloader_common_select_otadata(const esp_ota_select_entry_t *two_otadata, bool *valid_two_otadata, bool max);
|
|
|
|
|
2020-08-05 02:56:01 -04:00
|
|
|
/**
|
|
|
|
* @brief Get chip package
|
|
|
|
*
|
|
|
|
* @return Chip package number
|
|
|
|
*/
|
|
|
|
uint32_t bootloader_common_get_chip_ver_pkg(void);
|
|
|
|
|
2019-09-15 23:47:23 -04:00
|
|
|
/**
|
|
|
|
* @brief Check if the image (bootloader and application) has valid chip ID and revision
|
|
|
|
*
|
2019-10-11 05:05:22 -04:00
|
|
|
* @param[in] img_hdr: image header
|
|
|
|
* @param[in] type: image type, bootloader or application
|
2019-09-15 23:47:23 -04:00
|
|
|
* @return
|
|
|
|
* - ESP_OK: image and chip are matched well
|
|
|
|
* - ESP_FAIL: image doesn't match to the chip
|
|
|
|
*/
|
2019-10-11 05:05:22 -04:00
|
|
|
esp_err_t bootloader_common_check_chip_validity(const esp_image_header_t* img_hdr, esp_image_type type);
|
2019-09-15 23:47:23 -04:00
|
|
|
|
2019-05-07 04:36:37 -04:00
|
|
|
/**
|
|
|
|
* @brief Configure VDDSDIO, call this API to rise VDDSDIO to 1.9V when VDDSDIO regulator is enabled as 1.8V mode.
|
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
void bootloader_common_vddsdio_configure(void);
|
2019-06-25 21:02:15 -04:00
|
|
|
|
2019-07-05 06:18:58 -04:00
|
|
|
#if defined( CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP ) || defined( CONFIG_BOOTLOADER_CUSTOM_RESERVE_RTC )
|
|
|
|
/**
|
|
|
|
* @brief Returns partition from rtc_retain_mem
|
|
|
|
*
|
|
|
|
* Uses to get the partition of application which was worked before to go to the deep sleep.
|
|
|
|
* This partition was stored in rtc_retain_mem.
|
|
|
|
* Note: This function operates the RTC FAST memory which available only for PRO_CPU.
|
|
|
|
* Make sure that this function is used only PRO_CPU.
|
|
|
|
*
|
|
|
|
* @return partition: If rtc_retain_mem is valid.
|
|
|
|
* - NULL: If it is not valid.
|
|
|
|
*/
|
|
|
|
esp_partition_pos_t* bootloader_common_get_rtc_retain_mem_partition(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Update the partition and reboot_counter in rtc_retain_mem.
|
|
|
|
*
|
|
|
|
* This function saves the partition of application for fast booting from the deep sleep.
|
|
|
|
* An algorithm uses this partition to avoid reading the otadata and does not validate an image.
|
|
|
|
* Note: This function operates the RTC FAST memory which available only for PRO_CPU.
|
|
|
|
* Make sure that this function is used only PRO_CPU.
|
|
|
|
*
|
|
|
|
* @param[in] partition App partition description. Can be NULL, in this case rtc_retain_mem.partition is not updated.
|
|
|
|
* @param[in] reboot_counter If true then update reboot_counter.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void bootloader_common_update_rtc_retain_mem(esp_partition_pos_t* partition, bool reboot_counter);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Reset entire rtc_retain_mem.
|
|
|
|
*
|
|
|
|
* Note: This function operates the RTC FAST memory which available only for PRO_CPU.
|
|
|
|
* Make sure that this function is used only PRO_CPU.
|
|
|
|
*/
|
|
|
|
void bootloader_common_reset_rtc_retain_mem(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns reboot_counter from rtc_retain_mem
|
|
|
|
*
|
|
|
|
* The reboot_counter counts the number of reboots. Reset only when power is off.
|
|
|
|
* The very first launch of the application will be from 1.
|
|
|
|
* Overflow is not possible, it will stop at the value UINT16_MAX.
|
|
|
|
* Note: This function operates the RTC FAST memory which available only for PRO_CPU.
|
|
|
|
* Make sure that this function is used only PRO_CPU.
|
|
|
|
*
|
|
|
|
* @return reboot_counter: 1..65535
|
|
|
|
* - 0: If rtc_retain_mem is not valid.
|
|
|
|
*/
|
|
|
|
uint16_t bootloader_common_get_rtc_retain_mem_reboot_counter(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns rtc_retain_mem
|
|
|
|
*
|
|
|
|
* Note: This function operates the RTC FAST memory which available only for PRO_CPU.
|
|
|
|
* Make sure that this function is used only PRO_CPU.
|
|
|
|
*
|
|
|
|
* @return rtc_retain_mem
|
|
|
|
*/
|
|
|
|
rtc_retain_mem_t* bootloader_common_get_rtc_retain_mem(void);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2019-06-25 21:02:15 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|