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

Common log msg #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions os/include/tinyara/common_logs/common_logs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
typedef enum
{
/* Memory Operations */
CMN_LOG_ALLOC_FAIL,
CMN_LOG_NULL_CHECK_FAIL,
CMN_LOG_OUT_OF_MEMORY,
CMN_LOG_MEM_LEAK,
CMN_LOG_BUFFER_OVERFLOW,

/* File Operations */
CMN_LOG_FILE_NFOUND,
CMN_LOG_FILE_OPEN_ERROR,
CMN_LOG_FILE_READ_ERROR,
CMN_LOG_FILE_WRITE_ERROR,
CMN_LOG_FILE_SEEK_ERROR,
CMN_LOG_FILE_IOCTL_ERROR,

/* Network Operations */
CMN_LOG_CON_TIMEOUT,
CMN_LOG_CON_REFUSED,
CMN_LOG_DATA_TRANS_ERROR,
CMN_LOG_HANDSHAKE_FAILED,
CMN_LOG_CERTIFICATE_INVALID,

/* Authentication and Authorization */
CMN_LOG_INVALID_CREDENTIALS,

/* Commonly used logs for printing information */
CMN_LOG_VALUE_OF,
CMN_LOG_INVALID_VAL,
CMN_LOG_FAILED_OP,
CMN_LOG_PERFORMING_OP,
CMN_LOG_INIT_DONE,
CMN_LOG_DEINIT_DONE,
CMN_LOG_START,
CMN_LOG_END,
CMN_LOG_INVALID_DATA,
CMN_LOG_VALID_DATA,

CMN_LOG_MSG_MAX

} CLOG_INDEX;

static const char* clog_message_str[CMN_LOG_MSG_MAX] =
{
/* Memory Operations */
"Memory allocation failed :", //CMN_LOG_ALLOC_FAIL,
"Null pointer check failed :", //CMN_LOG_NULL_CHECK_FAIL,
"Out of memory :", //CMN_LOG_OUT_OF_MEMORY,
"Potential memory leak :", //CMN_LOG_MEM_LEAK,
"Buffer overflow detected :", //CMN_LOG_BUFFER_OVERFLOW,

/* File Operations */
"File not found :", //CMN_LOG_FILE_NFOUND,
"Failed to open file :", //CMN_LOG_FILE_OPEN_ERROR,
"Failed to read from file :", //CMN_LOG_FILE_READ_ERROR,
"Failed to write to file :", //CMN_LOG_FILE_WRITE_ERROR,
"Failed to seek file :", //CMN_LOG_FILE_SEEK_ERROR,
"Failed ioctl call to file :", //CMN_LOG_FILE_IOCTL_ERROR,

/* Network Operations */
"Connection Timeout :", //CMN_LOG_CON_TIMEOUT,
"Connection Refused :", //CMN_LOG_CON_REFUSED,
"Data Transmission Error :", //CMN_LOG_DATA_TRANS_ERROR,
"Handshake failed :", //CMN_LOG_HANDSHAKE_FAILED,
"Invalid Certificate :", //CMN_LOG_CERTIFICATE_INVALID,

/* Authentication and Authorization */
"Invalid Credentials :", //CMN_LOG_INVALID_CREDENTIALS,

/* Commonly used logs for printing information */
"Value of :", //CMN_LOG_VALUE_OF,
"Invalid value of :", //CMN_LOG_INVALID_VAL,
"Failed operation :", //CMN_LOG_FAILED_OP,
"Performing operation :", //CMN_LOG_PERFORMING_OP,
"Init done :", //CMN_LOG_INIT_DONE,
"Deinit done :", //CMN_LOG_DEINIT_DONE,
"Start of :", //CMN_LOG_START,
"End of :", //CMN_LOG_END,
"Invalid data in :", //CMN_LOG_INVALID_DATA
"Valid data in :", //CMN_LOG_VALID_DATA
};
25 changes: 13 additions & 12 deletions os/kernel/binary_manager/binary_manager_bootparam.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <stdbool.h>

#include <tinyara/binary_manager.h>
#include <tinyara/common_logs/common_logs.h>

#include "binary_manager.h"

