mirror of https://github.com/ARMmbed/mbed-os.git
Portenta removed resource_imp folder
parent
2852fe41ae
commit
b34a436d25
|
@ -1,320 +0,0 @@
|
|||
/*
|
||||
* Copyright 2020 Cypress Semiconductor Corporation
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
/** @file
|
||||
* Defines WHD resource functions for BCM943340WCD1 platform
|
||||
*/
|
||||
#include "resources.h"
|
||||
#include "wifi_nvram_image.h"
|
||||
#include "whd_resource_api.h"
|
||||
#include "whd_debug.h"
|
||||
#include "whd.h"
|
||||
|
||||
/******************************************************
|
||||
* Macros
|
||||
******************************************************/
|
||||
#define BLOCK_BUFFER_SIZE (1024)
|
||||
|
||||
/******************************************************
|
||||
* Constants
|
||||
******************************************************/
|
||||
|
||||
#if defined(WHD_DYNAMIC_NVRAM)
|
||||
#define NVRAM_SIZE dynamic_nvram_size
|
||||
#define NVRAM_IMAGE_VARIABLE dynamic_nvram_image
|
||||
#else
|
||||
#define NVRAM_SIZE sizeof(wifi_nvram_image)
|
||||
#define NVRAM_IMAGE_VARIABLE wifi_nvram_image
|
||||
#endif
|
||||
|
||||
/******************************************************
|
||||
* Enumerations
|
||||
******************************************************/
|
||||
|
||||
/******************************************************
|
||||
* Type Definitions
|
||||
******************************************************/
|
||||
|
||||
/******************************************************
|
||||
* Structures
|
||||
******************************************************/
|
||||
|
||||
/******************************************************
|
||||
* Static Function Declarations
|
||||
******************************************************/
|
||||
uint32_t host_platform_resource_size(whd_driver_t whd_drv, whd_resource_type_t resource, uint32_t *size_out);
|
||||
uint32_t 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 host_get_resource_no_of_blocks(whd_driver_t whd_drv, whd_resource_type_t type, uint32_t *block_count);
|
||||
uint32_t host_get_resource_block_size(whd_driver_t whd_drv, whd_resource_type_t type, uint32_t *size_out);
|
||||
resource_result_t resource_read(const resource_hnd_t *resource, uint32_t offset, uint32_t maxsize, uint32_t *size,
|
||||
void *buffer);
|
||||
|
||||
/******************************************************
|
||||
* Variable Definitions
|
||||
******************************************************/
|
||||
|
||||
#ifdef WLAN_MFG_FIRMWARE
|
||||
extern const resource_hnd_t wifi_mfg_firmware_image;
|
||||
extern const resource_hnd_t wifi_mfg_firmware_clm_blob;
|
||||
#else
|
||||
extern const resource_hnd_t wifi_firmware_image;
|
||||
extern const resource_hnd_t wifi_firmware_clm_blob;
|
||||
#endif
|
||||
|
||||
unsigned char r_buffer[BLOCK_BUFFER_SIZE];
|
||||
|
||||
#if defined(WHD_DYNAMIC_NVRAM)
|
||||
uint32_t dynamic_nvram_size = sizeof(wifi_nvram_image);
|
||||
void *dynamic_nvram_image = &wifi_nvram_image;
|
||||
#endif
|
||||
|
||||
/******************************************************
|
||||
* Function Definitions
|
||||
******************************************************/
|
||||
|
||||
resource_result_t resource_read(const resource_hnd_t *resource, uint32_t offset, uint32_t maxsize, uint32_t *size,
|
||||
void *buffer)
|
||||
{
|
||||
if (offset > resource->size)
|
||||
{
|
||||
return RESOURCE_OFFSET_TOO_BIG;
|
||||
}
|
||||
|
||||
*size = MIN(maxsize, resource->size - offset);
|
||||
|
||||
if (resource->location == RESOURCE_IN_MEMORY)
|
||||
{
|
||||
memcpy(buffer, &resource->val.mem.data[offset], *size);
|
||||
}
|
||||
#ifdef USES_RESOURCES_IN_EXTERNAL_STORAGE
|
||||
else if (resource->location == RESOURCE_IN_EXTERNAL_STORAGE)
|
||||
{
|
||||
return platform_read_external_resource(resource, offset, maxsize, size, buffer);
|
||||
}
|
||||
#endif
|
||||
#ifdef USES_RESOURCE_GENERIC_FILESYSTEM
|
||||
else
|
||||
{
|
||||
wiced_file_t file_handle;
|
||||
uint64_t size64;
|
||||
uint64_t maxsize64 = maxsize;
|
||||
if (WICED_SUCCESS !=
|
||||
wiced_filesystem_file_open (&resource_fs_handle, &file_handle, resource->val.fs.filename,
|
||||
WICED_FILESYSTEM_OPEN_FOR_READ) )
|
||||
{
|
||||
return RESOURCE_FILE_OPEN_FAIL;
|
||||
}
|
||||
if (WICED_SUCCESS != wiced_filesystem_file_seek (&file_handle, (offset + resource->val.fs.offset), SEEK_SET) )
|
||||
{
|
||||
return RESOURCE_FILE_SEEK_FAIL;
|
||||
}
|
||||
if (WICED_SUCCESS != wiced_filesystem_file_read (&file_handle, buffer, maxsize64, &size64) )
|
||||
{
|
||||
wiced_filesystem_file_close (&file_handle);
|
||||
return RESOURCE_FILE_READ_FAIL;
|
||||
}
|
||||
*size = (uint32_t)size64;
|
||||
wiced_filesystem_file_close (&file_handle);
|
||||
}
|
||||
#else
|
||||
#ifdef USES_RESOURCE_FILESYSTEM
|
||||
else
|
||||
{
|
||||
wicedfs_file_t file_hnd;
|
||||
|
||||
if (0 != wicedfs_fopen(&resource_fs_handle, &file_hnd, resource->val.fs.filename) )
|
||||
{
|
||||
return RESOURCE_FILE_OPEN_FAIL;
|
||||
}
|
||||
|
||||
if (0 != wicedfs_fseek(&file_hnd, (long)(offset + resource->val.fs.offset), SEEK_SET) )
|
||||
{
|
||||
wicedfs_fclose(&file_hnd);
|
||||
return RESOURCE_FILE_SEEK_FAIL;
|
||||
}
|
||||
|
||||
if (*size != wicedfs_fread(buffer, 1, *size, &file_hnd) )
|
||||
{
|
||||
wicedfs_fclose(&file_hnd);
|
||||
return RESOURCE_FILE_READ_FAIL;
|
||||
}
|
||||
|
||||
wicedfs_fclose(&file_hnd);
|
||||
}
|
||||
#endif /* ifdef USES_RESOURCE_FILESYSTEM */
|
||||
#endif /* USES_RESOURCE_GENERIC_FILESYSTEM */
|
||||
return RESOURCE_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t host_platform_resource_size(whd_driver_t whd_drv, whd_resource_type_t resource, uint32_t *size_out)
|
||||
{
|
||||
if (resource == WHD_RESOURCE_WLAN_FIRMWARE)
|
||||
{
|
||||
#ifdef NO_WIFI_FIRMWARE
|
||||
whd_assert("Request firmware in a no wifi firmware application", 0 == 1);
|
||||
*size_out = 0;
|
||||
#else
|
||||
#ifdef WIFI_FIRMWARE_IN_MULTI_APP
|
||||
wiced_app_t wifi_app;
|
||||
|
||||
*size_out = 0;
|
||||
if (wiced_waf_app_open(DCT_WIFI_FIRMWARE_INDEX, &wifi_app) != WICED_SUCCESS)
|
||||
{
|
||||
return ( whd_result_t )RESOURCE_UNSUPPORTED;
|
||||
}
|
||||
wiced_waf_app_get_size(&wifi_app, size_out);
|
||||
#else
|
||||
#ifdef WLAN_MFG_FIRMWARE
|
||||
*size_out = (uint32_t)resource_get_size(&wifi_mfg_firmware_image);
|
||||
#else
|
||||
*size_out = (uint32_t)resource_get_size(&wifi_firmware_image);
|
||||
#endif /* WLAN_MFG_FIRMWARE */
|
||||
#endif /* WIFI_FIRMWARE_IN_MULTI_APP */
|
||||
#endif /* NO_WIFI_FIRMWARE */
|
||||
|
||||
}
|
||||
else if (resource == WHD_RESOURCE_WLAN_NVRAM)
|
||||
{
|
||||
*size_out = NVRAM_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef WLAN_MFG_FIRMWARE
|
||||
*size_out = (uint32_t)resource_get_size(&wifi_mfg_firmware_clm_blob);
|
||||
#else
|
||||
*size_out = (uint32_t)resource_get_size(&wifi_firmware_clm_blob);
|
||||
#endif /* WLAN_MFG_FIRMWARE */
|
||||
}
|
||||
return WHD_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t 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 resource_size;
|
||||
uint32_t block_size;
|
||||
uint32_t block_count;
|
||||
uint32_t read_pos;
|
||||
uint32_t result;
|
||||
|
||||
host_platform_resource_size(whd_drv, type, &resource_size);
|
||||
host_get_resource_block_size(whd_drv, type, &block_size);
|
||||
host_get_resource_no_of_blocks(whd_drv, type, &block_count);
|
||||
memset(r_buffer, 0, block_size);
|
||||
read_pos = blockno * block_size;
|
||||
|
||||
if (blockno >= block_count)
|
||||
{
|
||||
return WHD_BADARG;
|
||||
}
|
||||
|
||||
if (type == WHD_RESOURCE_WLAN_FIRMWARE)
|
||||
{
|
||||
#ifdef WLAN_MFG_FIRMWARE
|
||||
result = resource_read( (const resource_hnd_t *)&wifi_mfg_firmware_image, read_pos, block_size, size_out,
|
||||
r_buffer );
|
||||
#else
|
||||
result = resource_read( (const resource_hnd_t *)&wifi_firmware_image, read_pos, block_size, size_out,
|
||||
r_buffer );
|
||||
#endif /* WLAN_MFG_FIRMWARE */
|
||||
if (result != WHD_SUCCESS)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
*data = (uint8_t *)&r_buffer;
|
||||
/*
|
||||
* In case of local buffer read use the following code
|
||||
*
|
||||
* *size_out = MIN(BLOCK_BUFFER_SIZE, resource_size - transfer_progress);
|
||||
* *data = (uint8_t *)wifi_firmware_image_data;
|
||||
*
|
||||
* For sending the entire buffer in single block set size out as following
|
||||
* *size_out = (uint32_t)resource_get_size(&wifi_firmware_image);
|
||||
*/
|
||||
}
|
||||
else if (type == WHD_RESOURCE_WLAN_NVRAM)
|
||||
{
|
||||
if (NVRAM_SIZE - read_pos > block_size)
|
||||
{
|
||||
*size_out = block_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
*size_out = NVRAM_SIZE - read_pos;
|
||||
}
|
||||
*data = ( (uint8_t *)NVRAM_IMAGE_VARIABLE ) + read_pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef WLAN_MFG_FIRMWARE
|
||||
result = resource_read( (const resource_hnd_t *)&wifi_mfg_firmware_clm_blob, read_pos, block_size,
|
||||
size_out,
|
||||
r_buffer );
|
||||
#else
|
||||
result = resource_read( (const resource_hnd_t *)&wifi_firmware_clm_blob, read_pos, block_size,
|
||||
size_out,
|
||||
r_buffer );
|
||||
#endif /* WLAN_MFG_FIRMWARE */
|
||||
if (result != WHD_SUCCESS)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
*data = (uint8_t *)&r_buffer;
|
||||
/*
|
||||
* In case of local buffer read use the following code
|
||||
*
|
||||
* *size_out = MIN(BLOCK_BUFFER_SIZE, resource_size - transfer_progress);
|
||||
* *data = (uint8_t *)wifi_firmware_clm_blob_image_data;
|
||||
*
|
||||
* For sending the entire buffer in single block set size out as following
|
||||
* *size_out = sizeof(wifi_firmware_clm_blob_image_data);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
return WHD_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t host_get_resource_block_size(whd_driver_t whd_drv, whd_resource_type_t type, uint32_t *size_out)
|
||||
{
|
||||
*size_out = BLOCK_BUFFER_SIZE;
|
||||
return WHD_SUCCESS;
|
||||
}
|
||||
|
||||
uint32_t host_get_resource_no_of_blocks(whd_driver_t whd_drv, whd_resource_type_t type, uint32_t *block_count)
|
||||
{
|
||||
uint32_t resource_size;
|
||||
uint32_t block_size;
|
||||
|
||||
host_platform_resource_size(whd_drv, type, &resource_size);
|
||||
host_get_resource_block_size(whd_drv, type, &block_size);
|
||||
*block_count = resource_size / block_size;
|
||||
if (resource_size % block_size)
|
||||
*block_count += 1;
|
||||
|
||||
return WHD_SUCCESS;
|
||||
}
|
||||
|
||||
whd_resource_source_t resource_ops =
|
||||
{
|
||||
.whd_resource_size = host_platform_resource_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_block = host_get_resource_block
|
||||
};
|
||||
|
|
@ -1,228 +0,0 @@
|
|||
/*
|
||||
* Copyright 2020 Cypress Semiconductor Corporation
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
|
||||
/** @file
|
||||
* WICED Resource API's
|
||||
* The Resource Management functions reads resource from a resource location
|
||||
* and returns the number of bytes from an offset in an caller filled buffer.
|
||||
*
|
||||
* Functions to get the resource size and resource data
|
||||
*
|
||||
* The Resource could be one of the three locations
|
||||
*
|
||||
* - Wiced Filesystem (File System)
|
||||
* - Internal Memory (Embedded Flash memory)
|
||||
* - External Storage ( External Flash connected via SPI interface)
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_RESOURCE_H_
|
||||
#define INCLUDED_RESOURCE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/******************************************************
|
||||
* Macros
|
||||
******************************************************/
|
||||
#ifndef MIN
|
||||
#define MIN(x, y) ( (x) < (y) ? (x) : (y) )
|
||||
#endif /* ifndef MIN */
|
||||
|
||||
/* Suppress unused parameter warning */
|
||||
#ifndef UNUSED_PARAMETER
|
||||
#define UNUSED_PARAMETER(x) ( (void)(x) )
|
||||
#endif
|
||||
|
||||
#ifndef RESULT_ENUM
|
||||
#define RESULT_ENUM(prefix, name, value) prefix ## name = (value)
|
||||
#endif /* ifndef RESULT_ENUM */
|
||||
|
||||
#if defined(CY_SECTION)
|
||||
#define CY_SECTION_WHD CY_SECTION
|
||||
#else
|
||||
#if !defined(CY_SECTION_WHD)
|
||||
#if defined(__ARMCC_VERSION)
|
||||
#define CY_SECTION_WHD(name) __attribute__ ( (section(name) ) )
|
||||
#elif defined (__GNUC__)
|
||||
#if defined (__clang__)
|
||||
#define CY_SECTION_WHD(name) __attribute__ ( (section("__DATA, "name) ) )
|
||||
#else
|
||||
#define CY_SECTION_WHD(name) __attribute__ ( (section(name) ) )
|
||||
#endif
|
||||
#elif defined (__ICCARM__)
|
||||
#define CY_SECTION_WHD(name) CY_PRAGMA(location = name)
|
||||
#else
|
||||
#error "An unsupported toolchain"
|
||||
#endif /* (__ARMCC_VERSION) */
|
||||
#endif /* !defined(CY_SECTION_WHD) */
|
||||
#endif /* defined(CY_SECTION) */
|
||||
|
||||
/* These Enum result values are for Resource errors
|
||||
* Values: 4000 - 4999
|
||||
*/
|
||||
#define RESOURCE_RESULT_LIST(prefix) \
|
||||
RESULT_ENUM(prefix, SUCCESS, 0), /**< Success */ \
|
||||
RESULT_ENUM(prefix, UNSUPPORTED, 7), /**< Unsupported function */ \
|
||||
RESULT_ENUM(prefix, OFFSET_TOO_BIG, 4001), /**< Offset past end of resource */ \
|
||||
RESULT_ENUM(prefix, FILE_OPEN_FAIL, 4002), /**< Failed to open resource file */ \
|
||||
RESULT_ENUM(prefix, FILE_SEEK_FAIL, 4003), /**< Failed to seek to requested offset in resource file */ \
|
||||
RESULT_ENUM(prefix, FILE_READ_FAIL, 4004), /**< Failed to read resource file */
|
||||
|
||||
#define resource_get_size(resource) ( (resource)->size )
|
||||
|
||||
/******************************************************
|
||||
* Constants
|
||||
******************************************************/
|
||||
|
||||
#define RESOURCE_ENUM_OFFSET (1300)
|
||||
|
||||
/******************************************************
|
||||
* Enumerations
|
||||
******************************************************/
|
||||
|
||||
/**
|
||||
* Result type for WICED Resource function
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
RESOURCE_RESULT_LIST(RESOURCE_)
|
||||
} resource_result_t;
|
||||
|
||||
/******************************************************
|
||||
* Type Definitions
|
||||
******************************************************/
|
||||
|
||||
typedef const void *resource_data_t;
|
||||
typedef unsigned long resource_size_t;
|
||||
|
||||
/******************************************************
|
||||
* Structures
|
||||
******************************************************/
|
||||
|
||||
/**
|
||||
* Memory handle
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
const char *data; /**< resource data */
|
||||
} memory_resource_handle_t;
|
||||
|
||||
/**
|
||||
* Filesystem handle
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
unsigned long offset; /**< Offset to the start of the resource */
|
||||
const char *filename; /**< name of the resource */
|
||||
} filesystem_resource_handle_t;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RESOURCE_IN_MEMORY, /**< resource location in memory */
|
||||
RESOURCE_IN_FILESYSTEM, /**< resource location in filesystem */
|
||||
RESOURCE_IN_EXTERNAL_STORAGE /**< resource location in external storage */
|
||||
} resource_location_t;
|
||||
|
||||
/**
|
||||
* Resource handle structure
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
resource_location_t location; /**< resource location */
|
||||
unsigned long size; /**< resource size */
|
||||
union
|
||||
{
|
||||
filesystem_resource_handle_t fs; /** < filesystem resource handle */
|
||||
memory_resource_handle_t mem; /** < memory resource handle */
|
||||
void *external_storage_context; /** < external storage context */
|
||||
} val;
|
||||
} resource_hnd_t;
|
||||
|
||||
/******************************************************
|
||||
* Global Variables
|
||||
******************************************************/
|
||||
|
||||
/******************************************************
|
||||
* Function Declarations
|
||||
******************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/** @addtogroup resourceapi Wiced Resource Management API's
|
||||
* @ingroup framework
|
||||
*
|
||||
* WCIED Resource Management API's has functions to get the
|
||||
* resource size and reads resource data from a resource
|
||||
* location and returns the number of bytes in an caller
|
||||
* filled buffer
|
||||
*
|
||||
* The Resource could be one of the three locations
|
||||
*
|
||||
* - Wiced Filesystem ( File System)
|
||||
* - Internal Memory (Embedded Flash memory)
|
||||
* - External Storage ( External Flash connected via SPI interface )
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
|
||||
/** Read resource using the handle specified
|
||||
*
|
||||
* @param[in] resource : handle of the resource to read
|
||||
* @param[in] offset : offset from the beginning of the resource block
|
||||
* @param[in] maxsize : size of the buffer
|
||||
* @param[out] size : size of the data successfully read
|
||||
* @param[in] buffer : pointer to a buffer to contain the read data
|
||||
*
|
||||
* @return @ref resource_result_t
|
||||
*/
|
||||
extern resource_result_t resource_read(const resource_hnd_t *resource, uint32_t offset, uint32_t maxsize,
|
||||
uint32_t *size, void *buffer);
|
||||
|
||||
/** Retrieve a read only resource buffer using the handle specified
|
||||
*
|
||||
* @param[in] resource : handle of the resource to read
|
||||
* @param[in] offset : offset from the beginning of the resource block
|
||||
* @param[in] maxsize : size of the buffer
|
||||
* @param[out] size : size of the data successfully read
|
||||
* @param[out] buffer : pointer to a buffer pointer to point to the resource data
|
||||
*
|
||||
* @return @ref resource_result_t
|
||||
*/
|
||||
extern resource_result_t resource_get_readonly_buffer(const resource_hnd_t *resource, uint32_t offset, uint32_t maxsize,
|
||||
uint32_t *size_out, const void **buffer);
|
||||
|
||||
/** Free a read only resource buffer using the handle specified
|
||||
*
|
||||
* @param[in] resource : handle of the resource to read
|
||||
* @param[in] buffer : pointer to a buffer set using resource_get_readonly_buffer
|
||||
*
|
||||
* @return @ref resource_result_t
|
||||
*/
|
||||
extern resource_result_t resource_free_readonly_buffer(const resource_hnd_t *handle, const void *buffer);
|
||||
/* @} */
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* ifndef INCLUDED_RESOURCE_H_ */
|
||||
|
Loading…
Reference in New Issue