[GitHub] mkiiskila commented on a change in pull request #281: imgmgr: add erase command, remove erase from upload command

2017-05-30 Thread git
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_r119240061
 
 

 ##
 File path: sys/flash_map/src/flash_map.c
 ##
 @@ -131,6 +132,40 @@ flash_area_align(const struct flash_area *fa)
 return hal_flash_align(fa->fa_device_id);
 }
 
+int
+flash_area_is_empty(const struct flash_area *fa, bool *empty)
+{
+uint32_t data[64 >> 2];
+uint32_t data_off = 0;
+int8_t bytes_to_read;
+uint8_t i;
+int rc;
+
+while(data_off < fa->fa_size)
+{
 
 Review comment:
   Can you fix the coding style?
   See 
https://github.com/apache/incubator-mynewt-core/blob/master/CODING_STANDARDS.md
 

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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] mkiiskila commented on a change in pull request #281: imgmgr: add erase command, remove erase from upload command

2017-05-30 Thread git
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_r119241026
 
 

 ##
 File path: sys/flash_map/src/flash_map.c
 ##
 @@ -131,6 +132,40 @@ flash_area_align(const struct flash_area *fa)
 return hal_flash_align(fa->fa_device_id);
 }
 
+int
+flash_area_is_empty(const struct flash_area *fa, bool *empty)
+{
+uint32_t data[64 >> 2];
+uint32_t data_off = 0;
+int8_t bytes_to_read;
+uint8_t i;
+int rc;
+
+while(data_off < fa->fa_size)
+{
+bytes_to_read = min(64, fa->fa_size - data_off);
+rc = flash_area_read(fa, data_off, data, bytes_to_read);
+if (rc) {
+return rc;
+}
+for (i = 0; i < bytes_to_read >> 2; i++){
+  if (data[i] != (uint32_t) -1) {
+goto not_empty;
+  }
+}
+for (i = i << 2; i < bytes_to_read; i++) {
+  if (*(((uint8_t *) data) + i) != (uint8_t) -1) {
+goto not_empty;
+  }
+}
 
 Review comment:
   I don't think this 2nd for loop is needed. I have not encountered a flash 
sector which would not be a multiple of minimally 4 bytes.
 

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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] mkiiskila commented on a change in pull request #281: imgmgr: add erase command, remove erase from upload command

2017-05-30 Thread git
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_r119239939
 
 

 ##
 File path: sys/flash_map/src/flash_map.c
 ##
 @@ -21,6 +21,7 @@
 #include 
 #include 
 
+#include 
 
 Review comment:
   Do we need this inclusion?
 

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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] mkiiskila commented on a change in pull request #281: imgmgr: add erase command, remove erase from upload command

2017-05-30 Thread git
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_r119239877
 
 

 ##
 File path: sys/flash_map/include/flash_map/flash_map.h
 ##
 @@ -41,6 +41,7 @@ extern "C" {
  * match the linker scripts when platform executes from flash,
  * and match the target offset specified in download script.
  */
+#include 
 
 Review comment:
   Do we need this inclusion?
 

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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] mkiiskila commented on a change in pull request #281: imgmgr: add erase command, remove erase from upload command

2017-05-30 Thread git
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, , 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, _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:
us...@infra.apache.org


With regards,
Apache Git Services