update_operation.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #define UPDATE_OPERATION_MAX_MANIFEST_PATH_LEN 255u
  10. #define UPDATE_OPERATION_MIN_MANIFEST_VERSION 2
  11. /*
  12. * Checks if supplied full manifest path is valid
  13. * @param full_path Full path to manifest file. Must be named UPDATE_MANIFEST_DEFAULT_NAME
  14. * @param out_manifest_dir Directory to apply update from, if supplied path is valid.
  15. * May be empty if update is in root update directory
  16. * @return bool if supplied path is valid and out_manifest_dir contains dir to apply
  17. */
  18. bool update_operation_get_package_dir_name(const char* full_path, string_t out_manifest_dir);
  19. /* When updating this enum, also update assets/protobuf/system.proto */
  20. typedef enum {
  21. UpdatePrepareResultOK,
  22. UpdatePrepareResultManifestPathInvalid,
  23. UpdatePrepareResultManifestFolderNotFound,
  24. UpdatePrepareResultManifestInvalid,
  25. UpdatePrepareResultStageMissing,
  26. UpdatePrepareResultStageIntegrityError,
  27. UpdatePrepareResultManifestPointerError,
  28. UpdatePrepareResultTargetMismatch,
  29. UpdatePrepareResultOutdatedManifestVersion,
  30. } UpdatePrepareResult;
  31. const char* update_operation_describe_preparation_result(const UpdatePrepareResult value);
  32. /*
  33. * Validates next stage and sets up registers to apply update after restart
  34. * @param manifest_dir_path Full path to manifest for update to apply
  35. * @return UpdatePrepareResult validation & arm result
  36. */
  37. UpdatePrepareResult update_operation_prepare(const char* manifest_file_path);
  38. /*
  39. * Gets filesystem path for current update package
  40. * @param storage Storage API
  41. * @param out_path Path to manifest. Must be initialized
  42. * @return true if path was restored successfully
  43. */
  44. bool update_operation_get_current_package_manifest_path(Storage* storage, string_t out_path);
  45. /*
  46. * Checks if an update operation step is pending after reset
  47. */
  48. bool update_operation_is_armed();
  49. /*
  50. * Cancels pending update operation
  51. */
  52. void update_operation_disarm();
  53. #ifdef __cplusplus
  54. }
  55. #endif