partition_linux.h 3.7 KB

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