diff options
-rw-r--r-- | module/sds/src/mod_sds.c | 138 | ||||
-rw-r--r-- | product/n1sdp/scp_ramfw/config_sds.c | 2 | ||||
-rw-r--r-- | product/rdn1e1/scp_ramfw/config_sds.c | 2 | ||||
-rw-r--r-- | product/sgi575/scp_ramfw/config_sds.c | 2 | ||||
-rw-r--r-- | product/sgm775/scp_romfw/config_sds.c | 2 |
5 files changed, 73 insertions, 73 deletions
diff --git a/module/sds/src/mod_sds.c b/module/sds/src/mod_sds.c index 95e3b041..b06f1fdc 100644 --- a/module/sds/src/mod_sds.c +++ b/module/sds/src/mod_sds.c @@ -100,7 +100,7 @@ struct sds_ctx { const struct mod_sds_config *module_config; /* Pointer to the base of the SDS Memory Region. */ - uint8_t *mem_base; + volatile char *mem_base; /* Size of the SDS Memory Region in bytes. */ unsigned int mem_size; @@ -109,10 +109,10 @@ struct sds_ctx { unsigned int mem_free; /* Pointer to the next free memory address in the SDS Memory Region. */ - uint8_t *mem_next_free; + volatile char *mem_next_free; /* Pointer to the Region Descriptor structure at the memory region base. */ - struct region_descriptor *region_desc; + volatile struct region_descriptor *region_desc; }; /* Module context */ @@ -126,7 +126,7 @@ static struct sds_ctx ctx; * Perform some tests to determine whether any of the fields within a Structure * Header contain obviously invalid data. */ -static bool header_is_valid(struct structure_header *header) +static bool header_is_valid(volatile struct structure_header *header) { if (header->id == 0) return false; /* Zero is not a valid identifier */ @@ -162,7 +162,7 @@ static bool validate_structure_access(uint32_t structure_size, uint32_t offset, /* * Search the SDS Memory Region for a given structure ID and return a * copy of the Structure Header that holds its information. Optionally, a - * uint8_t pointer pointer may be provided to retrieve a pointer to the base + * char pointer pointer may be provided to retrieve a pointer to the base * address of the structure content. * * The validity of the header is checked before its contents are returned. These @@ -178,37 +178,38 @@ static bool validate_structure_access(uint32_t structure_size, uint32_t offset, */ static int get_structure_info(uint32_t structure_id, struct structure_header *header, - uint8_t **structure_base) + volatile char **structure_base) { - unsigned int struct_idx; - struct structure_header current_header; - uint32_t offset; - - offset = sizeof(struct region_descriptor); - - /* Iterate over structure headers to find one with a matching ID */ - for (struct_idx = 0; struct_idx < ctx.region_desc->structure_count; - struct_idx++) { - current_header = *(struct structure_header *)(ctx.mem_base + offset); - if (!header_is_valid(¤t_header)) - return FWK_E_DATA; - - if (current_header.id == structure_id) { - if (structure_base != NULL) - *structure_base = ((uint8_t *)(ctx.mem_base + offset)) + - sizeof(struct structure_header); - - *header = current_header; - return FWK_SUCCESS; - } - - offset += current_header.size; - offset += sizeof(struct structure_header); - if (offset >= ctx.mem_size) - return FWK_E_RANGE; - } - - return FWK_E_PARAM; + unsigned int struct_idx; + struct structure_header current_header; + uint32_t offset; + + offset = sizeof(struct region_descriptor); + + /* Iterate over structure headers to find one with a matching ID */ + for (struct_idx = 0; struct_idx < ctx.region_desc->structure_count; + struct_idx++) { + current_header = *(struct structure_header *)( + ctx.mem_base + offset); + if (!header_is_valid(¤t_header)) + return FWK_E_DATA; + + if (current_header.id == structure_id) { + if (structure_base != NULL) + *structure_base = ((volatile char *)(ctx.mem_base + offset)) + + sizeof(struct structure_header); + + *header = current_header; + return FWK_SUCCESS; + } + + offset += current_header.size; + offset += sizeof(struct structure_header); + if (offset >= ctx.mem_size) + return FWK_E_RANGE; + } + + return FWK_E_PARAM; } /* @@ -226,12 +227,14 @@ static bool structure_exists(uint32_t structure_id) static int struct_alloc(uint32_t structure_id, size_t size) { - struct structure_header *header = NULL; + volatile struct structure_header *header = NULL; unsigned int padded_size; - unsigned int status; + int status = FWK_SUCCESS; - if (size < MIN_STRUCT_SIZE) - return FWK_E_PARAM; + if (size < MIN_STRUCT_SIZE) { + status = FWK_E_PARAM; + goto exit; + } padded_size = FWK_ALIGN_NEXT(size, MIN_STRUCT_ALIGNMENT); @@ -246,7 +249,7 @@ static int struct_alloc(uint32_t structure_id, size_t size) } /* Create the Structure Header */ - header = (struct structure_header *)ctx.mem_next_free; + header = (volatile struct structure_header *)ctx.mem_next_free; header->id = structure_id; header->size = padded_size; header->valid = false; @@ -254,15 +257,14 @@ static int struct_alloc(uint32_t structure_id, size_t size) ctx.mem_free -= sizeof(*header); /* Zero the memory reserved for the structure, avoiding the header */ - memset(ctx.mem_next_free, 0, padded_size); + for (unsigned int i = 0; i < padded_size; i++) + ctx.mem_next_free[i] = 0u; ctx.mem_next_free += padded_size; ctx.mem_free -= padded_size; /* Increment the structure count within the region descriptor */ ctx.region_desc->structure_count++; - status = FWK_SUCCESS; - exit: return status; } @@ -300,7 +302,7 @@ static int reinitialize_memory_region(void) for (struct_idx = 0; struct_idx < ctx.region_desc->structure_count; struct_idx++) { - header = *(struct structure_header *)(ctx.mem_base + mem_used); + header = *(volatile struct structure_header *)(ctx.mem_base + mem_used); if (!header_is_valid(&header)) return FWK_E_DATA; /* Unexpected invalid header */ @@ -367,7 +369,7 @@ static int create_memory_region(void) * directly. */ ctx.mem_next_free = ctx.mem_base + sizeof(struct region_descriptor); - assert(((uintptr_t)ctx.mem_next_free % + fwk_assert(((uintptr_t)ctx.mem_next_free % MIN_STRUCT_ALIGNMENT) == 0); return FWK_SUCCESS; @@ -377,35 +379,33 @@ static int struct_write(uint32_t structure_id, unsigned int offset, const void *data, size_t size) { int status; - uint8_t *structure_base; + volatile char *structure_base; struct structure_header header; - assert(data != NULL); - assert(size != 0); + fwk_assert(data != NULL); + fwk_assert(size != 0); /* Look up the Structure Header by its identifier */ status = get_structure_info(structure_id, &header, &structure_base); if (status != FWK_SUCCESS) return status; - /* - * Perform sanity checks on the field location and data size before invoking - * memcpy. - */ status = validate_structure_access(header.size, offset, size); if (status != FWK_SUCCESS) return status; - memcpy(structure_base + offset, data, size); + for (unsigned int i = 0; i < size; i++) + structure_base[offset + i] = ((const char*)data)[i]; + return FWK_SUCCESS; } static int struct_finalize(uint32_t structure_id) { int status; - uint8_t *structure_base; + volatile char *structure_base; struct structure_header header; - struct structure_header *header_mem; + volatile struct structure_header *header_mem; /* Check that the structure being finalized exists */ status = get_structure_info(structure_id, &header, &structure_base); @@ -413,7 +413,8 @@ static int struct_finalize(uint32_t structure_id) return status; /* Update the valid flag of the header within the SDS Memory Region */ - header_mem = (struct structure_header *)(structure_base - sizeof(header)); + header_mem = (volatile struct structure_header *)( + structure_base - sizeof(header)); header_mem->valid = true; return FWK_SUCCESS; @@ -498,7 +499,7 @@ static int sds_struct_read(uint32_t structure_id, unsigned int offset, void *data, size_t size) { int status; - uint8_t *structure_base; + volatile char *structure_base; struct structure_header header; status = fwk_module_check_call(fwk_module_id_sds); @@ -516,15 +517,13 @@ static int sds_struct_read(uint32_t structure_id, unsigned int offset, if (status != FWK_SUCCESS) return status; - /* - * Perform sanity checks on the field location and data size before invoking - * memcpy. - */ - status = validate_structure_access(header.size, offset, size); - if (status != FWK_SUCCESS) + status = validate_structure_access(header.size, offset, size); + if (status != FWK_SUCCESS) return status; - memcpy(data, structure_base + offset, size); + for (unsigned int i = 0; i < size; i++) + ((char*)data)[i] = structure_base[offset + i]; + return FWK_SUCCESS; } @@ -557,7 +556,7 @@ static int sds_init(fwk_id_t module_id, unsigned int element_count, ctx.module_config = data; - assert((MIN_STRUCT_ALIGNMENT % MIN_FIELD_ALIGNMENT) == 0); + fwk_assert((MIN_STRUCT_ALIGNMENT % MIN_FIELD_ALIGNMENT) == 0); if (ctx.module_config->region_base_address == 0) return FWK_E_PARAM; @@ -565,9 +564,9 @@ static int sds_init(fwk_id_t module_id, unsigned int element_count, MIN_STRUCT_ALIGNMENT) > 0) return FWK_E_PARAM; - ctx.mem_base = (uint8_t *)ctx.module_config->region_base_address; + ctx.mem_base = (volatile char *)ctx.module_config->region_base_address; ctx.mem_size = ctx.module_config->region_size; - ctx.region_desc = (struct region_descriptor *)ctx.mem_base; + ctx.region_desc = (volatile struct region_descriptor *)ctx.mem_base; return FWK_SUCCESS; } @@ -613,8 +612,9 @@ static int sds_process_notification( { struct clock_notification_params *params; - assert(fwk_id_is_equal(event->id, mod_clock_notification_id_state_changed)); - assert(fwk_id_is_type(event->target_id, FWK_ID_TYPE_MODULE)); + fwk_assert(fwk_id_is_equal(event->id, + mod_clock_notification_id_state_changed)); + fwk_assert(fwk_id_is_type(event->target_id, FWK_ID_TYPE_MODULE)); params = (struct clock_notification_params *)event->params; if (params->new_state != MOD_CLOCK_STATE_RUNNING) diff --git a/product/n1sdp/scp_ramfw/config_sds.c b/product/n1sdp/scp_ramfw/config_sds.c index 1ea4507f..765043c3 100644 --- a/product/n1sdp/scp_ramfw/config_sds.c +++ b/product/n1sdp/scp_ramfw/config_sds.c @@ -66,7 +66,7 @@ static struct fwk_element sds_element_table[] = { .finalize = true, }), }, -#ifdef BUILD_MODE_DEBUG +#ifdef BUILD_HAS_MOD_TEST { .name = "Boot Counters", .data = &((struct mod_sds_structure_desc) { diff --git a/product/rdn1e1/scp_ramfw/config_sds.c b/product/rdn1e1/scp_ramfw/config_sds.c index 3590fe99..db795fba 100644 --- a/product/rdn1e1/scp_ramfw/config_sds.c +++ b/product/rdn1e1/scp_ramfw/config_sds.c @@ -68,7 +68,7 @@ static struct fwk_element sds_element_table[] = { .finalize = true, }), }, -#ifdef BUILD_MODE_DEBUG +#ifdef BUILD_HAS_MOD_TEST { .name = "Boot Counters", .data = &((struct mod_sds_structure_desc) { diff --git a/product/sgi575/scp_ramfw/config_sds.c b/product/sgi575/scp_ramfw/config_sds.c index e628e347..f6d0152a 100644 --- a/product/sgi575/scp_ramfw/config_sds.c +++ b/product/sgi575/scp_ramfw/config_sds.c @@ -79,7 +79,7 @@ static struct fwk_element sds_element_table[] = { .finalize = true, }), }, -#ifdef BUILD_MODE_DEBUG +#ifdef BUILD_HAS_MOD_TEST { .name = "Boot Counters", .data = &((struct mod_sds_structure_desc) { diff --git a/product/sgm775/scp_romfw/config_sds.c b/product/sgm775/scp_romfw/config_sds.c index b55091f4..6d7fd53e 100644 --- a/product/sgm775/scp_romfw/config_sds.c +++ b/product/sgm775/scp_romfw/config_sds.c @@ -81,7 +81,7 @@ static const struct fwk_element sds_element_table[] = { .finalize = true, }), }, -#ifdef BUILD_MODE_DEBUG +#ifdef BUILD_HAS_MOD_TEST { .name = "Boot Counters", .data = &((struct mod_sds_structure_desc) { |