1# FAL API
2
3## Find Flash device
4
5```C
6const struct fal_flash_dev *fal_flash_device_find(const char *name)
7```
8
9| Parameters | Description |
10| :----- | :----------------------- |
11| name | Flash device name |
12| return | If the search is successful, the Flash device object will be returned, and if the search fails, it will return NULL |
13
14## Find Flash Partition
15
16```C
17const struct fal_partition *fal_partition_find(const char *name)
18```
19
20| Parameters | Description |
21| :----- | :----------------------- |
22| name | Flash partition name |
23| return | If the search is successful, the Flash partition object will be returned, and if the search fails, it will return NULL |
24
25## Get the partition table
26
27```C
28const struct fal_partition *fal_get_partition_table(rt_size_t *len)
29```
30
31| Parameters | Description |
32| :----- | :----------------------- |
33| len | The length of the partition table |
34| return | Partition table |
35
36## Temporarily set the partition table
37
38The default partition table will be automatically loaded when FAL is initialized. Using this setting will temporarily modify the partition table and will **lost** this setting after restarting
39
40```C
41void fal_set_partition_table_temp(struct fal_partition *table, rt_size_t len)
42```
43
44| Parameters | Description |
45| :----- | :----------------------- |
46| table | Partition table |
47| len | Length of the partition table |
48
49## Read data from partition
50
51```C
52int fal_partition_read(const struct fal_partition *part, rt_uint32_t addr, rt_uint8_t *buf, rt_size_t size)
53```
54
55| Parameters | Description |
56| :----- | :----------------------- |
57| part | Partition object |
58| addr | Relative partition offset address |
59| buf | Buffer to store the data to be read |
60| size | The size of the data to be read |
61| return | Return the actual read data size |
62
63## Write data to partition
64
65```C
66int fal_partition_write(const struct fal_partition *part, rt_uint32_t addr, const rt_uint8_t *buf, rt_size_t size)
67```
68
69| Parameters | Description |
70| :----- | :----------------------- |
71| part | Partition object |
72| addr | Relative partition offset address |
73| buf | Buffer to store data to be written |
74| size | The size of the data to be written |
75| return | Return the actual written data size |
76
77## Erase partition data
78
79```C
80int fal_partition_erase(const struct fal_partition *part, rt_uint32_t addr, rt_size_t size)
81```
82
83| Parameters | Description |
84| :----- | :----------------------- |
85| part | Partition object |
86| addr | Relative partition offset address |
87| size | The size of the erased area |
88| return | Return the actual erased area size |
89
90## Erase the entire partition data
91
92```C
93int fal_partition_erase_all(const struct fal_partition *part)
94```
95
96| Parameters | Description |
97| :----- | :----------------------- |
98| part | Partition object |
99| return | Return the actual erased area size |
100
101## Print partition table
102
103```c
104void fal_show_part_table(void)
105```
106
107## Create block device
108
109This function can create the corresponding block device according to the specified partition name, so as to mount the file system on the specified partition
110
111```C
112struct rt_device *fal_blk_device_create(const char *parition_name)
113```
114
115| Parameters | Description |
116| :----- | :----------------------- |
117| parition_name | partition name |
118| return | If the creation is successful, the corresponding block device will be returned, and if it fails, empty |
119
120## Create MTD Nor Flash device
121
122This function can create the corresponding MTD Nor Flash device according to the specified partition name, so as to mount the file system on the specified partition
123
124```C
125struct rt_device *fal_mtd_nor_device_create(const char *parition_name)
126```
127
128| Parameters | Description |
129| :------------ | :---------------------------------- ------------------ |
130| parition_name | Partition name |
131| return | If the creation is successful, the corresponding MTD Nor Flash device will be returned, otherwise empty |
132
133## Create a character device
134
135This function can create the corresponding character device according to the specified partition name to facilitate the operation of the partition through the deivice interface or the devfs interface. After POSIX is turned on, the partition can also be operated through the open/read/write function.
136
137```C
138struct rt_device *fal_char_device_create(const char *parition_name)
139```
140
141| Parameters | Description |
142| :------------ | :---------------------------------- ------- |
143| parition_name | partition name |
144| return | If the creation is successful, the corresponding character device will be returned, otherwise empty |