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_r330781509
##########
File path: cmd/img_mgmt/port/mynewt/src/mynewt_img_mgmt.c
##########
@@ -157,27 +392,124 @@ img_mgmt_impl_read(int slot, unsigned int offset, void
*dst,
return 0;
}
+#if MYNEWT_VAL(IMG_MGMT_LAZY_ERASE)
int
img_mgmt_impl_write_image_data(unsigned int offset, const void *data,
unsigned int num_bytes, bool last)
{
const struct flash_area *fa;
+ struct flash_area sector;
int rc;
rc = flash_area_open(FLASH_AREA_IMAGE_1, &fa);
if (rc != 0) {
return MGMT_ERR_EUNKNOWN;
}
+ /* Check if there any unerased target sectors, if not clean them. */
+ while ((fa->fa_off + offset + num_bytes) > upload_state.sector_end) {
+ rc = flash_area_getnext_sector(fa->fa_id, &upload_state.sector_id,
+ §or);
+ if (rc) {
+ goto err;
+ }
+ rc = flash_area_erase(§or, 0, sector.fa_size);
+ if (rc) {
+ goto err;
+ }
+ upload_state.sector_end = sector.fa_off + sector.fa_size;
+ }
+
+ if (last) {
+ upload_state.sector_id = -1;
+ upload_state.sector_end = 0;
+ }
+
rc = flash_area_write(fa, offset, data, num_bytes);
flash_area_close(fa);
if (rc != 0) {
return MGMT_ERR_EUNKNOWN;
}
return 0;
+
+err:
+ upload_state.sector_id = -1;
+ upload_state.sector_end = 0;
+ return MGMT_ERR_EUNKNOWN;
}
+#else
+int
+img_mgmt_impl_write_image_data(unsigned int offset, const void *data,
+ unsigned int num_bytes, bool last)
+{
+ const struct flash_area *fa;
+ int rc;
+
+ rc = flash_area_open(FLASH_AREA_IMAGE_1, &fa);
+ if (rc != 0) {
+ return MGMT_ERR_EUNKNOWN;
+ }
+
+ rc = flash_area_write(fa, offset, data, num_bytes);
+ flash_area_close(fa);
+ if (rc != 0) {
+ return MGMT_ERR_EUNKNOWN;
+ }
+
+ return 0;
+}
+#endif
+
+int
+img_mgmt_impl_erase_image_data(unsigned int off, unsigned int num_bytes)
+{
+ const struct flash_area *fa;
+ int rc;
+
+ rc = flash_area_open(FLASH_AREA_IMAGE_1, &fa);
+ if (rc != 0) {
+ return MGMT_ERR_EUNKNOWN;
+ }
+
+ rc = flash_area_erase(fa, off, num_bytes);
+ flash_area_close(fa);
+ if (rc != 0) {
+ return MGMT_ERR_EUNKNOWN;
+ }
+
+ return 0;
+}
+
+#if MYNEWT_VAL(IMG_MGMT_LAZY_ERASE)
+int
+img_mgmt_impl_erase_if_needed(uint32_t off, uint32_t len)
+{
+ int rc = 0;
+ struct flash_area sector;
+ const struct flash_area *cfa;
+
+ rc = flash_area_open(FLASH_AREA_IMAGE_1, &cfa);
+ if (rc != 0) {
+ return MGMT_ERR_EUNKNOWN;
+ }
+
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