partition_linux.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * SPDX-FileCopyrightText: 2021-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. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. /**
  13. * @file partition_linux.h
  14. *
  15. * @brief Private API functions used for Linux-target emulation of the Partition APIs (host-side testing)
  16. */
  17. /**
  18. * @brief Partition type to string conversion routine
  19. *
  20. * @param type Partition type, see esp_partition_type_t
  21. *
  22. * @return string equivalent of given partition type or "unknown" on mismatch
  23. */
  24. const char* esp_partition_type_to_str(const uint32_t type);
  25. /**
  26. * @brief Partition subtype to string conversion routine
  27. *
  28. * @param type Partition type, see esp_partition_type_t
  29. * @param subtype Partition subtype, see esp_partition_subtype_t
  30. *
  31. * @return string equivalent of given partition subtype or "unknown" on mismatch
  32. */
  33. const char *esp_partition_subtype_to_str(const uint32_t type, const uint32_t subtype);
  34. /**
  35. * @brief Creates memory emulation of SPI FLASH device (Linux host)
  36. *
  37. * The function creates a memory buffer to emulate SPI FLASH device and provides a pointer to its beginning, in order
  38. * to allow relevant Partition APIs run in host-emulated environment without any code change.
  39. *
  40. * The emulation buffer is actually a disk file mapped to the host memory, current version implements the following:
  41. * 1. create temporary file /tmp/idf-partition-XXXXXX (fixed size 4MB)
  42. * 2. mmap() whole file to the memory and set its contents to all 1s (SPI NOR flash default)
  43. * 3. upload build/partition_table/partition-table.bin (hard-wired path for now) to ESP_PARTITION_TABLE_OFFSET
  44. * (from the beginning of the memory buffer, ie to the same offset as in real SPI FLASH)
  45. * 4. [optional: iterate through the partitions uploaded and print esp_partition_info_t details for each]
  46. * 5. set part_desc_addr_start[out] parameter to the memory buffer starting address
  47. *
  48. * The pointer returned in part_desc_addr_start is then used as it was regular SPI FLASH address.
  49. *
  50. * NOTES:
  51. * 1. the temporary file generated is not deleted automatically - the cleanup happens during the next host system reset
  52. * 2. the mmapped() section remains active until esp_partition_file_unmmap() is called
  53. * 3. mmap() is called with MAP_SHARED so the emulated SPI FLASH can be shared among processes
  54. *
  55. * @param[out] part_desc_addr_start output pointer to receive memory SPI FLASH buffer address
  56. *
  57. * @return
  58. * - ESP_OK: Operation successful
  59. * - ESP_ERR_NOT_FINISHED: Failed to generate temporary file
  60. * - ESP_ERR_INVALID_SIZE (one of the following):
  61. * - Failed to resize temporary file to required value
  62. * - Failed to set filepointer in partition-table.bin
  63. * - ESP_ERR_NO_MEM: Failed to mmap() the temporary file into the memory
  64. * - ESP_ERR_NOT_FOUND: Couldn't open the partition_table.bin file
  65. * - ESP_ERR_INVALID_STATE: Failed to upload partition_table into the memory
  66. */
  67. esp_err_t esp_partition_file_mmap(const uint8_t **part_desc_addr_start);
  68. /**
  69. * @brief Releases the memory of emulated SPI FLASH device (Linux host)
  70. *
  71. * The function releases the memory block previously allocated by esp_partition_file_mmap().
  72. * The buffer is freed by calling munmap() with emulated_buffer, buffer_size
  73. *
  74. * @return
  75. * - ESP_OK: Operation successful
  76. * - ESP_ERR_NO_MEM: The memory buffer was not allocated
  77. * - ESP_ERR_INVALID_SIZE: The buffer size was 0
  78. * - ESP_ERR_INVALID_RESPONSE: Failed to munmap() the emulation file from memory
  79. */
  80. esp_err_t esp_partition_file_munmap(void);
  81. #ifdef __cplusplus
  82. }
  83. #endif