uf2.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * @file uf2.h
  3. * @brief UF2 file support functions.
  4. *
  5. * This is a minimal UF2 file implementation.
  6. *
  7. * UNsupported features:
  8. * - Non-flash blocks
  9. * - File containers
  10. * - Extended tags
  11. * - Md5 checksum
  12. *
  13. * Suported features:
  14. * - Family id (respective flag must be set)
  15. *
  16. * See https://github.com/Microsoft/uf2 for more information.
  17. */
  18. #pragma once
  19. #include <storage/storage.h>
  20. /**
  21. * @brief Get the block count in a UF2 file.
  22. *
  23. * The file MUST be already open.
  24. *
  25. * Will fail if the file size is not evenly divisible
  26. * by 512 bytes (UF2 block size).
  27. *
  28. * @param[in] file pointer to the storage file instance.
  29. * @param[out] block_count pointer to the value to contain the block count.
  30. * @returns true on success, false otherwise.
  31. */
  32. bool uf2_get_block_count(File* file, uint32_t* block_count);
  33. /**
  34. * @brief Verify a single UF2 block.
  35. *
  36. * The file MUST be already open.
  37. *
  38. * Will fail if:
  39. * - the family id flag is set, but does not match the provided value,
  40. * - payload size does not match the provided value.
  41. *
  42. * @param[in] file pointer to the storage file instance.
  43. * @param[in] family_id family identifier to check against the respective header field.
  44. * @param[in] payload_size payload size to check agains the respective header field, in bytes.
  45. * @returns true on success, false otherwise.
  46. */
  47. bool uf2_verify_block(File* file, uint32_t family_id, size_t payload_size);
  48. /**
  49. * @brief Read the payload from a single UF2 block.
  50. *
  51. * @param[in] file pointer to the storage file instance.
  52. * @param[out] payload pointer to the buffer to contain the payload data.
  53. * @param[in] payload_size size of the payload buffer, in bytes.
  54. * @returns true on success, false otherwise.
  55. */
  56. bool uf2_read_block(File* file, void* payload, size_t payload_size);