1# Getting Started with the Standard System with Hi3516 (CLI Mode) 2 3> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** 4> 5> Since OpenHarmony 3.2, the standard system does not perform adaptation verification for the Hi3516D V300 development board. You are advised to use RK3568 to develop standard-system devices. 6> 7> If you still need to use Hi3516DV300 to develop standard-system devices, adaptation may fail. In this case, contact the chip supplier to obtain the adaptation guide or complete adaptation by yourself. 8 9 10 11In addition to the small system, the Hi3516D V300 development board also supports the standard system. This topic describes how to develop the standard system on Hi3516DV300 by using the command-line interface (CLI). 12 13 14The following exemplifies how to run the first program on the development board. The created program outputs the message "Hello World!" 15 16 17Before development, [set up the development environment](quickstart-pkg-prepare.md). 18 19 20## Writing a Hello World Program 21 22 23### Example Directory 24 25 26``` 27applications/sample/hello 28 │── BUILD.gn 29 │── include 30 │ └── helloworld.h 31 │── src 32 │ └── helloworld.c 33 ├── bundle.json 34 build 35 └── subsystem_config.json 36 vendor/hisilicon 37 └── Hi3516DV300 38 └── config.json 39``` 40 41 42### How to Develop 43 44Perform the steps below in the source code directory: 45 461. Create a directory and write the service code. 47 48 Create the **applications/sample/hello/src/helloworld.c** directory and file whose code is shown in the following example. You can customize the content to be printed. For example, you can change **World** to **OHOS**. Declare the string printing function **HelloPrint** in the **helloworld.h** file. You can use either C or C++ to develop a program. 49 50 51 ``` 52 #include <stdio.h> 53 #include "helloworld.h" 54 int main(int argc, char **argv) 55 { 56 HelloPrint(); 57 return 0; 58 } 59 void HelloPrint() 60 { 61 printf("\n\n"); 62 printf("\n\t\tHello World!\n"); 63 printf("\n\n"); 64 } 65 ``` 66 67 Add the header file **applications/sample/hello/include/helloworld.h**. The sample code is as follows: 68 69 70 ``` 71 #ifndef HELLOWORLD_H 72 #define HELLOWORLD_H 73 #ifdef __cplusplus 74 #if __cplusplus 75 extern "C" { 76 #endif 77 #endif 78 void HelloPrint(); 79 #ifdef __cplusplus 80 #if __cplusplus 81 } 82 #endif 83 #endif 84 #endif // HELLOWORLD_H 85 ``` 86 872. Create a build file. 88 1. Create the **applications/sample/hello/BUILD.gn** file. The file content is as follows: 89 90 ``` 91 import("//build/ohos.gni") # Import the build template. 92 ohos_executable("helloworld") {# Executable module. 93 sources = [ # Source code of the module. 94 "src/helloworld.c" 95 ] 96 include_dirs = [ # Directory of header files on which the module depends. 97 "include" 98 ] 99 cflags = [] 100 cflags_c = [] 101 cflags_cc = [] 102 ldflags = [] 103 configs = [] 104 deps =[] # Internal dependencies of the component. 105 part_name = "hello" # Component name. This parameter is mandatory. 106 install_enable = true # Whether to install the software by default. This parameter is optional. By default, the software is not installed. 107 } 108 ``` 109 2. Create the **applications/sample/hello/bundle.json** file and add the description of the **sample** component. The content is as follows: 110 111 ``` 112 { 113 "name": "@ohos/hello", 114 "description": "Hello world example.", 115 "version": "3.1", 116 "license": "Apache License 2.0", 117 "publishAs": "code-segment", 118 "segment": { 119 "destPath": "applications/sample/hello" 120 }, 121 "dirs": {}, 122 "scripts": {}, 123 "component": { 124 "name": "hello", 125 "subsystem": "sample", 126 "syscap": [], 127 "features": [], 128 "adapted_system_type": [ "mini", "small", "standard" ], 129 "rom": "10KB", 130 "ram": "10KB", 131 "deps": { 132 "components": [], 133 "third_party": [] 134 }, 135 "build": { 136 "sub_component": [ 137 "//applications/sample/hello:helloworld" 138 ], 139 "inner_kits": [], 140 "test": [] 141 } 142 } 143 } 144 ``` 145 146 The **bundle.json** file consists of two parts. The first part describes the information about the subsystem to which the component belongs, and the second part defines the build configuration for the component. When adding a component, you must specify the **sub_component** of the component. If there are APIs provided for other components, add them in **inner_kits**. If there are test cases, add them in **test**. 147 1483. Modify the subsystem configuration file. 149 150 Add the configuration of the new subsystem to the **build/subsystem_config.json** file. 151 152 153 ``` 154 "sample": { 155 "path": "applications/sample/hello", 156 "name": "sample" 157 }, 158 ``` 159 1604. Modify the product configuration file. 161 162 In the **vendor/hisilicon/Hi3516DV300/config.json** file, add the **hello** part after the existing part. 163 164 165 ``` 166 "usb:usb_manager_native":{}, 167 "applications:prebuilt_hap":{}, 168 "sample:hello":{}, 169 "wpa_supplicant-2.9:wpa_supplicant-2.9":{}, 170 ``` 171 172 173## Building Source Code 174 175You can build source code with hb or the **build.sh** script. The following exemplifies how to build source code with hb. For details about how to build source code with the **build.sh** script, see [Building Source Code Using the build.sh Script](quickstart-pkg-common-build.md). 176 177For details about the functions of the OpenHarmony compilation and building module, see [Compilation and Building Guide](../subsystems/subsys-build-all.md). 178 179 180### Prerequisites 181 182- The [required libraries and tools](quickstart-pkg-install-package.md) have been installed. 183 184- The [compilation tools](quickstart-pkg-install-tool.md) have been installed. 185 186- A **Hello World** program has been created with code written. 187 188- The access to the Ubuntu environment is normal. 189 190 191### Procedure 192 193Go to the root directory of the source code and run the build command. 194 1951. Set the build path. 196 197 ``` 198 hb set 199 ``` 200 2012. Select the current path. 202 203 ``` 204 . 205 ``` 206 2073. Select **hispark_taurus_standard** under **hisilicon** and press **Enter**. 208 > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** 209 > 210 > When adapting the development board to a specific use case, select an appropriate build form factor, that is, **product** settings. For details, see [Build Form Factors](quickstart-appendix-compiledform.md). 211 212 **Figure 1** Hi3516 build settings 213 214 ![quick-start-hi3516-standard-build](figures/quick-start-hi3516-standard-build.png) 215 2164. Start building. 217 > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** 218 > - To build a component (for example, **hello**), run the **hb build -T *targetName*** command. 219 > 220 > - To build a product incrementally, run the **hb build** command. 221 > 222 > - To build a product from the scratch, run the **hb build -f** command. 223 > 224 > This example builds a product from the scratch. 225 226 227 ``` 228 hb build -f 229 ``` 230 2315. Check the build result. If "build success" is displayed, the building is successful. 232 > ![icon-notice.gif](public_sys-resources/icon-notice.gif) **NOTICE** 233 > 234 > The build result and log files are stored in **out/hi3516dv300**. 235 236 237## Burning an Image 238 239The following exemplifies how to burn an image to Hi3516DV300 using HiTool. You can also do so using DevEco Device Tool, by following instructions in [Burning an Image](quickstart-appendix-hi3516-ide.md#burning-an-image). 240 241 242### Prerequisites 243 244- The source code of the development board has been compiled into files for burning. 245 246- [HiTool](http://www.hihope.org/download/download.aspx) has been installed on the client platform (for example, a Windows-based computer). 247 248- The USB port driver has been installed on the client platform. For details, see [Installing the USB Port Driver on the Hi3516D V300 Development Board](https://device.harmonyos.com/en/docs/documentation/guide/usb_driver-0000001058690393). 249 250- A serial port terminal tool, such as IPOP, has been installed on the client platform. 251 252- The client platform and development board are connected using a USB cable and serial cable. 253 254 255### Procedure 256 2571. Prepare the files to be burnt. 258 1. On the client platform, create a folder for storing the files to be burnt, for example, **D:\L2**. 259 2. Download the compiled source package to the client platform, decompress the package, and copy the files required for burning to the folder created in step 1. 260 261 For the Hi3516DV300 development board, the files required for burning of the standard system are as follows: **boot.img**, **Hi3516DV300-emmc.xml**, **system.img**, **u-boot-hi3516dv300_emmc.bin**, **uImage**, **updater.img**, **userdata.img**, and **vendor.img**. 262 2632. Burn the image files using HiTool. 264 1. Open HiTool. 265 2. Set up HiTool. 266 267 Set the transfer mode to USB and burning mode to eMMC (the storage medium of the development board is eMMC). 268 3. Click **Browse** and select the burning configuration file (for example, **Hi3516DV300-emmc.xml**) from the folder created in step 1. 269 270 ![quickstart-hi3516-standard-hitool-select](figures/quickstart-hi3516-standard-hitool-select.png) 271 4. After clicking the **Burn** button, press and hold the **Update** key next to the serial port on the development board, and remove and insert the USB cable. 272 273 After the burning starts, logs are displayed in the console area at the bottom of HiTool. 274 275 When the burning is complete, HiTool displays a dialog box indicating that the burning is successful. 276 5. Click **OK**. 277 2783. Import startup parameters. 279 1. Use the terminal tool to enable the serial port. 280 2. Restart the development board by removing and inserting its power supply. Press **Enter** in the serial port terminal tool within 3 seconds. 281 282 If **hisilicon \#** is displayed on the terminal tool page, the serial port of the development board is connected. 283 3. Copy the following startup parameters in the serial port terminal tool and press **Enter** to complete the setup. 284 285 ``` 286 setenv bootargs 'mem=640M console=ttyAMA0,115200 mmz=anonymous,0,0xA8000000,384M clk_ignore_unused androidboot.selinux=permissive rootdelay=10 hardware=Hi3516DV300 init=/init root=/dev/ram0 rw blkdevparts=mmcblk0:1M(boot),15M(kernel),20M(updater),2M(misc),3307M(system),256M(vendor),-(userdata)';setenv bootcmd 'mmc read 0x0 0x82000000 0x800 0x4800; bootm 0x82000000' 287 288 saveenv 289 290 reset 291 ``` 292 293 > ![icon-notice.gif](public_sys-resources/icon-notice.gif) **NOTICE** 294 > 295 > When entering startup parameters, do not delete blank lines. 296 297 298## Running an Image 299 300After the system is started, copy the executable file **helloworld** in the **out** directory of the source code to the **bin** directory, and run the Hello World program as follows: 301 302 303### Procedure 304 3051. Go to the **bin** directory on the startup page. 306 307 ``` 308 cd bin 309 ``` 310 3112. Run the following command to run the **helloworld** program: 312 313 ``` 314 ./helloworld 315 ``` 316 317 If the message "Hello World!" is displayed, the program runs successfully. 318 319 320### Next 321 322Congratulations! You have finished all steps! Proceed to [develop a sample](../guide/device-clock-guide.md) to better familiarize yourself with OpenHarmony development. 323