1# Running a Hello OHOS Program<a name="EN-US_TOPIC_0000001174270695"></a> 2 3- [Creating a Program](#section204672145202) 4- [Building](#section1077671315253) 5- [Burning](#section1347011412201) 6 - [Programming Flash Memory Through the Network Port](#section1935410617363) 7 8- [Running an Image](#section24721014162010) 9- [Running a Program](#section5276734182615) 10 11This section describes how to create, compile, burn, and run the first program, and finally print **Hello OHOS!** on the develop board. 12 13## Creating a Program<a name="section204672145202"></a> 14 151. Create a directory and the program source code. 16 17 Create the **applications/sample/camera/apps/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 **OHOS** to **World**. You can use either C or C++ to develop a program. 18 19 ``` 20 #include <stdio.h> 21 22 int main(int argc, char **argv) 23 { 24 printf("\n************************************************\n"); 25 printf("\n\t\tHello OHOS!\n"); 26 printf("\n************************************************\n\n"); 27 28 return 0; 29 } 30 ``` 31 322. Create a build file. 33 34 Create the **applications/sample/camera/apps/BUILD.gn** file. The file content is as follows: 35 36 ``` 37 import("//build/lite/config/component/lite_component.gni") 38 lite_component("hello-OHOS") { 39 features = [ ":helloworld" ] 40 } 41 executable("helloworld") { 42 output_name = "helloworld" 43 sources = [ "src/helloworld.c" ] 44 include_dirs = [] 45 defines = [] 46 cflags_c = [] 47 ldflags = [] 48 } 49 ``` 50 513. Add a new component. 52 53 Add the configuration of the **hello\_world\_app** component to the **build/lite/components/applications.json** file. The sample code below shows some configurations defined in the **applications.json** file, and the code between **\#\#start\#\#** and **\#\#end\#\#** is the new configuration \(Delete the rows where **\#\#start\#\#** and **\#\#end\#\#** are located after the configurations are added.\) 54 55 ``` 56 { 57 "components": [ 58 { 59 "component": "camera_sample_communication", 60 "description": "Communication related samples.", 61 "optional": "true", 62 "dirs": [ 63 "applications/sample/camera/communication" 64 ], 65 "targets": [ 66 "//applications/sample/camera/communication:sample" 67 ], 68 "rom": "", 69 "ram": "", 70 "output": [], 71 "adapted_kernel": [ "liteos_a" ], 72 "features": [], 73 "deps": { 74 "components": [], 75 "third_party": [] 76 } 77 }, 78 ##start## 79 { 80 "component": "hello_world_app", 81 "description": "Communication related samples.", 82 "optional": "true", 83 "dirs": [ 84 "applications/sample/camera/apps" 85 ], 86 "targets": [ 87 "//applications/sample/camera/apps:hello-OHOS" 88 ], 89 "rom": "", 90 "ram": "", 91 "output": [], 92 "adapted_kernel": [ "liteos_a" ], 93 "features": [], 94 "deps": { 95 "components": [], 96 "third_party": [] 97 } 98 }, 99 ##end## 100 { 101 "component": "camera_sample_app", 102 "description": "Camera related samples.", 103 "optional": "true", 104 "dirs": [ 105 "applications/sample/camera/launcher", 106 "applications/sample/camera/cameraApp", 107 "applications/sample/camera/setting", 108 "applications/sample/camera/gallery", 109 "applications/sample/camera/media" 110 ], 111 ``` 112 1134. Modify the board configuration file. 114 115 Add the **hello\_world\_app** component to the **vendor/hisilicon/hispark\_taurus/config.json** file. The sample code below shows the configurations of the **applications** subsystem, and the code between **\#\#start\#\#** and **\#\#end\#\#** is the new configuration \(Delete the rows where **\#\#start\#\#** and **\#\#end\#\#** are located after the configurations are added.\) 116 117 ``` 118 { 119 "subsystem": "applications", 120 "components": [ 121 { "component": "camera_sample_app", "features":[] }, 122 { "component": "camera_sample_ai", "features":[] }, 123 ##start## 124 { "component": "hello_world_app", "features":[] }, 125 ##end## 126 { "component": "camera_screensaver_app", "features":[] } 127 ] 128 }, 129 ``` 130 131 132## Building<a name="section1077671315253"></a> 133 134If the Linux environment is installed using Docker, perform the building by referring to [Using Docker to Prepare the Build Environment](../get-code/gettools-acquire.md#section107932281315). If the Linux environment is installed using a software package, go to the root directory of the source code and run the following commands for source code compilation: 135 136``` 137hb set (Set the building path.) 138. (Select the current path.) 139Select ipcamera_hispark_taurus@hisilicon and press Enter. 140hb build -f (Start building.) 141``` 142 143**Figure 1** Settings<a name="fig1458988766"></a> 144 145 146The result files are generated in the **out/hispark\_taurus/ipcamera\_hispark\_taurus** directory. 147 148> **NOTICE:** 149>The U-Boot file of the Hi3516D V300 development board can be obtained from the following path: device/hisilicon/hispark\_taurus/sdk\_liteos/uboot/out/boot/u-boot-hi3516dv300.bin 150 151## Burning<a name="section1347011412201"></a> 152 153The Hi3516 development board allows you to burn flash memory over the USB port, serial port, or network port. The following uses the network port burning as an example. 154 155### Programming Flash Memory Through the Network Port<a name="section1935410617363"></a> 156 157To program flash memory through the network port in the Windows or Linux environment: 158 1591. Connect the PC and the target development board through the serial port, network port, and power port. For details, see [Introduction to the Hi3516 Development Board](https://device.harmonyos.com/en/docs/start/introduce/oem_minitinier_des_3516-0000001152041033). 1602. <a name="en-us_topic_0000001056443961_li142386399535"></a>Open Device Manager, then check and record the serial port number corresponding to the development board. 161 162 > **NOTE:** 163 >If the serial port number is not displayed correctly, follow the steps described in [Installing the Serial Port Driver on the Hi3516 or Hi3518 Series Development Boards](https://device.harmonyos.com/en/docs/ide/user-guides/hi3516_hi3518-drivers-0000001050743695). 164 165  166 1673. Open DevEco Device Tool and go to **Projects** \> **Settings**. 168 169  170 1714. On the **Partition Configuration** tab page, modify the settings. In general cases, you can leave the fields at their default settings. 1725. On the **hi3516dv300** tab page, configure the programming options. 173 174 - **upload\_port**: Select the serial port number obtained in step [2](#en-us_topic_0000001056443961_li142386399535). 175 - **upload\_protocol**: Select the programming protocol **hiburn-net**. 176 - **upload\_partitions**: Select the file to be programmed. By default, the **fastboot**, **kernel**, **rootfs**, and **userfs** files are programmed at the same time. 177 178  179 1806. <a name="en-us_topic_0000001056443961_li1558813168234"></a>Check and set the IP address of the network adapter connected to the development board. For details, see [Setting the IP Address of the Network Port for Programming on Hi3516](https://device.harmonyos.com/en/docs/ide/user-guides/set_ipaddress-0000001141825075). 1817. Set the IP address of the network port for programming: 182 183 - **upload\_net\_server\_ip**: Select the IP address set in step [6](#en-us_topic_0000001056443961_li1558813168234), such as 192.168.1.2. 184 - **upload\_net\_client\_mask**: Set the subnet mask of the development board, such as 255.255.255.0. Once the **upload\_net\_server\_ip** field is set, this field will be automatically populated. 185 - **upload\_net\_client\_gw**: Set the gateway of the development board, such as 192.168.1.1. Once the **upload\_net\_server\_ip** field is set, this field will be automatically populated. 186 - **upload\_net\_client\_ip**: Set the IP address of the development board, such as 192.168.1.3. Once the **upload\_net\_server\_ip** field is set, this field will be automatically populated. 187 188  189 1908. When you finish modifying, click **Save** in the upper right corner. 1919. Open the project file and go to  \> **PROJECT TASKS** \> **hi3516dv300** \> **Upload** to start programming. 192 193  194 19510. When the following message is displayed, power off the development board and then power it on. 196 197  198 19911. Start programming. If the following message is displayed, it indicates that the programming is successful. 200 201  202 203 204## Running an Image<a name="section24721014162010"></a> 205 2061. Connect to a serial port. 207 208 > **NOTICE:** 209 >If the connection fails, rectify the fault by referring to [FAQs](quickstart-lite-steps-hi3516-faqs.md). 210 211 **Figure 2** Serial port connection<a name="fig139171488431"></a> 212  213 214 1. Click **Monitor** to enable the serial port. 215 2. Press **Enter** repeatedly until **hisilicon** displays. 216 3. Go to step [2](#l5b42e79a33ea4d35982b78a22913b0b1) if the board is started for the first time or the startup parameters need to be modified; go to step [3](#ld26f18828aa44c36bfa36be150e60e49) otherwise. 217 2182. <a name="l5b42e79a33ea4d35982b78a22913b0b1"></a>\(Mandatory when the board is started for the first time\) Modify the bootcmd and bootargs parameters of U-Boot. You need to perform this step only once if the parameters need not to be modified during the operation. The board automatically starts after it is reset. 219 220 > **NOTICE:** 221 >The default waiting time in the U-Boot is 2s. You can press **Enter** to interrupt the waiting and run the **reset** command to restart the system after "hisilicon" is displayed. 222 223 **Table 1** Parameters of the U-Boot 224 225 <a name="table1323441103813"></a> 226 <table><thead align="left"><tr id="row1423410183818"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p623461163818"><a name="p623461163818"></a><a name="p623461163818"></a>Command</p> 227 </th> 228 <th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p42341014388"><a name="p42341014388"></a><a name="p42341014388"></a>Description</p> 229 </th> 230 </tr> 231 </thead> 232 <tbody><tr id="row1623471113817"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p102341719385"><a name="p102341719385"></a><a name="p102341719385"></a>setenv bootcmd "mmc read 0x0 0x80000000 0x800 0x4800; go 0x80000000";</p> 233 </td> 234 <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p92347120389"><a name="p92347120389"></a><a name="p92347120389"></a>Run this command to read content that has a size of 0x4800 (9 MB) and a start address of 0x800 (1 MB) to the memory address 0x80000000. The file size must be the same as that of the <strong id="b9140538191313"><a name="b9140538191313"></a><a name="b9140538191313"></a>OHOS_Image.bin</strong> file in the IDE.</p> 235 </td> 236 </tr> 237 <tr id="row12234912381"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p172306219392"><a name="p172306219392"></a><a name="p172306219392"></a>setenv bootargs "console=ttyAMA0,115200n8 root=emmc fstype=vfat rootaddr=10M rootsize=20M rw";</p> 238 </td> 239 <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p13489329396"><a name="p13489329396"></a><a name="p13489329396"></a>Run this command to set the output mode to serial port output, baud rate to <strong id="b1378372812210"><a name="b1378372812210"></a><a name="b1378372812210"></a>115200</strong>, data bit to <strong id="b27871628822"><a name="b27871628822"></a><a name="b27871628822"></a>8</strong>, <strong id="b678811281528"><a name="b678811281528"></a><a name="b678811281528"></a>rootfs</strong> to be mounted to the <strong id="b978813281220"><a name="b978813281220"></a><a name="b978813281220"></a>emmc</strong> component, and file system type to <strong id="b12788132814217"><a name="b12788132814217"></a><a name="b12788132814217"></a>vfat</strong>.</p> 240 <p id="p12481832163913"><a name="p12481832163913"></a><a name="p12481832163913"></a><strong id="b965011165313"><a name="b965011165313"></a><a name="b965011165313"></a>rootaddr=10M rootsize=20M rw</strong> indicates the start address and size of the <strong id="b1538675832018"><a name="b1538675832018"></a><a name="b1538675832018"></a>rootfs.img</strong> file to be burnt, respectively. The file size <strong id="b0633135515546"><a name="b0633135515546"></a><a name="b0633135515546"></a>must be the same</strong> as that of the <strong id="b69061726113015"><a name="b69061726113015"></a><a name="b69061726113015"></a>rootfs.img</strong> file in the IDE.</p> 241 </td> 242 </tr> 243 <tr id="row18234161153820"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p823417118386"><a name="p823417118386"></a><a name="p823417118386"></a>saveenv</p> 244 </td> 245 <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p32341616389"><a name="p32341616389"></a><a name="p32341616389"></a><strong id="b16238195319315"><a name="b16238195319315"></a><a name="b16238195319315"></a>saveenv</strong> means to save the current configuration.</p> 246 </td> 247 </tr> 248 <tr id="row192345113811"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p7235111183819"><a name="p7235111183819"></a><a name="p7235111183819"></a>reset</p> 249 </td> 250 <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p123781411114016"><a name="p123781411114016"></a><a name="p123781411114016"></a><strong id="b32719232420"><a name="b32719232420"></a><a name="b32719232420"></a>reset</strong> means to reset the board.</p> 251 </td> 252 </tr> 253 </tbody> 254 </table> 255 256 > **NOTICE:** 257 >**go 0x80000000** \(optional\) indicates that the command is fixed in the startup parameters by default and the board automatically starts after it is reset. If you want to manually start the board, press **Enter** in the countdown phase of the U-Boot startup to interrupt the automatic startup. 258 2593. <a name="ld26f18828aa44c36bfa36be150e60e49"></a>Run the **reset** command and press **Enter** to restart the board. After the board is restarted, **OHOS** is displayed when you press **Enter**. 260 261 **Figure 3** System startup<a name="fig784813366444"></a> 262  263 264 265## Running a Program<a name="section5276734182615"></a> 266 267In the root directory, run the **./bin/helloworld** command to operate the demo program. The compilation result is shown in the following example. 268 269**Figure 4** Successful system startup and program execution<a name="fig149821431194515"></a> 270 271 272