bootloader_flash.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include <esp_err.h>
  9. #include "spi_flash_mmap.h" /* including in bootloader for error values */
  10. #include "esp_private/spi_flash_os.h"
  11. #include "sdkconfig.h"
  12. #include "soc/soc_caps.h"
  13. #include "bootloader_flash_override.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /**
  18. * @brief Read flash ID by sending RDID command (0x9F)
  19. * @return flash raw ID
  20. * mfg_id = (ID >> 16) & 0xFF;
  21. flash_id = ID & 0xffff;
  22. */
  23. uint32_t bootloader_read_flash_id(void);
  24. /**
  25. * @brief Startup flow recommended by XMC. Call at startup before any erase/write operation.
  26. *
  27. * @return ESP_OK When startup successfully, otherwise ESP_FAIL (indiciating you should reboot before erase/write).
  28. */
  29. esp_err_t bootloader_flash_xmc_startup(void);
  30. /**
  31. * @brief Unlock Flash write protect.
  32. * Please do not call this function in SDK.
  33. *
  34. * @note This can be overridden because it's attribute weak.
  35. */
  36. esp_err_t __attribute__((weak)) bootloader_flash_unlock(void);
  37. /**
  38. * @brief Reset the flash chip (66H + 99H).
  39. *
  40. * @return ESP_OK if success, otherwise ESP_FAIL.
  41. */
  42. esp_err_t bootloader_flash_reset_chip(void);
  43. /**
  44. * @brief Check if octal flash mode is enabled in eFuse
  45. *
  46. * @return True if flash is in octal mode, false else
  47. */
  48. bool bootloader_flash_is_octal_mode_enabled(void);
  49. /**
  50. * @brief Get the spi flash working mode.
  51. *
  52. * @return The mode of flash working mode, see `esp_rom_spiflash_read_mode_t`
  53. */
  54. esp_rom_spiflash_read_mode_t bootloader_flash_get_spi_mode(void);
  55. #ifdef __cplusplus
  56. }
  57. #endif