1 /*
2  * Copyright (c) 2023 O.S.Systems
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef __UPDATEHUB_STORAGE_H__
8 #define __UPDATEHUB_STORAGE_H__
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #include <zephyr/dfu/flash_img.h>
15 #include <zephyr/storage/flash_map.h>
16 #define UPDATEHUB_SLOT_PARTITION_0 FIXED_PARTITION_ID(slot0_partition)
17 #define UPDATEHUB_SLOT_PARTITION_1 FIXED_PARTITION_ID(slot1_partition)
18 
19 struct updatehub_storage_context {
20 	struct flash_img_context flash_ctx;
21 };
22 
23 int updatehub_storage_is_partition_good(struct updatehub_storage_context *ctx);
24 int updatehub_storage_init(struct updatehub_storage_context *ctx,
25 			   const uint32_t partition_id);
26 int updatehub_storage_write(struct updatehub_storage_context *ctx,
27 			    const uint8_t *data, const size_t size,
28 			    const bool flush);
29 int updatehub_storage_check(struct updatehub_storage_context *ctx,
30 			    const uint32_t partition_id,
31 			    const uint8_t *hash, const size_t size);
32 int updatehub_storage_mark_partition_to_upgrade(struct updatehub_storage_context *ctx,
33 						const uint32_t partition_id);
34 int updatehub_storage_mark_partition_as_confirmed(const uint32_t partition_id);
35 
36 #ifdef __cplusplus
37 }
38 #endif
39 
40 #endif /* __UPDATEHUB_STORAGE_H__ */
41