update_operation.h 2.2 KB

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