update_operation.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #pragma once
  2. #include <stdbool.h>
  3. #include <m-string.h>
  4. #include <storage/storage.h>
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. /*
  9. * Checks if supplied full manifest path is valid
  10. * @param full_path Full path to manifest file. Must be named UPDATE_MANIFEST_DEFAULT_NAME
  11. * @param out_manifest_dir Directory to apply update from, if supplied path is valid.
  12. * May be empty if update is in root update directory
  13. * @return bool if supplied path is valid and out_manifest_dir contains dir to apply
  14. */
  15. bool update_operation_get_package_dir_name(const char* full_path, string_t out_manifest_dir);
  16. typedef enum {
  17. UpdatePrepareResultOK,
  18. UpdatePrepareResultManifestPathInvalid,
  19. UpdatePrepareResultManifestFolderNotFound,
  20. UpdatePrepareResultManifestInvalid,
  21. UpdatePrepareResultStageMissing,
  22. UpdatePrepareResultStageIntegrityError,
  23. } UpdatePrepareResult;
  24. const char* update_operation_describe_preparation_result(const UpdatePrepareResult value);
  25. /*
  26. * Validates next stage and sets up registers to apply update after restart
  27. * @param manifest_dir_path Full path to manifest for update to apply
  28. * @return UpdatePrepareResult validation & arm result
  29. */
  30. UpdatePrepareResult update_operation_prepare(const char* manifest_file_path);
  31. /*
  32. * Gets update package index to pass in RTC registers
  33. * @param storage Storage API
  34. * @param update_package_dir Package directory name
  35. * @return int32_t <0 - error, >= 0 - update index value
  36. */
  37. int32_t update_operation_get_package_index(Storage* storage, const char* update_package_dir);
  38. /*
  39. * Gets filesystem path for current update package
  40. * @param storage Storage API
  41. * @param out_path Path to directory with manifest & related files. Must be initialized
  42. * @return true if path was restored successfully
  43. */
  44. bool update_operation_get_current_package_path(Storage* storage, string_t out_path);
  45. /*
  46. * Stores given update index in RTC registers
  47. * @param index Value to store
  48. */
  49. void update_operation_persist_package_index(uint32_t index);
  50. /*
  51. * Sets up update operation to be performed on reset
  52. */
  53. bool update_operation_is_armed();
  54. /*
  55. * Cancels pending update operation
  56. */
  57. void update_operation_disarm();
  58. #ifdef __cplusplus
  59. }
  60. #endif