bootloader_flash.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef __BOOTLOADER_FLASH_H
  14. #define __BOOTLOADER_FLASH_H
  15. #include <stddef.h>
  16. #include <stdbool.h>
  17. #include <stdint.h>
  18. #include <esp_err.h>
  19. /* Provide a Flash API for bootloader_support code,
  20. that can be used from bootloader or app code.
  21. This header is available to source code in the bootloader &
  22. bootloader_support components only.
  23. */
  24. /**
  25. * @brief Map a region of flash to data memory
  26. *
  27. * @important In bootloader code, only one region can be bootloader_mmaped at once. The previous region must be bootloader_munmapped before another region is mapped.
  28. *
  29. * @important In app code, these functions are not thread safe.
  30. *
  31. * Call bootloader_munmap once for each successful call to bootloader_mmap.
  32. *
  33. * In esp-idf app, this function maps directly to spi_flash_mmap.
  34. *
  35. * @param offset - Starting flash offset to map to memory.
  36. * @param length - Length of data to map.
  37. *
  38. * @return Pointer to mapped data memory (at src_addr), or NULL
  39. * if an allocation error occured.
  40. */
  41. const void *bootloader_mmap(uint32_t src_addr, uint32_t size);
  42. /**
  43. * @brief Unmap a previously mapped region of flash
  44. *
  45. * Call bootloader_munmap once for each successful call to bootloader_mmap.
  46. */
  47. void bootloader_munmap(const void *mapping);
  48. /**
  49. * @brief Read data from Flash.
  50. *
  51. * @note Both src and dest have to be 4-byte aligned.
  52. *
  53. * @param src source address of the data in Flash.
  54. * @param dest pointer to the destination buffer
  55. * @param size length of data
  56. *
  57. * @return esp_err_t
  58. */
  59. esp_err_t bootloader_flash_read(size_t src_addr, void *dest, size_t size);
  60. #endif