• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  *    conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  *    of conditions and the following disclaimer in the documentation and/or other materials
13  *    provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  *    to endorse or promote products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /**
33  * @defgroup filesystem FileSystem
34  * @defgroup mtd_partition Multi Partition
35  * @ingroup filesystem
36  */
37 #ifndef _MTD_PARTITION_H
38 #define _MTD_PARTITION_H
39 
40 #include "sys/types.h"
41 #include "los_mux.h"
42 #include "mtd_list.h"
43 
44 #ifdef __cplusplus
45 #if __cplusplus
46 extern "C" {
47 #endif /* __cplusplus */
48 #endif /* __cplusplus */
49 
50 #define SPIBLK_NAME  "/dev/spinorblk"
51 #define SPICHR_NAME  "/dev/spinorchr"
52 
53 #define NANDBLK_NAME "/dev/nandblk"
54 #define NANDCHR_NAME "/dev/nandchr"
55 
56 typedef struct mtd_node {
57     UINT32 start_block;
58     UINT32 end_block;
59     UINT32 patitionnum;
60     CHAR *blockdriver_name;
61     CHAR *chardriver_name;
62     CHAR *mountpoint_name;
63     VOID *mtd_info; /* Driver used by a partition */
64     LOS_DL_LIST node_info;
65     LosMux lock;
66     UINT32 user_num;
67 } mtd_partition;
68 
69 typedef struct par_param {
70     mtd_partition *partition_head;
71     struct MtdDev *flash_mtd;
72     const struct block_operations *flash_ops;
73     const struct file_operations_vfs *char_ops;
74     CHAR *blockname;
75     CHAR *charname;
76     UINT32 block_size;
77 } partition_param;
78 
79 #define CONFIG_MTD_PATTITION_NUM 20
80 
81 #define ALIGN_ASSIGN(len, startAddr, startBlk, endBlk, blkSize) do {    \
82     (len) = (((len) + ((blkSize) - 1)) & ~((blkSize) - 1));             \
83     (startAddr) = ((startAddr) & ~((blkSize) - 1));                     \
84     (startBlk) = (startAddr) / (blkSize);                               \
85     (endBlk) = (len) / (blkSize) + ((startBlk) - 1);                    \
86 } while (0)
87 
88 #define PAR_ASSIGNMENT(node, len, startAddr, num, mtd, blkSize) do {    \
89     (node)->start_block = (startAddr) / (blkSize);                      \
90     (node)->end_block = (len) / (blkSize) + ((node)->start_block - 1);  \
91     (node)->patitionnum = (num);                                        \
92     (node)->mtd_info = (mtd);                                           \
93     (node)->mountpoint_name = NULL;                                     \
94 } while (0)
95 
96 partition_param *GetNandPartParam(VOID);
97 partition_param *GetSpinorPartParam(VOID);
98 mtd_partition *GetSpinorPartitionHead(VOID);
99 
100 /**
101  * @ingroup mtd_partition
102  * @brief Add a partition.
103  *
104  * @par Description:
105  * <ul>
106  * <li>This API is used to add a partition according to the passed-in parameters.</li>
107  * </ul>
108  * @attention
109  * <ul>
110  * <li>None.</li>
111  * </ul>
112  *
113  * @param type           [IN] Storage medium type, support "nand" and "spinor" currently.
114  * @param startAddr      [IN] Starting address of a partition.
115  * @param length         [IN] Partition size.
116  * @param partitionNum   [IN] Partition number, less than the value defined by CONFIG_MTD_PATTITION_NUM.
117  *
118  * @retval #-ENODEV      The driver is not found.
119  * @retval #-EINVAL      Invalid parameter.
120  * @retval #-ENOMEM      Insufficient memory.
121  * @retval #ENOERR       The partition is successfully created.
122  *
123  * @par Dependency:
124  * <ul><li>mtd_partition.h: the header file that contains the API declaration.</li></ul>
125  * @see delete_mtd_partition
126  */
127 extern INT32 add_mtd_partition(const CHAR *type, UINT32 startAddr, UINT32 length, UINT32 partitionNum);
128 
129 /**
130  * @ingroup mtd_partition
131  * @brief Delete a partition.
132  *
133  * @par Description:
134  * <ul>
135  * <li>This API is used to delete a partition according to its partition number and storage medium type.</li>
136  * </ul>
137  * @attention
138  * <ul>
139  * <li>None.</li>
140  * </ul>
141  *
142  * @param partitionNum   [IN] Partition number, less than the value defined by CONFIG_MTD_PATTITION_NUM.
143  * @param type           [IN] Storage medium type, support "nand" and "spinor" currently.
144  *
145  * @retval #-EINVAL    Invalid parameter.
146  * @retval #ENOERR     The partition is successfully deleted.
147  *
148  * @par Dependency:
149  * <ul><li>mtd_partition.h: the header file that contains the API declaration.</li></ul>
150  * @see add_mtd_partition
151  */
152 extern INT32 delete_mtd_partition(UINT32 partitionNum, const CHAR *type);
153 
154 #ifdef __cplusplus
155 #if __cplusplus
156 }
157 #endif /* __cplusplus */
158 #endif /* __cplusplus */
159 
160 #endif /* _MTD_PARTITION_H */
161