Expand All @@ -48,7 +49,7 @@ static binmgr_bpinfo_t g_bp_info;
void binary_manager_register_bppart(int part_num, int part_size)
{
if (part_num < 0 || part_size != BOOTPARAM_PARTSIZE) {
bmdbg("Invalid BP partition : num %d, size %d\n", part_num, part_size);
bmdbg("%s BP partition : num %d, size %d\n", clog_message_str[CMN_LOG_INVALID_VAL], part_num, part_size);
return;
}

Expand All @@ -62,15 +63,15 @@ bool is_valid_bootparam(char *bootparam)
binmgr_bpdata_t *bp_data = (binmgr_bpdata_t *)bootparam;

if (!bp_data) {
bmdbg("Boot param is NULL\n");
bmdbg("%s bootparam\n", clog_message_str[CMN_LOG_NULL_CHECK_FAIL]);
return false;
} else if (bp_data->format_ver == 0 || bp_data->active_idx >= binary_manager_get_kdata()->part_count) {
bmdbg("Invalid data. ver: %u, active index: %u, addresses: %x, %x\n", bp_data->version, bp_data->active_idx, bp_data->address[0], bp_data->address[1]);
bmdbg("%s ver: %u, active index: %u, addresses: %x, %x\n", clog_message_str[CMN_LOG_INVALID_VAL], bp_data->version, bp_data->active_idx, bp_data->address[0], bp_data->address[1]);
return false;
}

if (bp_data->crc_hash != crc32((uint8_t *)bootparam + CHECKSUM_SIZE, BOOTPARAM_SIZE - CHECKSUM_SIZE)) {
bmdbg("Invalid crc32 value, crc32 %u, ver: %u, active index: %u, addresses: %x, %x\n", bp_data->crc_hash, bp_data->version, bp_data->active_idx, bp_data->address[0], bp_data->address[1]);
bmdbg("%s crc32, crc32 %u, ver: %u, active index: %u, addresses: %x, %x\n", clog_message_str[CMN_LOG_INVALID_VAL], bp_data->crc_hash, bp_data->version, bp_data->active_idx, bp_data->address[0], bp_data->address[1]);
return false;
}

Expand All @@ -83,15 +84,15 @@ static int binary_manager_open_bootparam(void)
char bp_devpath[BINARY_PATH_LEN];

if (g_bp_info.part_num < 0) {
bmdbg("Invalid BP partition Num : %d\n", g_bp_info.part_num);
bmdbg("%s BP partition Num : %d\n", clog_message_str[CMN_LOG_INVALID_VAL], g_bp_info.part_num);
return BINMGR_INVALID_PARAM;
}

/* Open dev to access boot parameters */
snprintf(bp_devpath, BINARY_PATH_LEN, BINMGR_DEVNAME_FMT, g_bp_info.part_num);
fd = open(bp_devpath, O_RDWR, 0666);
if (fd < 0) {
bmdbg("Fail to get a fd for BP, errno %d\n", errno);
bmdbg("%s bp, errno %d\n", clog_message_str[CMN_LOG_FILE_OPEN_ERROR], errno);
return BINMGR_OPERATION_FAIL;
}
return fd;
Expand All @@ -113,7 +114,7 @@ int binary_manager_scan_bootparam(binmgr_bpinfo_t *bp_info)
char *bootparam;

if (bp_info == NULL) {
bmdbg("Invalid input bp_info\n");
bmdbg("%s bpinfo\n", clog_message_str[CMN_LOG_NULL_CHECK_FAIL]);
return BINMGR_INVALID_PARAM;
}

Expand All @@ -125,15 +126,15 @@ int binary_manager_scan_bootparam(binmgr_bpinfo_t *bp_info)
bootparam = (char *)kmm_malloc(BOOTPARAM_SIZE);
if (!bootparam) {
close(fd);
bmdbg("Fail to malloc to read BP\n");
bmdbg("%s BP\n", clog_message_str[CMN_LOG_ALLOC_FAIL]);
return BINMGR_OUT_OF_MEMORY;
}

for (bp_idx = 0; bp_idx < BOOTPARAM_COUNT; bp_idx++) {
bmdbg("Checking BP%d start\n", bp_idx);
ret = lseek(fd, BP_SEEK_OFFSET(bp_idx), SEEK_SET);
if (ret < 0) {
bmdbg("Fail to seek to read BP, offset %d errno %d\n", BP_SEEK_OFFSET(bp_idx), errno);
bmdbg("%s BP, offset %d errno %d\n", clog_message_str[CMN_LOG_FILE_SEEK_ERROR], BP_SEEK_OFFSET(bp_idx), errno);
kmm_free(bootparam);
close(fd);
return BINMGR_OPERATION_FAIL;
Expand All @@ -142,14 +143,14 @@ int binary_manager_scan_bootparam(binmgr_bpinfo_t *bp_info)
/* Read bootparam data */
ret = read(fd, (FAR uint8_t *)bootparam, BOOTPARAM_SIZE);
if (ret != BOOTPARAM_SIZE) {
bmdbg("Fail to read BP, errno %d\n", errno);
bmdbg("%s BP, errno %d\n", clog_message_str[CMN_LOG_FILE_READ_ERROR], errno);
continue;
} else if (!is_valid_bootparam(bootparam)) {
bmdbg("BP%d is invalid\n", bp_idx);
bmdbg("%s BP%d\n", clog_message_str[CMN_LOG_INVALID_DATA], bp_idx);
continue;
}

bmdbg("BP%d is valid\n", bp_idx);
bmdbg("%s BP%d\n", clog_message_str[CMN_LOG_VALID_DATA], bp_idx);

/* Update the latest version and index */
if (latest_ver < ((binmgr_bpdata_t *)bootparam)->version) {
Expand Down