manish-sudo commented on a change in pull request #2011: Change Reboot log from 
text to CBOR encoded.
URL: https://github.com/apache/mynewt-core/pull/2011#discussion_r329175599
 
 

 ##########
 File path: sys/reboot/src/log_reboot.c
 ##########
 @@ -175,41 +184,89 @@ log_reboot_write(const struct log_reboot_info *info)
     }
 #endif
 
-    rc = imgr_read_info(boot_current_slot, &ver, hash, NULL);
+    rc = imgr_read_info(boot_current_slot, &ver, hash, &flags);
     if (rc != 0) {
         return rc;
     }
 
-    off = 0;
-    off += snprintf(buf + off, sizeof buf - off,
-                    "rsn:%s, cnt:%u, img:%u.%u.%u.%u, hash:",
-                    REBOOT_REASON_STR(info->reason), reboot_cnt, ver.iv_major,
-                    ver.iv_minor, ver.iv_revision,
-                    (unsigned int)ver.iv_build_num);
+    memset(cbor_enc_buf, 0, sizeof(cbor_enc_buf));
+
+    cbor_buf_writer_init(&writer, cbor_enc_buf, sizeof(cbor_enc_buf));
+    cbor_encoder_init(&enc, &writer.enc, 0);
+    rc = cbor_encoder_create_map(&enc, &map, CborIndefiniteLength);
+    if (rc != 0) {
+        return rc;
+    }
 
+    cbor_encode_text_stringz(&map, "rsn");
+    cbor_encode_text_stringz(&map, REBOOT_REASON_STR(info->reason));
+
+    cbor_encode_text_stringz(&map, "cnt");
+    cbor_encode_int(&map, reboot_cnt);
+
+    cbor_encode_text_stringz(&map, "img");
+    snprintf(buf, sizeof(buf), "%u.%u.%u.%u",
+                  ver.iv_major, ver.iv_minor, ver.iv_revision,
+                  (unsigned int) ver.iv_build_num);
+    cbor_encode_text_stringz(&map, buf);
+
+    cbor_encode_text_stringz(&map, "hash");
+    off = 0;
     for (i = 0; i < sizeof hash; i++) {
         off += snprintf(buf + off, sizeof buf - off, "%02x",
                         (unsigned int)hash[i]);
     }
+    cbor_encode_text_stringz(&map, buf);
 
     if (info->file != NULL) {
-        off += snprintf(buf + off, sizeof buf - off, ", die:%s:%d",
-                info->file, info->line);
+        cbor_encode_text_stringz(&map, "die");
+        off  = 0;
+
+        /* If die filename is longer than 1/3 of total allocated
+         * buffer, then trim the filename from left. */
+        if (strlen(info->file) > (sizeof(buf) / 3))
+        {
+            off = strlen(info->file) - (sizeof(buf)/3);
+        }
+        snprintf(buf, sizeof(buf), "%s:%d",
+                &info->file[off], info->line);
+        cbor_encode_text_stringz(&map, buf);
     }
 
     if (info->pc != 0) {
-        off += snprintf(buf + off, sizeof buf - off, ", pc:0x%lx",
-                (unsigned long)info->pc);
+        cbor_encode_text_stringz(&map, "pc");
+        cbor_encode_int(&map, (unsigned long)info->pc);
+    }
+
+    state_flags = imgmgr_state_flags(boot_current_slot);
+    cbor_encode_text_stringz(&map, "flags");
+    off = 0;
+    if (state_flags & IMGMGR_STATE_F_ACTIVE) {
+        off += snprintf(buf + off, sizeof buf - off, "%s ", "active");
     }
+    if (!(flags & IMAGE_F_NON_BOOTABLE)) {
+       off += snprintf(buf + off, sizeof buf - off, "%s ", "bootable");
+       }
+    if (state_flags & IMGMGR_STATE_F_CONFIRMED) {
+       off += snprintf(buf + off, sizeof buf - off, "%s ", "confirmed");
+    }
+    if (state_flags & IMGMGR_STATE_F_PENDING) {
+       off += snprintf(buf + off, sizeof buf - off, "%s ", "pending");
+    }
+    buf[off - 1] = '\0';
 
 Review comment:
   I thought of adding a protection earlier, but didn't thought it's absolutely 
required as technically there will be at-least one flag. Anyway, for the sanity 
I guarded this unlikely case.

----------------------------------------------------------------
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

Reply via email to