更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_partition_utils.c 文件参考

浏览源代码.

函数

STATIC INT32 MatchPartPos (CHAR *p, const CHAR *partInfoName, INT32 *partInfo)
 
STATIC INT32 MatchPartInfo (CHAR *p, struct PartitionInfo *partInfo)
 
STATIC INT32 GetPartitionBootArgs (const CHAR *argName, CHAR **args)
 
INT32 GetPartitionInfo (struct PartitionInfo *partInfo)
 
const CHARGetDevNameOfPartition (const struct PartitionInfo *partInfo)
 
INT32 ResetDevNameofPartition (const struct PartitionInfo *partInfo)
 

函数说明

◆ GetDevNameOfPartition()

const CHAR * GetDevNameOfPartition ( const struct PartitionInfo partInfo)

在文件 los_partition_utils.c199 行定义.

200{
201 const CHAR *devName = NULL;
202
203 if (strcmp(partInfo->storageType, STORAGE_TYPE) == 0) {
204#if defined(LOSCFG_STORAGE_SPINOR)
205 INT32 ret = add_mtd_partition(FLASH_TYPE, partInfo->startAddr, partInfo->partSize, partInfo->partNum);
206 if (ret != LOS_OK) {
207 PRINT_ERR("Failed to add %s partition! error = %d\n", partInfo->partName, ret);
208 } else {
209 if (partInfo->devName != NULL) {
210 devName = partInfo->devName;
211 }
212 }
213#endif
214 } else {
215 PRINT_ERR("Failed to find %s dev type: %s\n", partInfo->partName, partInfo->storageType);
216 }
217
218 return devName;
219}
INT32 add_mtd_partition(const CHAR *type, UINT32 startAddr, UINT32 length, UINT32 partitionNum)
Add a partition.
signed int INT32
Definition: los_typedef.h:60
char CHAR
Definition: los_typedef.h:63
UINT32 partNum
分区编号
INT32 startAddr
开始地址
CHAR * devName
设备名称
const CHAR * partName
分区名称
INT32 partSize
分区大小
函数调用图:
这是这个函数的调用关系图:

◆ GetPartitionBootArgs()

STATIC INT32 GetPartitionBootArgs ( const CHAR argName,
CHAR **  args 
)

在文件 los_partition_utils.c111 行定义.

112{
113 INT32 i;
114 INT32 len = 0;
115 CHAR *cmdLine = NULL;
116 INT32 cmdLineLen;
117 CHAR *tmp = NULL;
118
119 cmdLine = (CHAR *)malloc(COMMAND_LINE_SIZE);
120 if (cmdLine == NULL) {
121 PRINT_ERR("Malloc cmdLine space failed!\n");
122 return LOS_NOK;
123 }
124
125#if defined(LOSCFG_STORAGE_SPINOR)
126 struct MtdDev *mtd = GetMtd(FLASH_TYPE);
127 if (mtd == NULL) {
128 PRINT_ERR("Get spinor mtd failed!\n");
129 goto ERROUT;
130 }
131 cmdLineLen = mtd->read(mtd, COMMAND_LINE_ADDR, COMMAND_LINE_SIZE, cmdLine);
132 if ((cmdLineLen != COMMAND_LINE_SIZE)) {
133 PRINT_ERR("Read spinor command line failed!\n");
134 goto ERROUT;
135 }
136#else
137 cmdLineLen = 0;
138#endif
139
140 for (i = 0; i < cmdLineLen; i += len + 1) {
141 len = strlen(cmdLine + i);
142 tmp = strstr(cmdLine + i, argName);
143 if (tmp != NULL) {
144 *args = strdup(tmp + strlen(argName));
145 if (*args == NULL) {
146 goto ERROUT;
147 }
148 free(cmdLine);
149 return LOS_OK;
150 }
151 }
152
153 PRINTK("no patch partition bootargs\n");
154
155ERROUT:
156 free(cmdLine);
157 return LOS_NOK;
158}
void * malloc(size_t size)
动态分配内存块大小
Definition: malloc.c:81
void free(void *ptr)
释放ptr所指向的内存空间
Definition: malloc.c:66
void * GetMtd(const char *type)
flash MTD 层 描述符
Definition: mtd_dev.h:76
int(* read)(struct MtdDev *mtd, UINT64 start, UINT64 len, const char *buf)
读操作
Definition: mtd_dev.h:84
函数调用图:
这是这个函数的调用关系图:

◆ GetPartitionInfo()

INT32 GetPartitionInfo ( struct PartitionInfo partInfo)

在文件 los_partition_utils.c160 行定义.

