@@ -75,36 +75,38 @@ struct log_storage_info {
75
75
};
76
76
#endif
77
77
78
- typedef int (* log_walk_func_t )(struct log * , struct log_offset * log_offset ,
78
+ typedef int (* log_walk_func_t )(struct log * log , struct log_offset * log_offset ,
79
79
const void * dptr , uint16_t len );
80
80
81
81
typedef int (* log_walk_body_func_t )(struct log * log ,
82
82
struct log_offset * log_offset , const struct log_entry_hdr * hdr ,
83
83
const void * dptr , uint16_t len );
84
84
85
- typedef int (* lh_read_func_t )(struct log * , const void * dptr , void * buf ,
85
+ typedef int (* lh_read_func_t )(struct log * log , const void * dptr , void * buf ,
86
86
uint16_t offset , uint16_t len );
87
- typedef int (* lh_read_mbuf_func_t )(struct log * , const void * dptr , struct os_mbuf * om ,
87
+ typedef int (* lh_read_mbuf_func_t )(struct log * log , const void * dptr , struct os_mbuf * om ,
88
88
uint16_t offset , uint16_t len );
89
- typedef int (* lh_append_func_t )(struct log * , void * buf , int len );
89
+ typedef int (* lh_append_func_t )(struct log * log , void * buf , int len );
90
90
typedef int (* lh_append_body_func_t )(struct log * log ,
91
91
const struct log_entry_hdr * hdr ,
92
92
const void * body , int body_len );
93
93
typedef int (* lh_append_mbuf_func_t )(struct log * , struct os_mbuf * om );
94
94
typedef int (* lh_append_mbuf_body_func_t )(struct log * log ,
95
95
const struct log_entry_hdr * hdr ,
96
96
struct os_mbuf * om );
97
- typedef int (* lh_walk_func_t )(struct log * ,
97
+ typedef int (* lh_walk_func_t )(struct log * log ,
98
98
log_walk_func_t walk_func , struct log_offset * log_offset );
99
- typedef int (* lh_flush_func_t )(struct log * );
100
- typedef uint16_t (* lh_read_entry_len_func_t )(struct log * , const void * dptr );
99
+ typedef int (* lh_flush_func_t )(struct log * log );
100
+ typedef uint16_t (* lh_read_entry_len_func_t )(struct log * log , const void * dptr );
101
101
#if MYNEWT_VAL (LOG_STORAGE_INFO )
102
- typedef int (* lh_storage_info_func_t )(struct log * , struct log_storage_info * );
102
+ typedef int (* lh_storage_info_func_t )(struct log * log , struct log_storage_info * );
103
103
#endif
104
104
#if MYNEWT_VAL (LOG_STORAGE_WATERMARK )
105
- typedef int (* lh_set_watermark_func_t )(struct log * , uint32_t );
105
+ typedef int (* lh_set_watermark_func_t )(struct log * log , uint32_t );
106
106
#endif
107
- typedef int (* lh_registered_func_t )(struct log * );
107
+ typedef int (* lh_registered_func_t )(struct log * log );
108
+ /* This calculates length based on alignment of underlying medium */
109
+ typedef int (* lh_len_in_medium_func_t )(struct log * log , uint16_t len );
108
110
109
111
struct log_handler {
110
112
int log_type ;
@@ -118,6 +120,7 @@ struct log_handler {
118
120
lh_walk_func_t log_walk_sector ;
119
121
lh_flush_func_t log_flush ;
120
122
lh_read_entry_len_func_t log_read_entry_len ;
123
+ lh_len_in_medium_func_t log_len_in_medium ;
121
124
#if MYNEWT_VAL (LOG_STORAGE_INFO )
122
125
lh_storage_info_func_t log_storage_info ;
123
126
#endif
@@ -136,6 +139,7 @@ struct log_handler {
136
139
#define LOG_FLAGS_TLV_SUPPORT (1 << 1)
137
140
138
141
#define LOG_TLV_NUM_ENTRIES (1 << 0)
142
+ #define LOG_TLV_NUM_TLVS (1 << 1)
139
143
140
144
#if MYNEWT_VAL (LOG_VERSION ) == 3
141
145
struct log_entry_hdr {
@@ -146,12 +150,16 @@ struct log_entry_hdr {
146
150
uint8_t ue_etype : 4 ;
147
151
uint8_t ue_flags : 4 ;
148
152
uint8_t ue_imghash [4 ];
153
+ /* Number of entries field which helps in calculating number of
154
+ * entries per log, these go on incrementing similar to an index
155
+ * but per log.
156
+ */
149
157
uint32_t ue_num_entries ;
150
158
} __attribute__((__packed__ ));
151
159
152
160
struct log_tlv {
153
- uint8_t tag ;
154
161
uint8_t len ;
162
+ uint8_t tag ;
155
163
/* Value is of variable size appended based on len,
156
164
* val is logged after the tag and len are logged
157
165
*/
@@ -164,6 +172,30 @@ struct log_tlv {
164
172
#define LOG_BASE_ENTRY_HDR_SIZE (15)
165
173
166
174
#define LOG_NUM_ENTRIES_SIZE (sizeof(((struct log *)0)->l_num_entries))
175
+ #define LOG_NUM_TLVS_SIZE (1)
176
+
177
+ #if MYNEWT_VAL (LOG_FCB2 )
178
+ #define LF_MAX_ALIGN LOG_FCB2_MAX_ALIGN
179
+ #else
180
+ #define LF_MAX_ALIGN LOG_FCB_MAX_ALIGN
181
+ #endif
182
+
183
+ #define LOG_FCB_MAX_TLV_SIZE (__tlv_name__ ) \
184
+ /* sizeof(struct log_tlv)) + alignment */ \
185
+ (LF_MAX_ALIGN + \
186
+ /* Max size per value of TLV including alignment */ \
187
+ (LOG_ ## __tlv_name__ ## _SIZE /LF_MAX_ALIGN ) ? \
188
+ (LOG_ ## __tlv_name__ ## _SIZE + LF_MAX_ALIGN ) : \
189
+ LF_MAX_ALIGN )
190
+
191
+ #define LOG_FCB_MAX_TLVS_SIZE LOG_FCB_MAX_TLV_SIZE(NUM_ENTRIES) + \
192
+ LOG_FCB_MAX_TLV_SIZE(NUM_TLVS)
193
+
194
+ #define LOG_FCB_EXT_HDR_SIZE LOG_BASE_ENTRY_HDR_SIZE + LOG_IMG_HASHLEN + \
195
+ LF_MAX_ALIGN
196
+
197
+ #define LOG_FCB_FLAT_BUF_SIZE (LOG_FCB_EXT_HDR_SIZE > LOG_FCB_MAX_TLVS_SIZE) ? \
198
+ LOG_FCB_EXT_HDR_SIZE : LOG_FCB_MAX_TLVS_SIZE
167
199
168
200
#define LOG_MODULE_STR (module ) log_module_get_name(module)
169
201
@@ -532,6 +564,10 @@ int log_read(struct log *log, const void *dptr, void *buf, uint16_t off,
532
564
/**
533
565
* Reads entry length from the specified log.
534
566
*
567
+ * @param log The log to read from.
568
+ * @param dptr Medium-specific data describing the area to
569
+ * read from; typically obtained by a call to
570
+ * `log_walk`.
535
571
* @return The number of bytes of entry length; 0 on failure.
536
572
*/
537
573
uint16_t
@@ -580,7 +616,7 @@ uint16_t log_hdr_len(const struct log_entry_hdr *hdr);
580
616
*
581
617
* @return Length of the trailer
582
618
*/
583
- uint16_t log_trailer_len (const struct log_entry_hdr * hdr );
619
+ uint16_t log_trailer_len (struct log * log , const struct log_entry_hdr * hdr );
584
620
585
621
/**
586
622
* @brief Reads data from the body of a log entry into a flat buffer.
@@ -778,13 +814,27 @@ int log_set_watermark(struct log *log, uint32_t index);
778
814
*
779
815
* @param log Ptr to log structure
780
816
* @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
817
+ * @param num_entries Ptr to number of entries
818
+ * @param offset Offset of the num of entries field in the log entry
783
819
*
784
820
* @return 0 on success, non-zero on failure
785
821
*/
786
822
int log_fill_num_entries (struct log * log , const void * dptr ,
787
- struct log_entry_hdr * hdr , uint16_t offset );
823
+ uint32_t * num_entries ,
824
+ uint16_t offset );
825
+ /**
826
+ * Fill number of tlvs
827
+ *
828
+ * @param log Ptr to log structure
829
+ * @param dptr Ptr to data to be read
830
+ * @param num_entries Ptr to number of entries
831
+ * @param offset Offset of the num of entries field in the log entry
832
+ *
833
+ * @return 0 on success, non-zero on failure
834
+ */
835
+ int
836
+ log_fill_num_tlvs (struct log * log , const void * dptr , uint8_t * num_tlvs ,
837
+ uint16_t offset );
788
838
789
839
/**
790
840
* Fill log current image hash
@@ -819,6 +869,14 @@ log_read_hdr_by_idx(struct log *log, uint32_t idx, struct log_entry_hdr *out_hdr
819
869
int
820
870
log_get_entries (struct log * log , uint32_t idx , uint32_t * entries );
821
871
872
+ /* Get the length of data in medium - storage (fcb/fcb2), memory or stream
873
+ *
874
+ * @param log The log to get number of entries for
875
+ * @param len Length in medium with padding if any
876
+ */
877
+ int
878
+ log_len_in_medium (struct log * log , uint16_t len );
879
+
822
880
/* Handler exports */
823
881
#if MYNEWT_VAL (LOG_CONSOLE )
824
882
extern const struct log_handler log_console_handler ;
0 commit comments