Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys/log: Add number of entries support in log #3168

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
12 changes: 0 additions & 12 deletions apps/slinky/pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,3 @@ pkg.deps:
pkg.deps.I2C_0: test/i2c_scan
pkg.deps.I2C_1: test/i2c_scan
pkg.deps.I2C_2: test/i2c_scan

pkg.deps.CONFIG_NFFS:
- "@apache-mynewt-core/fs/nffs"

pkg.deps.CONFIG_LITTLEFS:
- "@apache-mynewt-core/fs/littlefs"

pkg.deps.CONFIG_FCB:
- "@apache-mynewt-core/fs/fcb"

pkg.deps.REBOOT_LOG_FCB:
- "@apache-mynewt-core/fs/fcb"
2 changes: 1 addition & 1 deletion hw/mcu/native/src/hal_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static int
flash_native_write_internal(uint32_t address, const void *src, uint32_t length,
int allow_overwrite)
{
static uint8_t buf[256];
uint8_t buf[256] = {0};
uint32_t cur;
uint32_t end;
int chunk_sz;
Expand Down
100 changes: 92 additions & 8 deletions sys/log/full/include/log/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ typedef int (*lh_append_mbuf_body_func_t)(struct log *log,
typedef int (*lh_walk_func_t)(struct log *,
log_walk_func_t walk_func, struct log_offset *log_offset);
typedef int (*lh_flush_func_t)(struct log *);
typedef uint16_t (*lh_read_entry_len_func_t)(struct log *, const void *dptr);
vrahane marked this conversation as resolved.
Show resolved Hide resolved
#if MYNEWT_VAL(LOG_STORAGE_INFO)
typedef int (*lh_storage_info_func_t)(struct log *, struct log_storage_info *);
#endif
Expand All @@ -116,6 +117,7 @@ struct log_handler {
lh_walk_func_t log_walk;
lh_walk_func_t log_walk_sector;
lh_flush_func_t log_flush;
lh_read_entry_len_func_t log_read_entry_len;
#if MYNEWT_VAL(LOG_STORAGE_INFO)
lh_storage_info_func_t log_storage_info;
#endif
Expand All @@ -129,25 +131,40 @@ struct log_handler {
/* Image hash length to be looged */
#define LOG_IMG_HASHLEN 4

/* Flags used to indicate type of data in reserved payload*/
#define LOG_FLAGS_IMG_HASH (1 << 0)
/* Flags used to indicate type of data in reserved payload */
#define LOG_FLAGS_IMG_HASH (1 << 0)
#define LOG_FLAGS_TLV_SUPPORT (1 << 1)

#define LOG_TLV_NUM_ENTRIES (1 << 0)

#if MYNEWT_VAL(LOG_VERSION) == 3
struct log_entry_hdr {
int64_t ue_ts;
uint32_t ue_index;
uint8_t ue_module;
uint8_t ue_level;
uint8_t ue_etype:4;
uint8_t ue_flags:4;
uint8_t ue_etype : 4;
uint8_t ue_flags : 4;
uint8_t ue_imghash[4];
}__attribute__((__packed__));
uint32_t ue_num_entries;
vrahane marked this conversation as resolved.
Show resolved Hide resolved
} __attribute__((__packed__));

struct log_tlv {
uint8_t tag;
uint8_t len;
/* Value is of variable size appended based on len,
* val is logged after the tag and len are logged
*/
} __attribute__((__packed__));

#else
#error "Unsupported log version"
#endif

#define LOG_BASE_ENTRY_HDR_SIZE (15)

#define LOG_NUM_ENTRIES_SIZE (sizeof(((struct log *)0)->l_num_entries))

#define LOG_MODULE_STR(module) log_module_get_name(module)

#if MYNEWT_VAL(LOG_LEVEL) <= LOG_LEVEL_DEBUG
Expand Down Expand Up @@ -213,6 +230,7 @@ struct log {
#if !MYNEWT_VAL(LOG_GLOBAL_IDX)
uint32_t l_idx;
#endif
uint32_t l_num_entries;
#if MYNEWT_VAL(LOG_STATS)
STATS_SECT_DECL(logs) l_stats;
#endif
Expand Down Expand Up @@ -511,6 +529,14 @@ void log_printf(struct log *log, uint8_t module, uint8_t level,
int log_read(struct log *log, const void *dptr, void *buf, uint16_t off,
uint16_t len);

/**
* Reads entry length from the specified log.
*
* @return The number of bytes of entry length; 0 on failure.
vrahane marked this conversation as resolved.
Show resolved Hide resolved
*/
uint16_t
log_read_entry_len(struct log *log, const void *dptr);

/**
* @brief Reads a single log entry header.
*
Expand All @@ -524,15 +550,37 @@ int log_read(struct log *log, const void *dptr, void *buf, uint16_t off,
*/
int log_read_hdr(struct log *log, const void *dptr, struct log_entry_hdr *hdr);

/**
* @brief Reads a single log entry trailer.
*
* @param log The log to read from.
* @param dptr Medium-specific data describing the area to
* read from; typically obtained by a call to
* `log_walk`.
* @param tlv tlv type
* @param buf Value buffer
*
* @return 0 on success; nonzero on failure.
*/
int log_read_trailer(struct log *log, const void *dptr, uint16_t tlv, void *buf);

/**
* @brief Reads the header length
*
* @param hdr Ptr to the header
*
*
* @return Length of the header
*/
uint16_t
log_hdr_len(const struct log_entry_hdr *hdr);
uint16_t log_hdr_len(const struct log_entry_hdr *hdr);

/**
* @brief Reads the trailer length
*
* @param hdr Ptr to the header
*
* @return Length of the trailer
*/
uint16_t log_trailer_len(const struct log_entry_hdr *hdr);

/**
* @brief Reads data from the body of a log entry into a flat buffer.
Expand Down Expand Up @@ -725,6 +773,19 @@ log_set_rotate_notify_cb(struct log *log, log_notify_rotate_cb *cb);
int log_set_watermark(struct log *log, uint32_t index);
#endif

/**
* Fill number of entries
*
* @param log Ptr to log structure
* @param dptr Ptr to data to be read
* @param hdr Ptr to the header
* @param offset Offset of the num of entries in the log entry
*
* @return 0 on success, non-zero on failure
*/
int log_fill_num_entries(struct log *log, const void *dptr,
struct log_entry_hdr *hdr, uint16_t offset);

/**
* Fill log current image hash
*
Expand All @@ -735,6 +796,29 @@ int log_set_watermark(struct log *log, uint32_t index);
int
log_fill_current_img_hash(struct log_entry_hdr *hdr);

/**
* Reads the log entry's header from the specified log and log index
*
* @param log The log to read from.
* @param idx Index of the log entry to read header from
* @param out_hdr On success, the last entry header gets written
* here.
*
* @return 0 on success; nonzero on failure.
*/
int
log_read_hdr_by_idx(struct log *log, uint32_t idx, struct log_entry_hdr *out_hdr);

/**
* Get number of entries in log
*
* @param log The log to get number of entries for
* @param idx The log index to read number of entries from
* @param num_entries Ptr to fill up number of entries in log
*/
int
log_get_entries(struct log *log, uint32_t idx, uint32_t *entries);

/* Handler exports */
#if MYNEWT_VAL(LOG_CONSOLE)
extern const struct log_handler log_console_handler;
Expand Down
30 changes: 30 additions & 0 deletions sys/log/full/selftest/align1_img_hash_num_entries/pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
pkg.name: sys/log/full/selftest/align1_img_hash_num_entries
pkg.type: unittest
pkg.description: "Log unit tests; flash-alignment=1."
pkg.author: "Apache Mynewt <dev@mynewt.apache.org>"
pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:

pkg.deps:
- "@apache-mynewt-core/sys/console/stub"
- "@apache-mynewt-core/sys/log/full"
- "@apache-mynewt-core/sys/log/full/selftest/util"
- "@apache-mynewt-core/test/testutil"
- "@apache-mynewt-core/boot/stub"
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#include "os/mynewt.h"
#include "log_test_util/log_test_util.h"

int
main(int argc, char **argv)
{
log_test_suite_cbmem_flat();
log_test_suite_cbmem_mbuf();
log_test_suite_fcb_flat();
log_test_suite_fcb_mbuf();
log_test_suite_misc();

return tu_any_failed;
}
30 changes: 30 additions & 0 deletions sys/log/full/selftest/align1_img_hash_num_entries/syscfg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

syscfg.vals:
LOG_FCB: 1
MCU_FLASH_MIN_WRITE_SIZE: 1

# The mbuf append tests allocate lots of mbufs; ensure no exhaustion.
MSYS_1_BLOCK_COUNT: 1000
LOG_FLAGS_IMAGE_HASH: 1
LOG_FLAGS_TLV_SUPPORT: 1
LOG_TLV_NUM_ENTRIES: 1
IMGMGR_DUMMY_HDR: 1
LOG_MGMT: 0
IMG_MGMT: 0
30 changes: 30 additions & 0 deletions sys/log/full/selftest/align1_num_entries/pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
pkg.name: sys/log/full/selftest/align1_num_entries
pkg.type: unittest
pkg.description: "Log unit tests; flash-alignment=1."
pkg.author: "Apache Mynewt <dev@mynewt.apache.org>"
pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:

pkg.deps:
- "@apache-mynewt-core/sys/console/stub"
- "@apache-mynewt-core/sys/log/full"
- "@apache-mynewt-core/sys/log/full/selftest/util"
- "@apache-mynewt-core/test/testutil"
- "@apache-mynewt-core/boot/stub"
33 changes: 33 additions & 0 deletions sys/log/full/selftest/align1_num_entries/src/log_test_align1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#include "os/mynewt.h"
#include "log_test_util/log_test_util.h"

int
main(int argc, char **argv)
{
log_test_suite_cbmem_flat();
log_test_suite_cbmem_mbuf();
log_test_suite_fcb_flat();
log_test_suite_fcb_mbuf();
log_test_suite_misc();

return tu_any_failed;
}
29 changes: 29 additions & 0 deletions sys/log/full/selftest/align1_num_entries/syscfg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

syscfg.vals:
LOG_FCB: 1
MCU_FLASH_MIN_WRITE_SIZE: 1

# The mbuf append tests allocate lots of mbufs; ensure no exhaustion.
MSYS_1_BLOCK_COUNT: 1000
LOG_FLAGS_TLV_SUPPORT: 1
LOG_TLV_NUM_ENTRIES: 1
IMGMGR_DUMMY_HDR: 1
LOG_MGMT: 0
IMG_MGMT: 0
Loading
Loading