@@ -97,6 +97,7 @@ typedef int (*lh_append_mbuf_body_func_t)(struct log *log,
97
97
typedef int (* lh_walk_func_t )(struct log * ,
98
98
log_walk_func_t walk_func , struct log_offset * log_offset );
99
99
typedef int (* lh_flush_func_t )(struct log * );
100
+ typedef uint16_t (* lh_read_entry_len_func_t )(struct log * , const void * dptr );
100
101
#if MYNEWT_VAL (LOG_STORAGE_INFO )
101
102
typedef int (* lh_storage_info_func_t )(struct log * , struct log_storage_info * );
102
103
#endif
@@ -116,6 +117,7 @@ struct log_handler {
116
117
lh_walk_func_t log_walk ;
117
118
lh_walk_func_t log_walk_sector ;
118
119
lh_flush_func_t log_flush ;
120
+ lh_read_entry_len_func_t log_read_entry_len ;
119
121
#if MYNEWT_VAL (LOG_STORAGE_INFO )
120
122
lh_storage_info_func_t log_storage_info ;
121
123
#endif
@@ -129,25 +131,40 @@ struct log_handler {
129
131
/* Image hash length to be looged */
130
132
#define LOG_IMG_HASHLEN 4
131
133
132
- /* Flags used to indicate type of data in reserved payload*/
133
- #define LOG_FLAGS_IMG_HASH (1 << 0)
134
+ /* Flags used to indicate type of data in reserved payload */
135
+ #define LOG_FLAGS_IMG_HASH (1 << 0)
136
+ #define LOG_FLAGS_TLV_SUPPORT (1 << 1)
137
+
138
+ #define LOG_TLV_NUM_ENTRIES (1 << 0)
134
139
135
140
#if MYNEWT_VAL (LOG_VERSION ) == 3
136
141
struct log_entry_hdr {
137
142
int64_t ue_ts ;
138
143
uint32_t ue_index ;
139
144
uint8_t ue_module ;
140
145
uint8_t ue_level ;
141
- uint8_t ue_etype : 4 ;
142
- uint8_t ue_flags : 4 ;
146
+ uint8_t ue_etype : 4 ;
147
+ uint8_t ue_flags : 4 ;
143
148
uint8_t ue_imghash [4 ];
144
- }__attribute__((__packed__ ));
149
+ uint32_t ue_num_entries ;
150
+ } __attribute__((__packed__ ));
151
+
152
+ struct log_tlv {
153
+ uint8_t tag ;
154
+ uint8_t len ;
155
+ /* Value is of variable size appended based on len,
156
+ * val is logged after the tag and len are logged
157
+ */
158
+ } __attribute__((__packed__ ));
159
+
145
160
#else
146
161
#error "Unsupported log version"
147
162
#endif
148
163
149
164
#define LOG_BASE_ENTRY_HDR_SIZE (15)
150
165
166
+ #define LOG_NUM_ENTRIES_SIZE (sizeof(((struct log *)0)->l_num_entries))
167
+
151
168
#define LOG_MODULE_STR (module ) log_module_get_name(module)
152
169
153
170
#if MYNEWT_VAL (LOG_LEVEL ) <= LOG_LEVEL_DEBUG
@@ -213,6 +230,7 @@ struct log {
213
230
#if !MYNEWT_VAL (LOG_GLOBAL_IDX )
214
231
uint32_t l_idx ;
215
232
#endif
233
+ uint32_t l_num_entries ;
216
234
#if MYNEWT_VAL (LOG_STATS )
217
235
STATS_SECT_DECL (logs ) l_stats ;
218
236
#endif
@@ -511,6 +529,14 @@ void log_printf(struct log *log, uint8_t module, uint8_t level,
511
529
int log_read (struct log * log , const void * dptr , void * buf , uint16_t off ,
512
530
uint16_t len );
513
531
532
+ /**
533
+ * Reads entry length from the specified log.
534
+ *
535
+ * @return The number of bytes of entry length; 0 on failure.
536
+ */
537
+ uint16_t
538
+ log_read_entry_len (struct log * log , const void * dptr );
539
+
514
540
/**
515
541
* @brief Reads a single log entry header.
516
542
*
@@ -524,15 +550,37 @@ int log_read(struct log *log, const void *dptr, void *buf, uint16_t off,
524
550
*/
525
551
int log_read_hdr (struct log * log , const void * dptr , struct log_entry_hdr * hdr );
526
552
553
+ /**
554
+ * @brief Reads a single log entry trailer.
555
+ *
556
+ * @param log The log to read from.
557
+ * @param dptr Medium-specific data describing the area to
558
+ * read from; typically obtained by a call to
559
+ * `log_walk`.
560
+ * @param tlv tlv type
561
+ * @param buf Value buffer
562
+ *
563
+ * @return 0 on success; nonzero on failure.
564
+ */
565
+ int log_read_trailer (struct log * log , const void * dptr , uint16_t tlv , void * buf );
566
+
527
567
/**
528
568
* @brief Reads the header length
529
569
*
530
570
* @param hdr Ptr to the header
531
- *
571
+ *
532
572
* @return Length of the header
533
573
*/
534
- uint16_t
535
- log_hdr_len (const struct log_entry_hdr * hdr );
574
+ uint16_t log_hdr_len (const struct log_entry_hdr * hdr );
575
+
576
+ /**
577
+ * @brief Reads the trailer length
578
+ *
579
+ * @param hdr Ptr to the header
580
+ *
581
+ * @return Length of the trailer
582
+ */
583
+ uint16_t log_trailer_len (const struct log_entry_hdr * hdr );
536
584
537
585
/**
538
586
* @brief Reads data from the body of a log entry into a flat buffer.
@@ -725,6 +773,19 @@ log_set_rotate_notify_cb(struct log *log, log_notify_rotate_cb *cb);
725
773
int log_set_watermark (struct log * log , uint32_t index );
726
774
#endif
727
775
776
+ /**
777
+ * Fill number of entries
778
+ *
779
+ * @param log Ptr to log structure
780
+ * @param dptr Ptr to data to be read
781
+ * @param hdr Ptr to the header
782
+ * @param offset Offset of the num of entries in the log entry
783
+ *
784
+ * @return 0 on success, non-zero on failure
785
+ */
786
+ int log_fill_num_entries (struct log * log , const void * dptr ,
787
+ struct log_entry_hdr * hdr , uint16_t offset );
788
+
728
789
/**
729
790
* Fill log current image hash
730
791
*
@@ -735,6 +796,29 @@ int log_set_watermark(struct log *log, uint32_t index);
735
796
int
736
797
log_fill_current_img_hash (struct log_entry_hdr * hdr );
737
798
799
+ /**
800
+ * Reads the log entry's header from the specified log and log index
801
+ *
802
+ * @param log The log to read from.
803
+ * @param idx Index of the log entry to read header from
804
+ * @param out_hdr On success, the last entry header gets written
805
+ * here.
806
+ *
807
+ * @return 0 on success; nonzero on failure.
808
+ */
809
+ int
810
+ log_read_hdr_by_idx (struct log * log , uint32_t idx , struct log_entry_hdr * out_hdr );
811
+
812
+ /**
813
+ * Get number of entries in log
814
+ *
815
+ * @param log The log to get number of entries for
816
+ * @param idx The log index to read number of entries from
817
+ * @param num_entries Ptr to fill up number of entries in log
818
+ */
819
+ int
820
+ log_get_entries (struct log * log , uint32_t idx , uint32_t * entries );
821
+
738
822
/* Handler exports */
739
823
#if MYNEWT_VAL (LOG_CONSOLE )
740
824
extern const struct log_handler log_console_handler ;
0 commit comments