vrahane commented on a change in pull request #27: Update mynewt port of mcumgr
and various fixes
URL: https://github.com/apache/mynewt-mcumgr/pull/27#discussion_r330781746
##########
File path: cmd/img_mgmt/include/img_mgmt/img_mgmt.h
##########
@@ -44,11 +70,209 @@ extern "C" {
#define IMG_MGMT_ID_UPLOAD_STATUS_ONGOING 1
#define IMG_MGMT_ID_UPLOAD_STATUS_COMPLETE 2
+extern int boot_current_slot;
+extern struct img_mgmt_state g_img_mgmt_state;
+
+/** Represents an individual upload request. */
+struct img_mgmt_upload_req {
+ unsigned long long int off; /* -1 if unspecified */
+ unsigned long long int size; /* -1 if unspecified */
+ size_t data_len;
+ size_t data_sha_len;
+ uint8_t img_data[IMG_MGMT_UL_CHUNK_SIZE];
+ uint8_t data_sha[IMG_MGMT_DATA_SHA_LEN];
+ bool upgrade; /* Only allow greater version numbers. */
+};
+
+/** Global state for upload in progress. */
+struct img_mgmt_state {
+ /** Flash area being written; -1 if no upload in progress. */
+ int area_id;
+ /** Flash offset of next chunk. */
+ uint32_t off;
+ /** Total size of image data. */
+ uint32_t size;
+ /** Hash of image data; used for resumption of a partial upload. */
+ uint8_t data_sha_len;
+ uint8_t data_sha[IMG_MGMT_DATA_SHA_LEN];
+#if IMG_MGMT_LAZY_ERASE
+ int sector_id;
+ uint32_t sector_end;
+#endif
+};
+
+/** Describes what to do during processing of an upload request. */
+struct img_mgmt_upload_action {
+ /** The total size of the image. */
+ unsigned long long size;
+ /** The number of image bytes to write to flash. */
+ int write_bytes;
+ /** The flash area to write to. */
+ int area_id;
+ /** Whether to process the request; false if offset is wrong. */
+ bool proceed;
+ /** Whether to erase the destination flash area. */
+ bool erase;
+};
+
/**
* @brief Registers the image management command handler group.
*/
void img_mgmt_register_group(void);
+/**
+ * @brief Read info of an image give the slot number
+ *
+ * @param image_slot Image slot to read info from
+ * @param image_version Image version to be filled up
+ * @param hash Ptr to the read image hash
+ * @param flags Ptr to flags filled up from the image
+ */
+int img_mgmt_read_info(int image_slot, struct image_version *ver,
+ uint8_t *hash, uint32_t *flags);
+
+/**
+ * @brief Get the current running image version
+ *
+ * @param image_version Given image version
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+img_mgmt_my_version(struct image_version *ver);
+
+/**
+ * @brief Get image version in string from image_version
+ *
+ * @param image_version Structure filled with image version
+ * information
+ * @param dst Destination string created from the given
+ * in image version
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+img_mgmt_ver_str(const struct image_version *ver, char *dst);
+
+/**
+ * @brief Check if the image slot is in use
+ *
+ * @param slot Slot to check if its in use
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+img_mgmt_slot_in_use(int slot);
+
+/**
+ * @brief Collects information about the specified image slot
+ *
+ * @param query_slot Slot to read state flags from
+ *
+ * @return return the state flags
+ */
+uint8_t
+img_mgmt_state_flags(int query_slot);
+
+/**
+ * @brief Sets the pending flag for the specified image slot. That is, the
system
+ * will swap to the specified image on the next reboot. If the permanent
+ * argument is specified, the system doesn't require a confirm after the swap
+ * occurs.
+ *
+ * @param slot Image slot to set pending
+ * @param permanent If set no confirm is required after image swap
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+img_mgmt_state_set_pending(int slot, int permanent);
+
+/**
+ * Confirms the current image state. Prevents a fallback from occurring on the
+ * next reboot if the active image is currently being tested.
+ *
+ * @return 0 on success, non -zero on failure
+ */
+int
+img_mgmt_state_confirm(void);
+
+/** @brief Generic callback function for events */
+typedef void (*img_mgmt_dfu_cb)(void);
+
+/** Callback function pointers */
+typedef struct
+{
Review comment:
done
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services