1 /*
2  * Copyright (C) 2015-2017 Alibaba Group Holding Limited
3  */
4 #include "rec_flash.h"
5 
6 #include "flash_api.h"
7 #include "hal_platform.h"
8 
9 static flash_t flash_obj;
10 /* Logic partition on flash devices */
11 extern const hal_logic_partition_t hal_partitions[];
12 extern const size_t hal_partitions_amount;
13 
flash_read_data(UINT8 * buffer,UINT32 address,UINT32 len)14 static void flash_read_data(UINT8 *buffer, UINT32 address, UINT32 len)
15 {
16     flash_stream_read(&flash_obj, address, len, buffer);
17 }
18 
flash_write_data(UINT8 * buffer,UINT32 address,UINT32 len)19 static void flash_write_data(UINT8 *buffer, UINT32 address, UINT32 len)
20 {
21     flash_stream_write(&flash_obj, address, len, buffer);
22 }
23 
rec_flash_init(void)24 void rec_flash_init(void)
25 {
26     //flash has init in boot code;
27 }
28 
29 /* offset means physical address */
rec_flash_erase(unsigned long offset)30 void rec_flash_erase(unsigned long offset)
31 {
32     offset &= ~(FLASH_SECTOR_SIZE-1);
33     flash_erase_sector(&flash_obj, offset);
34 }
35 
36 /* offset means physical address */
rec_flash_read_data(unsigned char * buffer,unsigned long offset,unsigned long len)37 void rec_flash_read_data(unsigned char *buffer, unsigned long offset, unsigned long len)
38 {
39     flash_read_data(buffer, offset, len);
40 }
41 
42 /* offset means physical address */
rec_flash_write_data(unsigned char * buffer,unsigned long offset,unsigned long len)43 void rec_flash_write_data(unsigned char *buffer, unsigned long offset, unsigned long len)
44 {
45     flash_write_data(buffer, offset, len);
46 }
47 
rec_flash_get_info(hal_partition_t pno)48 hal_logic_partition_t *rec_flash_get_info(hal_partition_t pno)
49 {
50     if(pno >= hal_partitions_amount)
51     {
52         return NULL;
53     }
54     return &hal_partitions[pno];
55 }
56