Fix style problems in safety-memory.c
This commit is contained in:
parent
5ddae7efee
commit
ba8072c21d
@ -99,7 +99,8 @@ static enum safety_memory_state safety_memory_get_header(struct safety_memory_he
|
|||||||
res = 0;
|
res = 0;
|
||||||
if (header->boot_status_offset < wordsize_of(struct safety_memory_header))
|
if (header->boot_status_offset < wordsize_of(struct safety_memory_header))
|
||||||
res++;
|
res++;
|
||||||
if (header->config_overrides_offset < header->boot_status_offset + wordsize_of(struct safety_memory_boot_status))
|
if (header->config_overrides_offset < header->boot_status_offset +
|
||||||
|
wordsize_of(struct safety_memory_boot_status))
|
||||||
res++;
|
res++;
|
||||||
if (header->config_overrides_len > SAFETY_MEMORY_CONFIG_OVERRIDE_COUNT)
|
if (header->config_overrides_len > SAFETY_MEMORY_CONFIG_OVERRIDE_COUNT)
|
||||||
res++;
|
res++;
|
||||||
@ -107,7 +108,8 @@ static enum safety_memory_state safety_memory_get_header(struct safety_memory_he
|
|||||||
res++;
|
res++;
|
||||||
if (header->err_memory_offset < header->firmware_update_filename + (SAFETY_MEMORY_UPDATE_FILENAME_MAXSIZE / 4))
|
if (header->err_memory_offset < header->firmware_update_filename + (SAFETY_MEMORY_UPDATE_FILENAME_MAXSIZE / 4))
|
||||||
res++;
|
res++;
|
||||||
if (header->err_memory_end >= backup_ram_get_size_in_words() || header->err_memory_end < header->err_memory_offset)
|
if (header->err_memory_end >= backup_ram_get_size_in_words() ||
|
||||||
|
header->err_memory_end < header->err_memory_offset)
|
||||||
res++;
|
res++;
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
@ -148,7 +150,7 @@ static void safety_memory_write_new_header(void)
|
|||||||
safety_memory_write_and_patch_header(&header);
|
safety_memory_write_and_patch_header(&header);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int safety_memory_check_crc()
|
static int safety_memory_check_crc(void)
|
||||||
{
|
{
|
||||||
struct safety_memory_header header;
|
struct safety_memory_header header;
|
||||||
enum safety_memory_state state = safety_memory_get_header(&header);
|
enum safety_memory_state state = safety_memory_get_header(&header);
|
||||||
@ -181,7 +183,7 @@ static int safety_memory_check_crc()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int safety_memory_gen_crc()
|
static int safety_memory_gen_crc(void)
|
||||||
{
|
{
|
||||||
struct safety_memory_header header;
|
struct safety_memory_header header;
|
||||||
uint32_t word_addr;
|
uint32_t word_addr;
|
||||||
@ -268,9 +270,8 @@ int safety_memory_get_boot_status(struct safety_memory_boot_status *status)
|
|||||||
if (!status)
|
if (!status)
|
||||||
return -1001;
|
return -1001;
|
||||||
|
|
||||||
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY) {
|
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY)
|
||||||
return -2000;
|
return -2000;
|
||||||
}
|
|
||||||
|
|
||||||
if (safety_memory_check_crc())
|
if (safety_memory_check_crc())
|
||||||
return -2001;
|
return -2001;
|
||||||
@ -289,9 +290,8 @@ int safety_memory_set_boot_status(const struct safety_memory_boot_status *status
|
|||||||
if (!status)
|
if (!status)
|
||||||
return -1001;
|
return -1001;
|
||||||
|
|
||||||
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY) {
|
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY)
|
||||||
return -2000;
|
return -2000;
|
||||||
}
|
|
||||||
|
|
||||||
if (safety_memory_check_crc())
|
if (safety_memory_check_crc())
|
||||||
return -2001;
|
return -2001;
|
||||||
@ -304,7 +304,7 @@ int safety_memory_set_boot_status(const struct safety_memory_boot_status *status
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int safety_memory_check_error_entries()
|
static int safety_memory_check_error_entries(void)
|
||||||
{
|
{
|
||||||
struct safety_memory_header header;
|
struct safety_memory_header header;
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
@ -312,9 +312,8 @@ static int safety_memory_check_error_entries()
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY) {
|
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY)
|
||||||
return -2000;
|
return -2000;
|
||||||
}
|
|
||||||
|
|
||||||
for (addr = header.err_memory_offset; addr < header.err_memory_end; addr++) {
|
for (addr = header.err_memory_offset; addr < header.err_memory_end; addr++) {
|
||||||
res = backup_ram_get_data(addr, &data, 1UL);
|
res = backup_ram_get_data(addr, &data, 1UL);
|
||||||
@ -340,9 +339,8 @@ int safety_memory_get_error_entry_count(uint32_t *count)
|
|||||||
if (!count)
|
if (!count)
|
||||||
return -1001;
|
return -1001;
|
||||||
|
|
||||||
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY) {
|
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY)
|
||||||
return -2000;
|
return -2000;
|
||||||
}
|
|
||||||
|
|
||||||
*count = header.err_memory_end - header.err_memory_offset;
|
*count = header.err_memory_end - header.err_memory_offset;
|
||||||
|
|
||||||
@ -354,9 +352,8 @@ int safety_memory_check(void)
|
|||||||
int res;
|
int res;
|
||||||
|
|
||||||
res = safety_memory_check_crc();
|
res = safety_memory_check_crc();
|
||||||
if (!res) {
|
if (!res)
|
||||||
res |= safety_memory_check_error_entries();
|
res |= safety_memory_check_error_entries();
|
||||||
}
|
|
||||||
|
|
||||||
return -!!res;
|
return -!!res;
|
||||||
}
|
}
|
||||||
@ -372,9 +369,8 @@ int safety_memory_get_error_entry(uint32_t idx, struct error_memory_entry *entry
|
|||||||
if (!entry)
|
if (!entry)
|
||||||
return -1001;
|
return -1001;
|
||||||
|
|
||||||
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY) {
|
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY)
|
||||||
return -2000;
|
return -2000;
|
||||||
}
|
|
||||||
|
|
||||||
err_mem_count = header.err_memory_end - header.err_memory_offset;
|
err_mem_count = header.err_memory_end - header.err_memory_offset;
|
||||||
if (idx < err_mem_count && err_mem_count > 0) {
|
if (idx < err_mem_count && err_mem_count > 0) {
|
||||||
@ -410,9 +406,8 @@ int safety_memory_insert_error_entry(struct error_memory_entry *entry)
|
|||||||
|
|
||||||
input_data = error_memory_entry_to_word(entry);
|
input_data = error_memory_entry_to_word(entry);
|
||||||
|
|
||||||
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY) {
|
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY)
|
||||||
return -2000;
|
return -2000;
|
||||||
}
|
|
||||||
|
|
||||||
if (entry->type == SAFETY_MEMORY_ERR_ENTRY_NOP) {
|
if (entry->type == SAFETY_MEMORY_ERR_ENTRY_NOP) {
|
||||||
/* Append to end */
|
/* Append to end */
|
||||||
@ -510,9 +505,8 @@ int safety_memory_insert_config_override(struct config_override *config_override
|
|||||||
int res;
|
int res;
|
||||||
int ret = -3;
|
int ret = -3;
|
||||||
|
|
||||||
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY) {
|
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY)
|
||||||
return -2000;
|
return -2000;
|
||||||
}
|
|
||||||
|
|
||||||
if (header.config_overrides_len == 0)
|
if (header.config_overrides_len == 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -550,9 +544,8 @@ int safety_memory_get_config_override_count(uint32_t *count)
|
|||||||
|
|
||||||
*count = 0UL;
|
*count = 0UL;
|
||||||
|
|
||||||
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY) {
|
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY)
|
||||||
return -2000;
|
return -2000;
|
||||||
}
|
|
||||||
|
|
||||||
if (header.config_overrides_len == 0)
|
if (header.config_overrides_len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
@ -582,18 +575,15 @@ int safety_memory_get_config_override(uint32_t idx, struct config_override *conf
|
|||||||
if (!config_override)
|
if (!config_override)
|
||||||
return -1002;
|
return -1002;
|
||||||
|
|
||||||
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY) {
|
if (safety_memory_get_header(&header) != SAFETY_MEMORY_INIT_VALID_MEMORY)
|
||||||
return -2000;
|
return -2000;
|
||||||
}
|
|
||||||
|
|
||||||
if (idx >= header.config_overrides_len) {
|
if (idx >= header.config_overrides_len)
|
||||||
return -1001;
|
return -1001;
|
||||||
}
|
|
||||||
|
|
||||||
res = backup_ram_get_data(header.config_overrides_offset + idx, &data, 1UL);
|
res = backup_ram_get_data(header.config_overrides_offset + idx, &data, 1UL);
|
||||||
if (res) {
|
if (res)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
switch (data & 0xFF) {
|
switch (data & 0xFF) {
|
||||||
case 0xA2:
|
case 0xA2:
|
||||||
@ -649,8 +639,8 @@ int safety_memory_get_update_filename(char *filename, size_t *outlen)
|
|||||||
{
|
{
|
||||||
struct safety_memory_header header;
|
struct safety_memory_header header;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
volatile char *ptr;
|
|
||||||
size_t len = 0u;
|
size_t len = 0u;
|
||||||
|
volatile char *ptr;
|
||||||
|
|
||||||
/* If filename and outlen are both NULL, we don't do anything */
|
/* If filename and outlen are both NULL, we don't do anything */
|
||||||
if (!filename && !outlen)
|
if (!filename && !outlen)
|
||||||
@ -696,9 +686,9 @@ int safety_memory_set_update_filename(const char *filename)
|
|||||||
ram_ptr = backup_ram_get_base_ptr();
|
ram_ptr = backup_ram_get_base_ptr();
|
||||||
ram_ptr += header.firmware_update_filename * 4;
|
ram_ptr += header.firmware_update_filename * 4;
|
||||||
|
|
||||||
for (i = 0u; i < len; i++) {
|
for (i = 0u; i < len; i++)
|
||||||
ram_ptr[i] = filename[i];
|
ram_ptr[i] = filename[i];
|
||||||
}
|
|
||||||
ram_ptr[i] = 0;
|
ram_ptr[i] = 0;
|
||||||
|
|
||||||
ret = safety_memory_gen_crc();
|
ret = safety_memory_gen_crc();
|
||||||
|
Loading…
Reference in New Issue
Block a user