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

浏览源代码.

结构体

struct  BootArgs
 

函数

INT32 LOS_GetCmdLine (VOID)
 读取环境变量bootcmd 来启动内核 更多...
 
VOID LOS_FreeCmdLine (VOID)
 
INT32 LOS_ParseBootargs (VOID)
 解析boot参数 更多...
 
INT32 LOS_GetArgValue (CHAR *argName, CHAR **argValue)
 
UINT64 LOS_GetAlignsize (VOID)
 
UINT64 LOS_SizeStrToNum (CHAR *value)
 
CHAROsGetArgsAddr (VOID)
 

函数说明

◆ LOS_FreeCmdLine()

VOID LOS_FreeCmdLine ( VOID  )

在文件 los_bootargs.c121 行定义.

122{
123 if (g_cmdLine != NULL) {
125 g_cmdLine = NULL;
126 }
127}
STATIC CHAR * g_cmdLine
Definition: los_bootargs.c:47
void free(void *ptr)
释放ptr所指向的内存空间
Definition: malloc.c:66
函数调用图:

◆ LOS_GetAlignsize()

UINT64 LOS_GetAlignsize ( VOID  )

在文件 los_bootargs.c207 行定义.

208{
209 return g_alignSize;
210}
STATIC UINT64 g_alignSize
Definition: los_bootargs.c:48
这是这个函数的调用关系图:

◆ LOS_GetArgValue()

INT32 LOS_GetArgValue ( CHAR argName,
CHAR **  argValue 
)

在文件 los_bootargs.c189 行定义.

190{
191 INT32 idx = 0;
192
193 while (idx < MAX_ARGS_NUM) {
194 if (g_bootArgs[idx].argName == NULL) {
195 break;
196 }
197 if (strcmp(argName, g_bootArgs[idx].argName) == 0) {
198 *argValue = g_bootArgs[idx].argValue;
199 return LOS_OK;
200 }
201 idx++;
202 }
203
204 return LOS_NOK;
205}
STATIC struct BootArgs g_bootArgs[MAX_ARGS_NUM]
Definition: los_bootargs.c:49
signed int INT32
Definition: los_typedef.h:60
CHAR * argValue
Definition: los_bootargs.h:48
这是这个函数的调用关系图:

◆ LOS_GetCmdLine()

INT32 LOS_GetCmdLine ( VOID  )

读取环境变量bootcmd 来启动内核

在文件 los_bootargs.c51 行定义.

52{
53 int ret;
54
55 g_cmdLine = (CHAR *)malloc(COMMAND_LINE_SIZE);
56 if (g_cmdLine == NULL) {
57 PRINT_ERR("Malloc g_cmdLine space error!\n");
58 return LOS_NOK;
59 }
60
61#ifdef LOSCFG_STORAGE_EMMC
62 los_disk *emmcDisk = los_get_mmcdisk_bytype(EMMC); //获取硬盘信息
63 if (emmcDisk == NULL) {
64 PRINT_ERR("Get EMMC disk failed!\n");
65 goto ERROUT;
66 }
67 g_alignSize = EMMC_SEC_SIZE;
68 ret = los_disk_read(emmcDisk->disk_id, g_cmdLine, COMMAND_LINE_ADDR / EMMC_SEC_SIZE,
69 COMMAND_LINE_SIZE / EMMC_SEC_SIZE, TRUE);//读取命令行内容
70 if (ret == 0) {
71 return LOS_OK;
72 }
73#endif
74
75#ifdef LOSCFG_STORAGE_SPINOR
76 struct MtdDev *mtd = GetMtd("spinor");//获取flash描述信息
77 if (mtd == NULL) {
78 PRINT_ERR("Get spinor mtd failed!\n");
79 goto ERROUT;
80 }
82 ret = mtd->read(mtd, COMMAND_LINE_ADDR, COMMAND_LINE_SIZE, g_cmdLine);//读取spinor下的命令行内容
83 if (ret == COMMAND_LINE_SIZE) {
84 return LOS_OK;
85 }
86#endif
87
88#ifdef LOSCFG_STORAGE_SPINAND
89 struct MtdDev *mtd = GetMtd("nand");//获取flash描述信息
90 if (mtd == NULL) {
91 PRINT_ERR("Get nand mtd failed!\n");
92 goto ERROUT;
93 }
95 ret = mtd->read(mtd, COMMAND_LINE_ADDR, COMMAND_LINE_SIZE, g_cmdLine);//读取nand下的命令行内容
96 if (ret == COMMAND_LINE_SIZE) {
97 return LOS_OK;
98 }
99#endif
100
101#ifdef LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7
102 struct MtdDev *mtd = GetCfiMtdDev();
103 if (mtd == NULL) {
104 PRINT_ERR("Get CFI mtd failed!\n");
105 goto ERROUT;
106 }
107 g_alignSize = mtd->eraseSize;
108 ret = mtd->read(mtd, CFIFLASH_BOOTARGS_ADDR, COMMAND_LINE_SIZE, g_cmdLine);
109 if (ret == COMMAND_LINE_SIZE) {
110 return LOS_OK;
111 }
112#endif
113
114 PRINT_ERR("Read cmdline error!\n");
115ERROUT:
117 g_cmdLine = NULL;
118 return LOS_NOK;
119}
los_disk * los_get_mmcdisk_bytype(UINT8 type)
Definition: disk.c:226
INT32 los_disk_read(INT32 drvID, VOID *buf, UINT64 sector, UINT32 count, BOOL useRead)
Read data from disk driver.
Definition: disk.c:911
char CHAR
Definition: los_typedef.h:63
void * malloc(size_t size)
动态分配内存块大小
Definition: malloc.c:81
void * GetMtd(const char *type)
UINT32 disk_id
Definition: disk.h:177
flash MTD 层 描述符
Definition: mtd_dev.h:76
UINT32 eraseSize
4K, 跟PAGE_CACHE_SIZE对应
Definition: mtd_dev.h:81
int(* read)(struct MtdDev *mtd, UINT64 start, UINT64 len, const char *buf)
读操作
Definition: mtd_dev.h:84
函数调用图:

