• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "target_config.h"
16 #include "los_typedef.h"
17 
18 #include "stdlib.h"
19 #include "stdio.h"
20 #include "los_process_pri.h"
21 #include "disk.h"
22 #include "los_bootargs.h"
23 #include "los_rootfs.h"
24 #ifdef LOSCFG_DRIVERS_VIDEO
25 #include "fb.h"
26 #endif
27 #ifdef LOSCFG_SHELL
28 #include "shell.h"
29 #include "shcmd.h"
30 #endif
31 
32 #ifdef LOSCFG_DRIVERS_HDF_PLATFORM_UART
33 #include "console.h"
34 #include "hisoc/uart.h"
35 #endif
36 
37 #ifdef LOSCFG_DRIVERS_MEM
38 #include "los_dev_mem.h"
39 #endif
40 
41 #ifdef LOSCFG_DRIVERS_RANDOM
42 #include "los_random.h"
43 #include "hisoc/random.h"
44 #endif
45 
46 #ifdef LOSCFG_DRIVERS_HDF
47 #include "devmgr_service_start.h"
48 #endif
49 
50 #ifdef LOSCFG_DRIVERS_USB
51 #include "implementation/usb_init.h"
52 #endif
53 
54 #ifdef LOSCFG_DRIVERS_NETDEV
55 #include "lwip/tcpip.h"
56 #include "lwip/netif.h"
57 #include "lwip/netifapi.h"
58 
59 #define SLEEP_TIME_MS 60
60 #define NETIF_SETUP_OVERTIME 100
61 
net_init(void)62 void net_init(void)
63 {
64 extern void tcpip_init(tcpip_init_done_fn initfunc, void *arg);
65     dprintf("\ntcpip_init start\n");
66     tcpip_init(NULL, NULL);
67     dprintf("\ntcpip_init end\n");
68 }
69 #endif
70 
71 extern void SDK_init(void);
72 extern void CatLogShell(void);
73 
SystemInit(void)74 void SystemInit(void)
75 {
76     InitRebootHook();
77 
78 #ifdef LOSCFG_PLATFORM_HISI_AMP
79     extern int _ipcm_vdd_init(void);
80     dprintf("ipcm init ...\n");
81     _ipcm_vdd_init();
82 
83 #ifndef LOSCFG_ARCH_CORTEX_M7
84     extern int sharefs_client_init(const char *path);
85     dprintf("sharefs init ...\n");
86     sharefs_client_init("/sharefs");
87 #endif
88 
89     extern int virt_tty_dev_init(void);
90     dprintf("virt tty init ...\n");
91     virt_tty_dev_init();
92 #endif
93 
94 #ifdef LOSCFG_DRIVERS_RANDOM
95     dprintf("dev urandom init ...\n");
96     PlatformRandomOperationsInit();
97     DevUrandomRegister();
98 #endif
99 
100 #ifdef LOSCFG_DRIVERS_MEM
101     dprintf("dev mem init ...\n");
102     DevMemRegister();
103 #endif
104 
105 #ifndef LOSCFG_DRIVERS_HDF
106 #ifdef LOSCFG_DRIVERS_GPIO
107     dprintf("gpio init ...\n");
108     extern int gpio_dev_init(void);
109     gpio_dev_init();
110 #endif
111 #endif
112 
113 #ifdef LOSCFG_DRIVERS_HIEDMAC
114     extern int hiedmac_init(void);
115     hiedmac_init();
116 #endif
117 #ifdef LOSCFG_DRIVERS_HIDMAC
118     dprintf("dmac init ...\n");
119 #endif
120 
121 #ifdef LOSCFG_DRIVERS_MTD_NAND
122     dprintf("nand init ...\n");
123     extern int nand_init(void);
124 
125     if (!nand_init()) {
126         extern int add_mtd_partition(char *type, UINT32 start_addr, UINT32 length, UINT32 partition_num);
127 
128         extern int mount(const char *source, const char *target,
129                          const char *filesystemtype, unsigned long mountflags,
130                          const void *data);
131     }
132 
133 #endif
134 
135 #ifdef LOSCFG_DRIVERS_MTD_SPI_NOR
136     dprintf("spi nor flash init ...\n");
137     extern int spinor_init(void);
138     if (!spinor_init()) {
139         dprintf("spinor_init ...\n");
140     }
141 #endif
142 
143 #ifdef LOSCFG_DRIVERS_NETDEV
144     dprintf("net init ...\n");
145     net_init();
146     dprintf("\n************************************************************\n");
147 #endif
148 
149 #ifdef LOSCFG_DRIVERS_USB
150     dprintf("usb init ...\n");
151     usb_init(DEVICE, DEV_ETHERNET);
152 #endif
153 
154     dprintf("Date:%s.\n", __DATE__);
155     dprintf("Time:%s.\n", __TIME__);
156 
157 #ifndef LOSCFG_DRIVERS_HDF_PLATFORM_HISI_SDK
158     dprintf("calling SDK_init form HISI_SDK");
159     SDK_init();
160     dprintf("calling SDK_init form HISI_SDK done!");
161 #endif
162 
163 #ifdef LOSCFG_DRIVERS_HDF
164     dprintf("DeviceManagerStart start ...\n");
165     if (DeviceManagerStart()) {
166         PRINT_ERR("No drivers need load by hdf manager!");
167     }
168     dprintf("DeviceManagerStart end ...\n");
169 #endif
170 
171 #ifdef LOSCFG_PLATFORM_ROOTFS
172     dprintf("OsMountRootfs start ...\n");
173     if (LOS_GetCmdLine()) {
174         PRINT_ERR("get cmdline error!\n");
175     }
176     if (LOS_ParseBootargs()) {
177         PRINT_ERR("parse bootargs error!\n");
178     }
179     if (OsMountRootfs()) {
180         PRINT_ERR("mount rootfs error!\n");
181     }
182     dprintf("OsMountRootfs end ...\n");
183 #endif
184 
185 #ifdef LOSCFG_DRIVERS_HDF_PLATFORM_UART
186     dprintf("virtual_serial_init start ...\n");
187     if (virtual_serial_init(TTY_DEVICE) != 0) {
188         PRINT_ERR("virtual_serial_init failed");
189     }
190     dprintf("virtual_serial_init end ...\n");
191     if (system_console_init(SERIAL) != 0) {
192         PRINT_ERR("system_console_init failed\n");
193     }
194     dprintf("system_console_init end ...\n");
195 #endif
196 #ifdef LOSCFG_SHELL
197     dprintf("CatLogShell start ...\n");
198     CatLogShell();
199     dprintf("CatLogShell start ...\n");
200 #endif
201     dprintf("OsUserInitProcess start ...\n");
202     if (OsUserInitProcess()) {
203         PRINT_ERR("Create user init process faialed!\n");
204         return;
205     }
206     dprintf("OsUserInitProcess end ...\n");
207     return;
208 }
209