161{
162 CHAR *args = NULL;
163 CHAR *argsBak = NULL;
164 CHAR *p = NULL;
165
166 if (GetPartitionBootArgs(partInfo->cmdlineArgName, &args) != LOS_OK) {
167 return LOS_NOK;
168 }
169 argsBak = args;
170
171 p = strsep(&args, " ");
172 while (p != NULL) {
173 if (MatchPartInfo(p, partInfo) != LOS_OK) {
174 goto ERROUT;
175 }
176 p = strsep(&args, " ");
177 }
178 if ((partInfo->fsType != NULL) && (partInfo->storageType != NULL)) {
179 free(argsBak);
180 return LOS_OK;
181 }
182 PRINT_ERR("Cannot find %s type\n", partInfo->partName);
183
184ERROUT:
185 PRINT_ERR("Invalid %s information!\n", partInfo->partName);
186 if (partInfo->storageType != NULL) {
187 free(partInfo->storageType);
188 partInfo->storageType = NULL;
189 }
190 if (partInfo->fsType != NULL) {
191 free(partInfo->fsType);
192 partInfo->fsType = NULL;
193 }
194 free(argsBak);
195
196 return LOS_NOK;
197}
STATIC INT32 MatchPartInfo(CHAR *p, struct PartitionInfo *partInfo)
STATIC INT32 GetPartitionBootArgs(const CHAR *argName, CHAR **args)
CHAR * fsType
文件系统类型
const CHAR * cmdlineArgName
命令行参数名称
函数调用图:
这是这个函数的调用关系图:

◆ MatchPartInfo()

STATIC INT32 MatchPartInfo ( CHAR p,
struct PartitionInfo partInfo 
)

在文件 los_partition_utils.c71 行定义.

72{
73 const CHAR *storageTypeArgName = partInfo->storageTypeArgName;
74 const CHAR *fsTypeArgName = partInfo->fsTypeArgName;
75 const CHAR *addrArgName = partInfo->addrArgName;
76 const CHAR *partSizeArgName = partInfo->partSizeArgName;
77
78 if ((partInfo->storageType == NULL) && (strncmp(p, storageTypeArgName, strlen(storageTypeArgName)) == 0)) {
79 partInfo->storageType = strdup(p + strlen(storageTypeArgName));
80 if (partInfo->storageType == NULL) {
81 return LOS_NOK;
82 }
83 return LOS_OK;
84 }
85
86 if ((partInfo->fsType == NULL) && (strncmp(p, fsTypeArgName, strlen(fsTypeArgName)) == 0)) {
87 partInfo->fsType = strdup(p + strlen(fsTypeArgName));
88 if (partInfo->fsType == NULL) {
89 return LOS_NOK;
90 }
91 return LOS_OK;
92 }
93
94 if (partInfo->startAddr < 0) {
95 if (MatchPartPos(p, addrArgName, &partInfo->startAddr) != LOS_OK) {
96 return LOS_NOK;
97 } else if (partInfo->startAddr >= 0) {
98 return LOS_OK;
99 }
100 }
101
102 if (partInfo->partSize < 0) {
103 if (MatchPartPos(p, partSizeArgName, &partInfo->partSize) != LOS_OK) {
104 return LOS_NOK;
105 }
106 }
107
108 return LOS_OK;
109}
STATIC INT32 MatchPartPos(CHAR *p, const CHAR *partInfoName, INT32 *partInfo)
const CHAR * storageTypeArgName
const CHAR * addrArgName
const CHAR * fsTypeArgName
const CHAR * partSizeArgName
函数调用图:
这是这个函数的调用关系图:

◆ MatchPartPos()

STATIC INT32 MatchPartPos ( CHAR p,
const CHAR partInfoName,
INT32 partInfo 
)

在文件 los_partition_utils.c36 行定义.

37{
38 UINT32 offset;
39 CHAR *value = NULL;
40
41 if (strncmp(p, partInfoName, strlen(partInfoName)) == 0) {
42 value = p + strlen(partInfoName);
43 offset = strspn(value, DEC_NUMBER_STRING);
44 if (strcmp(p + strlen(p) - 1, "M") == 0) {
45 if ((offset < strlen(value) - 1) || (sscanf_s(value, "%d", partInfo) <= 0)) {
46 goto ERROUT;
47 }
48 *partInfo = *partInfo * BYTES_PER_MBYTE;
49 } else if (strcmp(p + strlen(p) - 1, "K") == 0) {
50 if ((offset < (strlen(value) - 1)) || (sscanf_s(value, "%d", partInfo) <= 0)) {
51 goto ERROUT;
52 }
53 *partInfo = *partInfo * BYTES_PER_KBYTE;
54 } else if (sscanf_s(value, "0x%x", partInfo) > 0) {
55 value += strlen("0x");
56 if (strspn(value, HEX_NUMBER_STRING) < strlen(value)) {
57 goto ERROUT;
58 }
59 } else {
60 goto ERROUT;
61 }
62 }
63
64 return LOS_OK;
65
66ERROUT:
67 PRINT_ERR("Invalid format: %s\n", p + strlen(partInfoName));
68 return LOS_NOK;
69}
unsigned int UINT32
Definition: los_typedef.h:57
这是这个函数的调用关系图:

◆ ResetDevNameofPartition()

INT32 ResetDevNameofPartition ( const struct PartitionInfo partInfo)

在文件 los_partition_utils.c221 行定义.

222{
223 INT32 ret;
224#if defined(LOSCFG_STORAGE_SPINOR)
225 ret = delete_mtd_partition(partInfo->partNum, FLASH_TYPE);
226 if (ret != ENOERR) {
227 int err = get_errno();
228 PRINT_ERR("Failed to delete %s, errno %d: %s\n", partInfo->devName, err, strerror(err));
229 ret = LOS_NOK;
230 }
231#else
232 ret = LOS_NOK;
233#endif
234 return ret;
235}
INT32 delete_mtd_partition(UINT32 partitionNum, const CHAR *type)
Delete a partition.
函数调用图:
这是这个函数的调用关系图: