Skip to content

Commit

Permalink
log imghash support added
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaz authored and vrahane committed Sep 28, 2019
1 parent 61dd615 commit 542db22
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
13 changes: 12 additions & 1 deletion cmd/log_mgmt/include/log_mgmt/log_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ extern "C" {
/** @brief Log entries are persisted across reboots. */
#define LOG_MGMT_TYPE_STORAGE 2

/* @brief Flags used to indicate type of data in reserved payload. */
#define LOG_MGMT_FLAGS_IMG_HASH (1 << 0)

/* @brief Log entry types. */
#define LOG_MGMT_ETYPE_STRING 0
#define LOG_MGMT_ETYPE_CBOR 1
#define LOG_MGMT_ETYPE_BINARY 2


/** @brief Generic descriptor for an OS-specific log. */
struct log_mgmt_log {
const char *name;
Expand All @@ -57,7 +66,9 @@ struct log_mgmt_entry {
size_t len;
uint8_t module;
uint8_t level;
uint8_t type;
uint8_t type:4;
uint8_t flags:4;
const uint8_t *imghash;
void *ctxt;
};

Expand Down
31 changes: 21 additions & 10 deletions cmd/log_mgmt/port/mynewt/src/mynewt_log_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,12 @@ mynewt_log_mgmt_walk_cb(struct log *log, struct log_offset *log_offset,
{
struct mynewt_log_mgmt_walk_arg *mynewt_log_mgmt_walk_arg;
struct log_mgmt_entry entry;
int header_len;
int read_len;
int rc;

mynewt_log_mgmt_walk_arg = log_offset->lo_arg;

/* If specified timestamp is nonzero, it is the primary criterion, and the
* specified index is the secondary criterion. If specified timetsamp is
* zero, specified index is the only criterion.
Expand All @@ -122,7 +123,6 @@ mynewt_log_mgmt_walk_cb(struct log *log, struct log_offset *log_offset,
* Else: encode entries whose timestamp >= specified timestamp and whose
* index >= specified index
*/

if (log_offset->lo_ts == 0) {
if (log_offset->lo_index > leh->ue_index) {
return 0;
Expand All @@ -133,21 +133,32 @@ mynewt_log_mgmt_walk_cb(struct log *log, struct log_offset *log_offset,
return 0;
}

read_len = min(len - sizeof leh, LOG_MGMT_BODY_LEN - sizeof leh);
rc = log_read(log, dptr, mynewt_log_mgmt_walk_arg->body, sizeof leh,
entry.ts = leh->ue_ts;
entry.index = leh->ue_index;
entry.module = leh->ue_module;
entry.level = leh->ue_level;

#if MYNEWT_VAL(LOG_VERSION) < 3
entry.type = LOG_ETYPE_STRING;
entry.flags = 0;
header_len = sizeof leh;
#else
entry.type = leh->ue_etype;
entry.flags = leh->ue_flags;
entry.imghash = (leh->ue_flags & LOG_FLAGS_IMG_HASH) ?
leh->ue_imghash : NULL;
header_len = log_hdr_len(leh);
#endif

read_len = min(len - header_len, LOG_MGMT_BODY_LEN - header_len);
rc = log_read(log, dptr, mynewt_log_mgmt_walk_arg->body, header_len,
read_len);
if (rc < 0) {
return MGMT_ERR_EUNKNOWN;
}

entry.ts = leh->ue_ts;
entry.index = leh->ue_index;
entry.module = leh->ue_module;
entry.level = leh->ue_level;
entry.len = rc;
entry.type = leh->ue_etype;
entry.data = mynewt_log_mgmt_walk_arg->body;

return mynewt_log_mgmt_walk_arg->cb(&entry, mynewt_log_mgmt_walk_arg->arg);
}

Expand Down
13 changes: 9 additions & 4 deletions cmd/log_mgmt/src/log_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ log_mgmt_encode_entry(CborEncoder *enc, const struct log_mgmt_entry *entry,
err |= cbor_encoder_create_map(enc, &rsp, CborIndefiniteLength);

switch (entry->type) {
case LOG_ETYPE_CBOR:
case LOG_MGMT_ETYPE_CBOR:
err |= cbor_encode_text_stringz(&rsp, "type");
err |= cbor_encode_text_stringz(&rsp, "cbor");
break;
case LOG_ETYPE_BINARY:
case LOG_MGMT_ETYPE_BINARY:
err |= cbor_encode_text_stringz(&rsp, "type");
err |= cbor_encode_text_stringz(&rsp, "bin");
break;
case LOG_ETYPE_STRING:
case LOG_MGMT_ETYPE_STRING:
err |= cbor_encode_text_stringz(&rsp, "type");
err |= cbor_encode_text_stringz(&rsp, "str");
break;
Expand All @@ -108,7 +108,7 @@ log_mgmt_encode_entry(CborEncoder *enc, const struct log_mgmt_entry *entry,
}

err |= cbor_encoder_close_container(&rsp, &str_encoder);

err |= cbor_encode_text_stringz(&rsp, "ts");
err |= cbor_encode_int(&rsp, entry->ts);
err |= cbor_encode_text_stringz(&rsp, "level");
Expand All @@ -117,6 +117,11 @@ log_mgmt_encode_entry(CborEncoder *enc, const struct log_mgmt_entry *entry,
err |= cbor_encode_uint(&rsp, entry->index);
err |= cbor_encode_text_stringz(&rsp, "module");
err |= cbor_encode_uint(&rsp, entry->module);
if (entry->flags & LOG_MGMT_FLAGS_IMG_HASH) {
err |= cbor_encode_text_stringz(&rsp, "imghash");
err |= cbor_encode_byte_string(&rsp, entry->imghash,
LOG_MGMT_IMG_HASHLEN);
}
err |= cbor_encoder_close_container(enc, &rsp);

if (out_len != NULL) {
Expand Down
1 change: 1 addition & 0 deletions cmd/log_mgmt/src/log_mgmt_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define LOG_MGMT_CHUNK_SIZE MYNEWT_VAL(LOG_MGMT_CHUNK_SIZE)
#define LOG_MGMT_NAME_LEN MYNEWT_VAL(LOG_MGMT_NAME_LEN)
#define LOG_MGMT_BODY_LEN MYNEWT_VAL(LOG_MGMT_BODY_LEN)
#define LOG_MGMT_IMG_HASHLEN 4

#elif defined __ZEPHYR__

Expand Down

0 comments on commit 542db22

Please sign in to comment.