Ran astyle for mbed code format.

pull/14063/head
Dustin Crossman 2021-01-05 13:51:52 -08:00
parent 782b23d626
commit 82c98618cd
3 changed files with 49 additions and 81 deletions

View File

@ -53,15 +53,14 @@ CyReservedRegionBlockDevice *cy_get_ext_wifi_fw_reserved_region_bd()
} }
extern "C" { extern "C" {
extern void cy_ext_wifi_fw_resources_update_handles(void *image_addr, unsigned long image_size, void *clm_blob_addr, unsigned long clm_blob_size); extern void cy_ext_wifi_fw_resources_update_handles(void *image_addr, unsigned long image_size, void *clm_blob_addr, unsigned long clm_blob_size);
} }
int cy_update_ext_wifi_fw_location_and_size(mbed::bd_addr_t image_addr, mbed::bd_size_t image_size, mbed::bd_addr_t clm_blob_addr, mbed::bd_size_t clm_blob_size) int cy_update_ext_wifi_fw_location_and_size(mbed::bd_addr_t image_addr, mbed::bd_size_t image_size, mbed::bd_addr_t clm_blob_addr, mbed::bd_size_t clm_blob_size)
{ {
CyReservedRegionBlockDevice *bd = cy_get_ext_wifi_fw_reserved_region_bd(); CyReservedRegionBlockDevice *bd = cy_get_ext_wifi_fw_reserved_region_bd();
// If the reserved region end is NULL, the block device hasn't been initialized yet, so we can't perform this check // If the reserved region end is NULL, the block device hasn't been initialized yet, so we can't perform this check
if ((bd->reserved_region_end() != 0) && (image_addr + image_size > bd->reserved_region_end() || clm_blob_addr + clm_blob_size > bd->reserved_region_end())) if ((bd->reserved_region_end() != 0) && (image_addr + image_size > bd->reserved_region_end() || clm_blob_addr + clm_blob_size > bd->reserved_region_end())) {
{
// Should not exceed originally computed reserved region size, as this will break anything that was using the rest of external storage // Should not exceed originally computed reserved region size, as this will break anything that was using the rest of external storage
return -1; return -1;
} }

View File

@ -68,9 +68,9 @@ extern "C" {
* Static Function Declarations * Static Function Declarations
******************************************************/ ******************************************************/
uint32_t ext_wifi_fw_host_get_resource_block(whd_driver_t whd_drv, whd_resource_type_t type, uint32_t ext_wifi_fw_host_get_resource_block(whd_driver_t whd_drv, whd_resource_type_t type,
uint32_t blockno, const uint8_t **data, uint32_t *size_out); uint32_t blockno, const uint8_t **data, uint32_t *size_out);
resource_result_t ext_wifi_fw_resource_read(const resource_hnd_t *resource, uint32_t offset, uint32_t maxsize, uint32_t *size, resource_result_t ext_wifi_fw_resource_read(const resource_hnd_t *resource, uint32_t offset, uint32_t maxsize, uint32_t *size,
void *buffer); void *buffer);
extern uint32_t host_platform_resource_size(whd_driver_t whd_drv, whd_resource_type_t resource, uint32_t *size_out); extern uint32_t host_platform_resource_size(whd_driver_t whd_drv, whd_resource_type_t resource, uint32_t *size_out);
extern uint32_t host_get_resource_block_size(whd_driver_t whd_drv, whd_resource_type_t type, uint32_t *size_out); extern uint32_t host_get_resource_block_size(whd_driver_t whd_drv, whd_resource_type_t type, uint32_t *size_out);
@ -119,29 +119,28 @@ void *dynamic_nvram_image = &wifi_nvram_image;
void try_init_external_handles() void try_init_external_handles()
{ {
if (!external_handles_initialized) if (!external_handles_initialized) {
{
#if defined(WLAN_MFG_FIRMWARE) #if defined(WLAN_MFG_FIRMWARE)
wifi_mfg_firmware_image_external = (resource_hnd_t){ wifi_mfg_firmware_image_external = (resource_hnd_t) {
RESOURCE_IN_EXTERNAL_STORAGE, RESOURCE_IN_EXTERNAL_STORAGE,
wifi_mfg_firmware_image.size, wifi_mfg_firmware_image.size,
{ .external_storage_context = (void *) (wifi_mfg_firmware_image.val.mem.data - (uint32_t) CY_WIFI_FW_SECTION_START) } { .external_storage_context = (void *)(wifi_mfg_firmware_image.val.mem.data - (uint32_t) CY_WIFI_FW_SECTION_START) }
}; };
wifi_mfg_firmware_clm_blob_external = (resource_hnd_t){ wifi_mfg_firmware_clm_blob_external = (resource_hnd_t) {
RESOURCE_IN_EXTERNAL_STORAGE, RESOURCE_IN_EXTERNAL_STORAGE,
wifi_mfg_firmware_clm_blob.size, wifi_mfg_firmware_clm_blob.size,
{ .external_storage_context = (void *) (wifi_mfg_firmware_clm_blob.val.mem.data - (uint32_t) CY_WIFI_FW_SECTION_START) } { .external_storage_context = (void *)(wifi_mfg_firmware_clm_blob.val.mem.data - (uint32_t) CY_WIFI_FW_SECTION_START) }
}; };
#else #else
wifi_firmware_image_external = (resource_hnd_t){ wifi_firmware_image_external = (resource_hnd_t) {
RESOURCE_IN_EXTERNAL_STORAGE, RESOURCE_IN_EXTERNAL_STORAGE,
wifi_firmware_image.size, wifi_firmware_image.size,
{ .external_storage_context = (void *) (wifi_firmware_image.val.mem.data - (uint32_t) CY_WIFI_FW_SECTION_START) } { .external_storage_context = (void *)(wifi_firmware_image.val.mem.data - (uint32_t) CY_WIFI_FW_SECTION_START) }
}; };
wifi_firmware_clm_blob_external = (resource_hnd_t){ wifi_firmware_clm_blob_external = (resource_hnd_t) {
RESOURCE_IN_EXTERNAL_STORAGE, RESOURCE_IN_EXTERNAL_STORAGE,
wifi_firmware_clm_blob.size, wifi_firmware_clm_blob.size,
{ .external_storage_context = (void *) (wifi_firmware_clm_blob.val.mem.data - (uint32_t) CY_WIFI_FW_SECTION_START) } { .external_storage_context = (void *)(wifi_firmware_clm_blob.val.mem.data - (uint32_t) CY_WIFI_FW_SECTION_START) }
}; };
#endif /* defined(WLAN_MFG_FIRMWARE) */ #endif /* defined(WLAN_MFG_FIRMWARE) */
external_handles_initialized = true; external_handles_initialized = true;
@ -158,65 +157,53 @@ void cy_ext_wifi_fw_resources_update_handles(void *image_addr, unsigned long ima
} }
resource_result_t ext_wifi_fw_resource_read(const resource_hnd_t *resource, uint32_t offset, uint32_t maxsize, uint32_t *size, resource_result_t ext_wifi_fw_resource_read(const resource_hnd_t *resource, uint32_t offset, uint32_t maxsize, uint32_t *size,
void *buffer) void *buffer)
{ {
if (offset > resource->size) if (offset > resource->size) {
{
return RESOURCE_OFFSET_TOO_BIG; return RESOURCE_OFFSET_TOO_BIG;
} }
*size = MIN(maxsize, resource->size - offset); *size = MIN(maxsize, resource->size - offset);
if (resource->location == RESOURCE_IN_MEMORY) if (resource->location == RESOURCE_IN_MEMORY) {
{
memcpy(buffer, &resource->val.mem.data[offset], *size); memcpy(buffer, &resource->val.mem.data[offset], *size);
} } else if (resource->location == RESOURCE_IN_EXTERNAL_STORAGE) {
else if (resource->location == RESOURCE_IN_EXTERNAL_STORAGE)
{
return platform_read_external_resource(resource, offset, maxsize, size, buffer); return platform_read_external_resource(resource, offset, maxsize, size, buffer);
} }
#ifdef USES_RESOURCE_GENERIC_FILESYSTEM #ifdef USES_RESOURCE_GENERIC_FILESYSTEM
else else {
{
wiced_file_t file_handle; wiced_file_t file_handle;
uint64_t size64; uint64_t size64;
uint64_t maxsize64 = maxsize; uint64_t maxsize64 = maxsize;
if (WICED_SUCCESS != if (WICED_SUCCESS !=
wiced_filesystem_file_open (&resource_fs_handle, &file_handle, resource->val.fs.filename, wiced_filesystem_file_open(&resource_fs_handle, &file_handle, resource->val.fs.filename,
WICED_FILESYSTEM_OPEN_FOR_READ) ) WICED_FILESYSTEM_OPEN_FOR_READ)) {
{
return RESOURCE_FILE_OPEN_FAIL; return RESOURCE_FILE_OPEN_FAIL;
} }
if (WICED_SUCCESS != wiced_filesystem_file_seek (&file_handle, (offset + resource->val.fs.offset), SEEK_SET) ) if (WICED_SUCCESS != wiced_filesystem_file_seek(&file_handle, (offset + resource->val.fs.offset), SEEK_SET)) {
{
return RESOURCE_FILE_SEEK_FAIL; return RESOURCE_FILE_SEEK_FAIL;
} }
if (WICED_SUCCESS != wiced_filesystem_file_read (&file_handle, buffer, maxsize64, &size64) ) if (WICED_SUCCESS != wiced_filesystem_file_read(&file_handle, buffer, maxsize64, &size64)) {
{ wiced_filesystem_file_close(&file_handle);
wiced_filesystem_file_close (&file_handle);
return RESOURCE_FILE_READ_FAIL; return RESOURCE_FILE_READ_FAIL;
} }
*size = (uint32_t)size64; *size = (uint32_t)size64;
wiced_filesystem_file_close (&file_handle); wiced_filesystem_file_close(&file_handle);
} }
#elif USES_RESOURCE_FILESYSTEM #elif USES_RESOURCE_FILESYSTEM
else else {
{
wicedfs_file_t file_hnd; wicedfs_file_t file_hnd;
if (0 != wicedfs_fopen(&resource_fs_handle, &file_hnd, resource->val.fs.filename) ) if (0 != wicedfs_fopen(&resource_fs_handle, &file_hnd, resource->val.fs.filename)) {
{
return RESOURCE_FILE_OPEN_FAIL; return RESOURCE_FILE_OPEN_FAIL;
} }
if (0 != wicedfs_fseek(&file_hnd, (long)(offset + resource->val.fs.offset), SEEK_SET) ) if (0 != wicedfs_fseek(&file_hnd, (long)(offset + resource->val.fs.offset), SEEK_SET)) {
{
wicedfs_fclose(&file_hnd); wicedfs_fclose(&file_hnd);
return RESOURCE_FILE_SEEK_FAIL; return RESOURCE_FILE_SEEK_FAIL;
} }
if (*size != wicedfs_fread(buffer, 1, *size, &file_hnd) ) if (*size != wicedfs_fread(buffer, 1, *size, &file_hnd)) {
{
wicedfs_fclose(&file_hnd); wicedfs_fclose(&file_hnd);
return RESOURCE_FILE_READ_FAIL; return RESOURCE_FILE_READ_FAIL;
} }
@ -228,7 +215,7 @@ resource_result_t ext_wifi_fw_resource_read(const resource_hnd_t *resource, uint
} }
uint32_t ext_wifi_fw_host_get_resource_block(whd_driver_t whd_drv, whd_resource_type_t type, uint32_t ext_wifi_fw_host_get_resource_block(whd_driver_t whd_drv, whd_resource_type_t type,
uint32_t blockno, const uint8_t **data, uint32_t *size_out) uint32_t blockno, const uint8_t **data, uint32_t *size_out)
{ {
uint32_t resource_size; uint32_t resource_size;
uint32_t block_size; uint32_t block_size;
@ -244,17 +231,14 @@ uint32_t ext_wifi_fw_host_get_resource_block(whd_driver_t whd_drv, whd_resource_
memset(whd_r_buffer, 0, block_size); memset(whd_r_buffer, 0, block_size);
read_pos = blockno * block_size; read_pos = blockno * block_size;
if (blockno >= block_count) if (blockno >= block_count) {
{
return WHD_BADARG; return WHD_BADARG;
} }
if (type == WHD_RESOURCE_WLAN_FIRMWARE) if (type == WHD_RESOURCE_WLAN_FIRMWARE) {
{ result = ext_wifi_fw_resource_read((const resource_hnd_t *)&WIFI_FIRMWARE_IMAGE, read_pos, block_size, size_out,
result = ext_wifi_fw_resource_read( (const resource_hnd_t *)&WIFI_FIRMWARE_IMAGE, read_pos, block_size, size_out, whd_r_buffer);
whd_r_buffer ); if (result != WHD_SUCCESS) {
if (result != WHD_SUCCESS)
{
return result; return result;
} }
*data = (uint8_t *)&whd_r_buffer; *data = (uint8_t *)&whd_r_buffer;
@ -267,26 +251,18 @@ uint32_t ext_wifi_fw_host_get_resource_block(whd_driver_t whd_drv, whd_resource_
* For sending the entire buffer in single block set size out as following * For sending the entire buffer in single block set size out as following
* *size_out = (uint32_t)resource_get_size(&wifi_firmware_image); * *size_out = (uint32_t)resource_get_size(&wifi_firmware_image);
*/ */
} } else if (type == WHD_RESOURCE_WLAN_NVRAM) {
else if (type == WHD_RESOURCE_WLAN_NVRAM) if (NVRAM_SIZE - read_pos > block_size) {
{
if (NVRAM_SIZE - read_pos > block_size)
{
*size_out = block_size; *size_out = block_size;
} } else {
else
{
*size_out = NVRAM_SIZE - read_pos; *size_out = NVRAM_SIZE - read_pos;
} }
*data = ( (uint8_t *)NVRAM_IMAGE_VARIABLE ) + read_pos; *data = ((uint8_t *)NVRAM_IMAGE_VARIABLE) + read_pos;
} } else {
else result = ext_wifi_fw_resource_read((const resource_hnd_t *)&WIFI_FIRMWARE_CLM_BLOB, read_pos, block_size,
{ size_out,
result = ext_wifi_fw_resource_read( (const resource_hnd_t *)&WIFI_FIRMWARE_CLM_BLOB, read_pos, block_size, whd_r_buffer);
size_out, if (result != WHD_SUCCESS) {
whd_r_buffer );
if (result != WHD_SUCCESS)
{
return result; return result;
} }
*data = (uint8_t *)&whd_r_buffer; *data = (uint8_t *)&whd_r_buffer;
@ -305,8 +281,7 @@ uint32_t ext_wifi_fw_host_get_resource_block(whd_driver_t whd_drv, whd_resource_
return WHD_SUCCESS; return WHD_SUCCESS;
} }
whd_resource_source_t cy_ext_wifi_fw_resource_ops = whd_resource_source_t cy_ext_wifi_fw_resource_ops = {
{
.whd_resource_size = host_platform_resource_size, .whd_resource_size = host_platform_resource_size,
.whd_get_resource_block_size = host_get_resource_block_size, .whd_get_resource_block_size = host_get_resource_block_size,
.whd_get_resource_no_of_blocks = host_get_resource_no_of_blocks, .whd_get_resource_no_of_blocks = host_get_resource_no_of_blocks,

View File

@ -35,16 +35,12 @@ CyReservedRegionBlockDevice::CyReservedRegionBlockDevice(BlockDevice *underlying
int CyReservedRegionBlockDevice::init() int CyReservedRegionBlockDevice::init()
{ {
int status = _underlying_bd->init(); int status = _underlying_bd->init();
if (status == BD_ERROR_OK) if (status == BD_ERROR_OK) {
{
// Round up to start usable region on an erase boundary // Round up to start usable region on an erase boundary
// May need to wait until after init() to determine erase size (e.g. QSPI) // May need to wait until after init() to determine erase size (e.g. QSPI)
if (_reserved_region_size % get_erase_size() != 0) if (_reserved_region_size % get_erase_size() != 0) {
{
_reserved_region_end = _reserved_region_size + get_erase_size() - (_reserved_region_size % get_erase_size()); _reserved_region_end = _reserved_region_size + get_erase_size() - (_reserved_region_size % get_erase_size());
} } else {
else
{
_reserved_region_end = _reserved_region_size; _reserved_region_end = _reserved_region_size;
} }
} }
@ -54,8 +50,7 @@ int CyReservedRegionBlockDevice::init()
int CyReservedRegionBlockDevice::deinit() int CyReservedRegionBlockDevice::deinit()
{ {
int status = _underlying_bd->deinit(); int status = _underlying_bd->deinit();
if (status == BD_ERROR_OK) if (status == BD_ERROR_OK) {
{
_reserved_region_end = 0; _reserved_region_end = 0;
} }
return status; return status;
@ -113,8 +108,7 @@ const char *CyReservedRegionBlockDevice::get_type() const
int CyReservedRegionBlockDevice::reserved_read(void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size) int CyReservedRegionBlockDevice::reserved_read(void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size)
{ {
if (addr + size > _reserved_region_end || addr % get_read_size() != 0 || size % get_read_size() != 0) if (addr + size > _reserved_region_end || addr % get_read_size() != 0 || size % get_read_size() != 0) {
{
return BD_ERROR_DEVICE_ERROR; return BD_ERROR_DEVICE_ERROR;
} }