1# Running a Hello OHOS Program<a name="EN-US_TOPIC_0000001174350607"></a> 2 3- [Creating a Program](#section1550972416485) 4- [Building](#section234175193114) 5- [Burning](#section7609155824819) 6- [Running an Image](#section17612105814480) 7- [Follow-up Learning](#section9712145420182) 8 9This section describes how to create, compile, burn, and run the first program, and finally print **Hello OHOS!** on the develop board. 10 11## Creating a Program<a name="section1550972416485"></a> 12 131. Create a directory and the program source code. 14 15 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. 16 17 ``` 18 #include <stdio.h> 19 20 int main(int argc, char **argv) 21 { 22 printf("\n************************************************\n"); 23 printf("\n\t\tHello OHOS!\n"); 24 printf("\n************************************************\n\n"); 25 26 return 0; 27 } 28 ``` 29 302. Create a build file. 31 32 Create the **applications/sample/camera/apps/BUILD.gn** file. The file content is as follows: 33 34 ``` 35 import("//build/lite/config/component/lite_component.gni") 36 lite_component("hello-OHOS") { 37 features = [ ":helloworld" ] 38 } 39 executable("helloworld") { 40 output_name = "helloworld" 41 sources = [ "src/helloworld.c" ] 42 include_dirs = [] 43 defines = [] 44 cflags_c = [] 45 ldflags = [] 46 } 47 ``` 48 493. Add a component. 50 51 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.\) 52 53 ``` 54 { 55 "components": [ 56 { 57 "component": "camera_sample_communication", 58 "description": "Communication related samples.", 59 "optional": "true", 60 "dirs": [ 61 "applications/sample/camera/communication" 62 ], 63 "targets": [ 64 "//applications/sample/camera/communication:sample" 65 ], 66 "rom": "", 67 "ram": "", 68 "output": [], 69 "adapted_kernel": [ "liteos_a" ], 70 "features": [], 71 "deps": { 72 "components": [], 73 "third_party": [] 74 } 75 }, 76 ##start## 77 { 78 "component": "hello_world_app", 79 "description": "Communication related samples.", 80 "optional": "true", 81 "dirs": [ 82 "applications/sample/camera/apps" 83 ], 84 "targets": [ 85 "//applications/sample/camera/apps:hello-OHOS" 86 ], 87 "rom": "", 88 "ram": "", 89 "output": [], 90 "adapted_kernel": [ "liteos_a" ], 91 "features": [], 92 "deps": { 93 "components": [], 94 "third_party": [] 95 } 96 }, 97 ##end## 98 { 99 "component": "camera_sample_app", 100 "description": "Camera related samples.", 101 "optional": "true", 102 "dirs": [ 103 "applications/sample/camera/launcher", 104 "applications/sample/camera/cameraApp", 105 "applications/sample/camera/setting", 106 "applications/sample/camera/gallery", 107 "applications/sample/camera/media" 108 ], 109 ``` 110 1114. Modify the board configuration file. 112 113 Add the **hello\_world\_app** component to the **vendor/hisilicon/hispark\_aries/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.\) 114 115 ``` 116 { 117 "subsystem": "applications", 118 "components": [ 119 ##start## 120 { "component": "hello_world_app", "features":[] }, 121 ##end## 122 { "component": "camera_sample_app", "features":[] } 123 124 ] 125 }, 126 ``` 127 128 129## Building<a name="section234175193114"></a> 130 131If 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: 132 133``` 134hb set (Set the building path.) 135. (Select the current path.) 136Select ipcamera_hispark_aries@hisilicon and press Enter. 137hb build -f (Start building.) 138``` 139 140The result files are generated in the **out/hispark\_aries/ipcamera\_hispark\_aries** directory. 141 142**Figure 1** Settings<a name="fig1766174411418"></a> 143 144 145> **NOTICE:** 146>The U-Boot file of the Hi3518E V300 development board can be obtained from the following path: device/hisilicon/hispark\_aries/sdk\_liteos/uboot/out/boot/u-boot-hi3518ev300.bin 147 148## Burning<a name="section7609155824819"></a> 149 150Programming the flash memory is the process of downloading compiled program files to a chipset development board to provide a basis for subsequent debugging. With the one-click flash memory programming function of DevEco Device Tool, you can program flash memory on development boards quickly and efficiently. 151 152The Hi3518E V300 development board allows you to program flash memory through the USB port or serial port. 153 154- **Windows system: Supports programming through the USB port or serial port** 155- **Linux system: Supports programming through the serial port \(Linux+Windows dual system: Supports programming through the serial port or USB port\)** 156 157Except for environment setup, the operations of programming are the same for Windows and Linux. 158 159The following uses the USB port burning as an example. 160 1611. Connect the PC and the target development board through the serial port and USB port. For details, see [Introduction to the Hi3518 Development Board](https://device.harmonyos.com/en/docs/start/introduce/oem_minitinier_des_3518-0000001105201138). 1622. <a name="en-us_topic_0000001057313128_li46411811196"></a>Open Device Manager, then check and record the serial port number corresponding to the development board. 163 164 > **NOTE:** 165 >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). 166 167  168 1693. Open DevEco Device Tool and go to **Projects** \> **Settings**. 170 171  172 1734. On the **Partition Configuration** tab page, modify the settings. In general cases, you can leave the fields at their default settings. 1745. On the **hi3518ev300** tab page, set the programming options. 175 176 - **upload\_port**: Select the serial port number obtained in step [2](#en-us_topic_0000001057313128_li46411811196). 177 - **upload\_protocol**: Select the programming protocol **hiburn-usb**. 178 - **upload\_partitions**: Select the file to be programmed. By default, the **fastboot**, **kernel**, **rootfs**, and **userfs** files are programmed at the same time. 179 180  181 1826. When you finish modifying, click **Save** in the upper right corner. 1837. Open the project file, go to  \> **PROJECT TASKS** \> **hi3518ev300\_fastboot** \> **Erase** to erase U-Boot. 184 185  186 1878. When the following message is displayed, power off the development board and then power it on. 188 189  190 1919. If the following message is displayed, it indicates that U-Boot is erased successfully. 192 193  194 19510. Go to **hi3518ev300** \> **Upload** to start programming. 196 197  198 19911. If the following message is displayed, it indicates that the programming is successful. 200 201  202 203 204## Running an Image<a name="section17612105814480"></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-hi3518-faqs.md#en-us_topic_0000001053466255_section14871149155911). 210 211 **Figure 2** Serial port connection<a name="fig049019841616"></a> 212  213 214 1. Click **Monitor** to enable the serial port. The **TERMINAL** window is displayed. 215 2. Press **Enter** repeatedly until **hisilicon** displays. 216 3. Go to [step 2](#li9441185382314) if the board is started for the first time or the startup parameters need to be modified; go to [step 3](#li6442853122312) otherwise. 217 2182. <a name="li9441185382314"></a>\(Mandatory for first-time burning\) Modify the **bootcmd** and **bootargs** parameters of U-Boot. This step is a fixed operation and the result can be saved. However, you need to perform the following steps again if U-Boot needs to be reburnt. 219 220 **Table 1** Parameters of the U-Boot 221 222 <a name="table1336762011222"></a> 223 <table><thead align="left"><tr id="row193681920182219"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p3368202016229"><a name="p3368202016229"></a><a name="p3368202016229"></a>Command</p> 224 </th> 225 <th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p936812052217"><a name="p936812052217"></a><a name="p936812052217"></a>Description</p> 226 </th> 227 </tr> 228 </thead> 229 <tbody><tr id="row10368142032210"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1636882092214"><a name="p1636882092214"></a><a name="p1636882092214"></a>setenv bootcmd "sf probe 0;sf read 0x40000000 0x100000 0x600000;go 0x40000000";</p> 230 </td> 231 <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p17368202082213"><a name="p17368202082213"></a><a name="p17368202082213"></a>Run this command to set the content of <strong id="b209671361282"><a name="b209671361282"></a><a name="b209671361282"></a>bootcmd</strong>. Select the flash whose number is 0, and read content that has a size of 0x600000 (6 MB) and a start address of 0x100000 to memory address 0x40000000. The size must be the same as that of the <strong id="b12634352103017"><a name="b12634352103017"></a><a name="b12634352103017"></a>OHOS_Image.bin</strong> file in the IDE.</p> 232 </td> 233 </tr> 234 <tr id="row136814209227"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p234414019231"><a name="p234414019231"></a><a name="p234414019231"></a>setenv bootargs "console=ttyAMA0,115200n8 root=flash fstype=jffs2 rw rootaddr=7M rootsize=8M";</p> 235 </td> 236 <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p10368102010223"><a name="p10368102010223"></a><a name="p10368102010223"></a>In this command, <strong id="b1475793912349"><a name="b1475793912349"></a><a name="b1475793912349"></a>bootargs</strong> is set to the serial port output, the baud rate is <strong id="b1310782917185"><a name="b1310782917185"></a><a name="b1310782917185"></a>115200</strong>, the data bit is <strong id="b149010367189"><a name="b149010367189"></a><a name="b149010367189"></a>8</strong>, and the <strong id="b19757173918344"><a name="b19757173918344"></a><a name="b19757173918344"></a>rootfs</strong> is mounted to the flash memory. The file system type is set to <strong id="b875763919342"><a name="b875763919342"></a><a name="b875763919342"></a>jffs2 rw</strong>, which provides the read-write attribute for the JFFS2 file system. <strong id="b186911414141517"><a name="b186911414141517"></a><a name="b186911414141517"></a>rootaddr=7M rootsize=8M</strong> indicates the actual start address and length of the <strong id="b841582383217"><a name="b841582383217"></a><a name="b841582383217"></a>rootfs.img</strong> file to be burnt, respectively. The file size must be the same as that of the <strong id="b51690521108"><a name="b51690521108"></a><a name="b51690521108"></a>rootfs.img</strong> file in the IDE.</p> 237 </td> 238 </tr> 239 <tr id="row2368120112219"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p20368142072217"><a name="p20368142072217"></a><a name="p20368142072217"></a>saveenv</p> 240 </td> 241 <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p19368102020220"><a name="p19368102020220"></a><a name="p19368102020220"></a><strong id="b12547103053713"><a name="b12547103053713"></a><a name="b12547103053713"></a>saveenv</strong> means to save the current configuration.</p> 242 </td> 243 </tr> 244 <tr id="row63689205220"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p3368162015223"><a name="p3368162015223"></a><a name="p3368162015223"></a>reset</p> 245 </td> 246 <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p23681820182217"><a name="p23681820182217"></a><a name="p23681820182217"></a><strong id="b29195356377"><a name="b29195356377"></a><a name="b29195356377"></a>reset</strong> means to reset the board.</p> 247 </td> 248 </tr> 249 <tr id="row346253519253"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p16462113512251"><a name="p16462113512251"></a><a name="p16462113512251"></a>pri</p> 250 </td> 251 <td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3462335152514"><a name="p3462335152514"></a><a name="p3462335152514"></a><strong id="b18592103953712"><a name="b18592103953712"></a><a name="b18592103953712"></a>pri</strong> means to view the displayed parameters.</p> 252 </td> 253 </tr> 254 </tbody> 255 </table> 256 257 > **NOTICE:** 258 >**go 0x40000000** \(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. 259 2603. <a name="li6442853122312"></a>If **hisilicon \#** is displayed during the startup, run the **reset** command. After the system automatically starts and **OHOS** is displayed, run the **./bin/helloworld** command and then press **Enter**. The system is started successfully if information shown in the following figure is displayed. 261 262 **Figure 3** Successful system startup and program execution<a name="fig2103121215172"></a> 263  264 265 266## Follow-up Learning<a name="section9712145420182"></a> 267 268Congratulations! You have finished all steps! You are advised to go on learning how to develop [Cameras with a Screen](../guide/device-wlan-sdk.md). 269 270