• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2022 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 #include "stdarg.h"
33 #include "los_arch.h"
34 #include "los_config.h"
35 #include "los_debug.h"
36 #include "los_memory.h"
37 #include "los_mux.h"
38 #include "los_queue.h"
39 #include "los_sem.h"
40 
41 #if (LOSCFG_PLATFORM_HWI == 1)
42 #include "los_interrupt.h"
43 #endif
44 
45 #if (LOSCFG_BASE_CORE_SWTMR == 1)
46 #include "los_swtmr.h"
47 #endif
48 
49 #if (LOSCFG_BASE_CORE_CPUP == 1)
50 #include "los_cpup.h"
51 #endif
52 
53 #if (LOSCFG_PLATFORM_EXC == 1)
54 #include "los_exc_info.h"
55 #endif
56 
57 #if (LOSCFG_BACKTRACE_TYPE != 0)
58 #include "los_backtrace.h"
59 #endif
60 
61 #if (LOSCFG_KERNEL_PM == 1)
62 #include "los_pm.h"
63 #endif
64 
65 #if (LOSCFG_DYNLINK == 1)
66 #include "los_dynlink.h"
67 #endif
68 
69 #ifdef LOSCFG_KERNEL_LMS
70 #include "los_lms_pri.h"
71 #endif
72 
73 #if (LOSCFG_KERNEL_LMK == 1)
74 #include "los_lmk.h"
75 #endif
76 
77 #if (LOSCFG_POSIX_PIPE_API == 1)
78 #include "pipe_impl.h"
79 #endif
80 
81 #if (LOSCFG_KERNEL_SIGNAL == 1)
82 #include "los_signal.h"
83 #endif
84 
85 #if (LOSCFG_SECURE == 1)
86 #include "los_syscall.h"
87 #include "los_box.h"
88 #endif
89 
90 #if (LOSCFG_FS_VFS == 1)
91 #include "vfs_operations.h"
92 #endif
93 
94 #if (LOSCFG_KERNEL_TRACE == 1)
95 #include "los_trace_pri.h"
96 #endif
97 
98 /*****************************************************************************
99  Function    : LOS_Reboot
100  Description : system exception, die in here, wait for watchdog.
101  Input       : None
102  Output      : None
103  Return      : None
104  *****************************************************************************/
LOS_Reboot(VOID)105 LITE_OS_SEC_TEXT_INIT VOID LOS_Reboot(VOID)
106 {
107     OsDoExcHook(EXC_REBOOT);
108     ArchSysExit();
109 }
110 
LOS_Panic(const CHAR * fmt,...)111 LITE_OS_SEC_TEXT_INIT VOID LOS_Panic(const CHAR *fmt, ...)
112 {
113     va_list ap;
114     va_start(ap, fmt);
115     PRINT_ERR(fmt, ap);
116     va_end(ap);
117     OsDoExcHook(EXC_PANIC);
118 #if (LOSCFG_BACKTRACE_TYPE != 0)
119     LOS_BackTrace();
120 #endif
121     ArchSysExit();
122 }
123 
LOS_Start(VOID)124 LITE_OS_SEC_TEXT_INIT UINT32 LOS_Start(VOID)
125 {
126     return ArchStartSchedule();
127 }
128 
129 /*****************************************************************************
130  Function    : LOS_KernelInit
131  Description : System kernel initialization function, configure all system modules
132  Input       : None
133  Output      : None
134  Return      : LOS_OK on success or error code on failure
135  *****************************************************************************/
LOS_KernelInit(VOID)136 LITE_OS_SEC_TEXT_INIT UINT32 LOS_KernelInit(VOID)
137 {
138     UINT32 ret;
139     PRINTK("entering kernel init...\n");
140 
141 #if (LOSCFG_BACKTRACE_TYPE != 0)
142     OsBackTraceInit();
143 #endif
144 
145 #ifdef LOSCFG_KERNEL_LMS
146     OsLmsInit();
147 #endif
148     ret = OsMemSystemInit();
149     if (ret != LOS_OK) {
150         PRINT_ERR("OsMemSystemInit error %d\n", ret);
151         return ret;
152     }
153 
154     ArchInit();
155 
156     ret = OsTickTimerInit();
157     if (ret != LOS_OK) {
158         PRINT_ERR("OsTickTimerInit error! 0x%x\n", ret);
159         return ret;
160     }
161 
162     ret = OsTaskInit();
163     if (ret != LOS_OK) {
164         PRINT_ERR("OsTaskInit error\n");
165         return ret;
166     }
167 
168 #if (LOSCFG_BASE_CORE_TSK_MONITOR == 1)
169     OsTaskMonInit();
170 #endif
171 
172 #if (LOSCFG_BASE_CORE_CPUP == 1)
173     ret = OsCpupInit();
174     if (ret != LOS_OK) {
175         PRINT_ERR("OsCpupInit error\n");
176         return ret;
177     }
178 #endif
179 
180 #if (LOSCFG_BASE_IPC_SEM == 1)
181     ret = OsSemInit();
182     if (ret != LOS_OK) {
183         return ret;
184     }
185 #endif
186 
187 #if (LOSCFG_BASE_IPC_MUX == 1)
188     ret = OsMuxInit();
189     if (ret != LOS_OK) {
190         return ret;
191     }
192 #endif
193 
194 #if (LOSCFG_BASE_IPC_QUEUE == 1)
195     ret = OsQueueInit();
196     if (ret != LOS_OK) {
197         PRINT_ERR("OsQueueInit error\n");
198         return ret;
199     }
200 #endif
201 
202 #if (LOSCFG_BASE_CORE_SWTMR == 1)
203     ret = OsSwtmrInit();
204     if (ret != LOS_OK) {
205         PRINT_ERR("OsSwtmrInit error\n");
206         return ret;
207     }
208 #endif
209 
210 #if (LOSCFG_CPUP_INCLUDE_IRQ == 1)
211     ret = OsCpupDaemonInit();
212     if (ret != LOS_OK) {
213         PRINT_ERR("OsCpupDaemonInit error\n");
214         return ret;
215     }
216 #endif
217 
218 #if (LOSCFG_FS_VFS == 1)
219     ret = OsVfsInit();
220     if (ret != LOS_OK) {
221         PRINT_ERR("OsVfsInit error\n");
222         return ret;
223     }
224 #endif
225 
226     ret = OsIdleTaskCreate();
227     if (ret != LOS_OK) {
228         return ret;
229     }
230 
231 #if (LOSCFG_KERNEL_TRACE == 1)
232     ret = OsTraceInit();
233     if (ret != LOS_OK) {
234         PRINT_ERR("OsTraceInit error\n");
235         return ret;
236     }
237 #endif
238 
239 #if (LOSCFG_KERNEL_PM == 1)
240     ret = OsPmInit();
241     if (ret != LOS_OK) {
242         PRINT_ERR("Pm init failed!\n");
243         return ret;
244     }
245 #endif
246 
247 #if (LOSCFG_KERNEL_LMK == 1)
248     OsLmkInit();
249 #endif
250 
251 #if (LOSCFG_PLATFORM_EXC == 1)
252     OsExcMsgDumpInit();
253 #endif
254 
255 #if (LOSCFG_DYNLINK == 1)
256     ret = LOS_DynlinkInit();
257     if (ret != LOS_OK) {
258         return ret;
259     }
260 #endif
261 
262 #if (LOSCFG_POSIX_PIPE_API == 1)
263     ret = OsPipeInit();
264     if (ret != LOS_OK) {
265         PRINT_ERR("Pipe init failed!\n");
266         return ret;
267     }
268 #endif
269 
270 #if (LOSCFG_KERNEL_SIGNAL == 1)
271     ret = OsSignalInit();
272     if (ret != LOS_OK) {
273         PRINT_ERR("Signal init failed!\n");
274         return ret;
275     }
276 #endif
277 
278 #if (LOSCFG_SECURE == 1)
279     OsSyscallHandleInit();
280     LOS_BoxStart();
281 #endif
282 
283     return LOS_OK;
284 }
285 
286