◆ LOS_ParseBootargs()

INT32 LOS_ParseBootargs ( VOID  )

解析boot参数

在文件 los_bootargs.c158 行定义.

159{
160 INT32 idx = 0;
161 INT32 ret;
162 CHAR *args = NULL;
163 CHAR *argName = NULL;
164 CHAR *argValue = NULL;
165
166 ret = GetBootargs(&args);
167 if (ret != LOS_OK) {
168 return LOS_NOK;
169 }
170
171 while ((argValue = strsep(&args, " ")) != NULL) {
172 argName = strsep(&argValue, "=");
173 if (argValue == NULL) {
174 /* If the argument is not compliance with the format 'foo=bar' */
175 g_bootArgs[idx].argName = argName;
176 g_bootArgs[idx].argValue = argName;
177 } else {
178 g_bootArgs[idx].argName = argName;
179 g_bootArgs[idx].argValue = argValue;
180 }
181 if (++idx >= MAX_ARGS_NUM) {
182 /* Discard the rest arguments */
183 break;
184 }
185 }
186 return LOS_OK;
187}
STATIC INT32 GetBootargs(CHAR **args)
获取boot参数
Definition: los_bootargs.c:129
CHAR * argName
Definition: los_bootargs.h:47
函数调用图:

◆ LOS_SizeStrToNum()

UINT64 LOS_SizeStrToNum ( CHAR value)

在文件 los_bootargs.c212 行定义.

213{
214 UINT64 num = 0;
215
216 /* If the string is a hexadecimal value */
217 if (sscanf_s(value, "0x%llx", &num) > 0) {
218 value += strlen("0x");
219 if (strspn(value, "0123456789abcdefABCDEF") < strlen(value)) {
220 goto ERROUT;
221 }
222 return num;
223 }
224
225 /* If the string is a decimal value in unit *Bytes */
226 INT32 ret = sscanf_s(value, "%d", &num);
227 INT32 decOffset = strspn(value, "0123456789");
228 CHAR *endPos = value + decOffset;
229 if ((ret <= 0) || (decOffset < (strlen(value) - 1))) {
230 goto ERROUT;
231 }
232
233 if (strlen(endPos) == 0) {
234 return num;
235 } else if (strcasecmp(endPos, "k") == 0) {
236 num = num * BYTES_PER_KBYTE;
237 } else if (strcasecmp(endPos, "m") == 0) {
238 num = num * BYTES_PER_MBYTE;
239 } else if (strcasecmp(endPos, "g") == 0) {
240 num = num * BYTES_PER_GBYTE;
241 } else {
242 goto ERROUT;
243 }
244
245 return num;
246
247ERROUT:
248 PRINT_ERR("Invalid value string \"%s\"!\n", value);
249 return num;
250}
long unsigned int UINT64
Definition: los_typedef.h:66
这是这个函数的调用关系图:

◆ OsGetArgsAddr()

CHAR * OsGetArgsAddr ( VOID  )
这是这个函数的调用关系图: