113 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			113 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /****************************************************************************
 | |
| 
 | |
| Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
 | |
| 
 | |
| This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
 | |
| be copied by any method or incorporated into another program without
 | |
| the express written consent of Aerospace C.Power. This Information or any portion
 | |
| thereof remains the property of Aerospace C.Power. The Information contained herein
 | |
| is believed to be accurate and Aerospace C.Power assumes no responsibility or
 | |
| liability for its use in any way and conveys no license or title under
 | |
| any patent or copyright and makes no representation or warranty that this
 | |
| Information is free from patent or copyright infringement.
 | |
| 
 | |
| ****************************************************************************/
 | |
| #include "chip_reg_base.h"
 | |
| #include "hw_reg_api.h"
 | |
| #include "flash.h"
 | |
| #include "iot_config.h"
 | |
| #include "flash_bench.h"
 | |
| #include "os_mem.h"
 | |
| #include "iot_flash_layout.h"
 | |
| 
 | |
| void flash_bench_get_flash_image_offset(uint32_t part[], uint32_t *p_num)
 | |
| {
 | |
|     iot_flash_info_t info;
 | |
| 
 | |
|     flash_bench_get_flash_info(&info);
 | |
| 
 | |
|     if (FLASH_BENCH_SIZE_4M == info.chip_size) {
 | |
|         part[0] = FLASH_4M_SP_OFFSET;
 | |
|         part[1] = FLASH_4M_SBL_OFFSET;
 | |
|         part[2] = FLASH_4M_OEM_OFFSET;
 | |
|         part[3] = FLASH_4M_PIB1_OFFSET;
 | |
|         part[4] = FLASH_4M_PSRAM_RUN_OFFSET;
 | |
|         part[5] = FLASH_4M_FW1_OFFSET;
 | |
|         *p_num = 6;
 | |
|     } else if (FLASH_BENCH_SIZE_2M == info.chip_size) {
 | |
|         part[0] = FLASH_2M_SP_OFFSET;
 | |
|         part[1] = FLASH_2M_SBL_OFFSET;//FLASH_2M_SBL_OFFSET;
 | |
|         part[2] = FLASH_2M_OEM_OFFSET;
 | |
|         part[3] = FLASH_2M_PIB1_OFFSET;
 | |
|         part[4] = FLASH_2M_RUN_OFFSET;
 | |
|         part[5] = FLASH_2M_FW1_OFFSET;
 | |
|         *p_num = 6;
 | |
|     } else if (FLASH_BENCH_SIZE_1M == info.chip_size) {
 | |
|         part[0] = FLASH_1M_SP_OFFSET;
 | |
|         part[1] = FLASH_1M_SBL_OFFSET;
 | |
|         part[2] = FLASH_1M_OEM_OFFSET;
 | |
|         part[3] = FLASH_1M_PIB1_OFFSET;
 | |
|         part[4] = FLASH_1M_FW1_OFFSET;
 | |
|         *p_num = 5;
 | |
|     } else {
 | |
|         *p_num = 0;
 | |
|     }
 | |
| 
 | |
|     return;
 | |
| }
 | |
| uint32_t flash_bench_get_flash_base_addr(void)
 | |
| {
 | |
|     return FLASH_BENCH_FLASH_BASE;
 | |
| }
 | |
| 
 | |
| void flash_bench_get_flash_info(iot_flash_info_t *p_info)
 | |
| {
 | |
|     uint8_t data[4];
 | |
|     uint32_t chip_size;
 | |
| 
 | |
|     if (NULL == p_info) {
 | |
|         return;
 | |
|     }
 | |
| 
 | |
|     flash_get_dev_id(data);
 | |
|     p_info->id = data[1] | data[0];
 | |
|     p_info->sec_size = FLASH_DEF_SECTOR_SIZE;
 | |
| 
 | |
|     chip_size = flash_get_dev_size();
 | |
| 
 | |
|     if (chip_size >= FLASH_8M) {
 | |
|         p_info->chip_size = FLASH_BENCH_SIZE_8M;
 | |
|     } else if (chip_size >= FLASH_4M) {
 | |
|         p_info->chip_size = FLASH_BENCH_SIZE_4M;
 | |
|     } else if (chip_size >= FLASH_2M) {
 | |
|         p_info->chip_size = FLASH_BENCH_SIZE_2M;
 | |
|     } else {
 | |
|         p_info->chip_size = FLASH_BENCH_SIZE_1M;
 | |
|     }
 | |
| 
 | |
|     return;
 | |
| }
 | |
| 
 | |
| void flash_bench_read_contrl(void *data, uint32_t offset, uint32_t size)
 | |
| {
 | |
|     flash_read(data, offset, (int)size, MOD_SFC_READ_QUAD_IO_FAST);
 | |
| 
 | |
|     return;
 | |
| }
 | |
| 
 | |
| void flash_bench_read_cache(void *data, uint32_t offset, uint32_t size)
 | |
| {
 | |
|     uint32_t flash_base = flash_bench_get_flash_base_addr();
 | |
| 
 | |
|     os_mem_cpy(data, (void *)(flash_base | offset), size);
 | |
| 
 | |
|     return;
 | |
| }
 | |
| 
 | |
| void flash_bench_init(void)
 | |
| {
 | |
|     flash_init(1);
 | |
| 
 | |
|     return;
 | |
| }
 |