mkiiskila commented on a change in pull request #281: imgmgr: add erase
command, remove erase from upload command
URL:
https://github.com/apache/incubator-mynewt-core/pull/281#discussion_r119239770
##########
File path: mgmt/imgmgr/src/imgmgr.c
##########
@@ -223,6 +228,70 @@ imgr_find_by_hash(uint8_t *find, struct image_version
*ver)
}
static int
+imgr_erase(struct mgmt_cbuf *cb)
+{
+ struct image_version ver;
+ int area_id;
+ int best = -1;
+ int rc;
+ int i;
+ CborError g_err = CborNoError;
+
+ for (i = 0; i < 2; i++) {
+ rc = imgr_read_info(i, &ver, NULL, NULL);
+ if (rc < 0) {
+ continue;
+ }
+ if (rc == 0) {
+ /* Image in slot is ok. */
+ if (imgmgr_state_slot_in_use(i)) {
+ /* Slot is in use; can't erase to this. */
+ continue;
+ } else {
+ /*
+ * Not active slot, but image is ok. Use it if there are
+ * no better candidates.
+ */
+ best = i;
+ }
+ continue;
+ }
+ best = i;
+ break;
+ }
+ if (best >= 0) {
+ area_id = flash_area_id_from_image_slot(best);
+ if (imgr_state.upload.fa) {
+ flash_area_close(imgr_state.upload.fa);
+ imgr_state.upload.fa = NULL;
+ }
+ rc = flash_area_open(area_id, &imgr_state.upload.fa);
+ if (rc) {
+ return MGMT_ERR_EINVAL;
+ }
+ rc = flash_area_erase(imgr_state.upload.fa, 0,
+ imgr_state.upload.fa->fa_size);
Review comment:
Could call flash_area_close() for completeness.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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