1 Star 0 Fork 5.1K

youguilin / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
running-a-hello-ohos-program-4.md 14.73 KB
一键复制 编辑 原始数据 按行查看 历史
mamingshuai 提交于 2021-06-02 01:00 . update OpenHarmony 2.0 Canary

Running a Hello OHOS Program

This section describes how to create, compile, burn, and run the first program, and finally print Hello OHOS! on the develop board.

Creating a Program

  1. Create a directory and the program source code.

    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.

    #include <stdio.h>
    
    int main(int argc, char **argv)
    {
        printf("\n************************************************\n");
        printf("\n\t\tHello OHOS!\n");
        printf("\n************************************************\n\n");
    
        return 0;
    }
  2. Create a build file.

    Create the applications/sample/camera/apps/BUILD.gn file. The file content is as follows:

    import("//build/lite/config/component/lite_component.gni")
    lite_component("hello-OHOS") {
      features = [ ":helloworld" ]
    }
    executable("helloworld") {
      output_name = "helloworld"
      sources = [ "src/helloworld.c" ]
      include_dirs = []
      defines = []
      cflags_c = []
      ldflags = []
    }
  3. Add a new component.

    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.)

    {
      "components": [
        {
          "component": "camera_sample_communication",
          "description": "Communication related samples.",
          "optional": "true",
          "dirs": [
            "applications/sample/camera/communication"
          ],
          "targets": [
            "//applications/sample/camera/communication:sample"
          ],
          "rom": "",
          "ram": "",
          "output": [],
          "adapted_kernel": [ "liteos_a" ],
          "features": [],
          "deps": {
            "components": [],
            "third_party": []
          }
        },
    ##start##
        {
          "component": "hello_world_app",
          "description": "Communication related samples.",
          "optional": "true",
          "dirs": [
            "applications/sample/camera/apps"
          ],
          "targets": [
            "//applications/sample/camera/apps:hello-OHOS"
          ],
          "rom": "",
          "ram": "",
          "output": [],
          "adapted_kernel": [ "liteos_a" ],
          "features": [],
          "deps": {
            "components": [],
            "third_party": []
          }
        },
    ##end##
        {
          "component": "camera_sample_app",
          "description": "Camera related samples.",
          "optional": "true",
          "dirs": [
            "applications/sample/camera/launcher",
            "applications/sample/camera/cameraApp",
            "applications/sample/camera/setting",
            "applications/sample/camera/gallery",
            "applications/sample/camera/media"
          ],
  4. Modify the board configuration file.

    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.)

          {
            "subsystem": "applications",
            "components": [
    ##start##
              { "component": "hello_world_app", "features":[] },
    ##end##
              { "component": "camera_sample_app", "features":[] }
    
            ]
          },

Building

If the Linux environment is installed using Docker, perform the compilation by referring to Using Docker to Prepare the Build Environment. If the Linux compilation environment is installed using a software package, execute the following commands to compile source code in the root directory of the source code package.

hb set (Set the building path.)
. (Select the current path.)
Select ipcamera_hispark_aries@hisilicon and press Enter.
hb build -f (Start building.)

The result files are generated in the out/hispark_aries/ipcamera_hispark_aries directory.

Figure 1 Settings

NOTICE: 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

Burning

The USB port is the only burning mode supported by the Hi3518 development board.

  1. Connect the PC and the target development board through the serial port and USB port. In this section, the Hi3518EV300 is used as an example. For details, please refer to Introduction to the Hi3518 Development Board.

  2. Open Device Manager, then check and record the serial port number corresponding to the development board.

    NOTE: 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.

  3. Open DevEco Device Tool and go to Projects > Settings.

  4. On the hi3518ev300 tab page, set the programming options.

    • upload_port: Select the serial port number obtained in step 2.
    • upload_protocol: Select the programming protocol hiburn-usb.
    • upload_partitions: Select the file to be programmed. By default, the fastboot, kernel, rootfs, and userfs files are programmed at the same time.

  5. Switch between the hi3518ev300_fastboot, hi3518ev300_kernel, hi3518ev300_rootfs, and hi3518ev300_userfs tab pages, and modify the settings. In general cases, you can leave the fields at their default settings. To change the default settings, select the target item in the New Option field first.

  6. When you finish modifying, click Save in the upper right corner.

  7. Open the project file, go to > PROJECT TASKS > partition:hi3518ev300_fastboot > Erase to erase U-boot.

  8. When the following message is displayed, power off the development board and then power it on.

  9. If the following message is displayed, it indicates that U-Boot is erased successfully.

  10. Go to env:hi3518ev300 > Upload to start programming.

  11. If the following message is displayed, it indicates that the programming is successful.

Running an Image

  1. Connect to a serial port.

    NOTICE: If the connection fails, rectify the fault by referring to FAQs.

    Figure 2 Serial port connection

    1. Click Monitor to enable the serial port. The TERMINAL window is displayed.
    2. Press Enter repeatedly until hisilicon displays.
    3. Go to step 2 if the board is started for the first time or the startup parameters need to be modified; go to step 3 otherwise.
  2. (Mandatory for the first 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.

    Table 1 Parameters of the U-boot

    Command

    Description

    setenv bootcmd "sf probe 0;sf read 0x40000000 0x100000 0x600000;go 0x40000000";

    Run this command to set the content of bootcmd. 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 OHOS_Image.bin file in the IDE.

    setenv bootargs "console=ttyAMA0,115200n8 root=flash fstype=jffs2 rw rootaddr=7 M rootsize=8 M";

    In this command, bootargs is set to the serial port output, the baud rate is 115200, the data bit is 8, and the rootfs is mounted to the flash memory. The file system type is set to jffs2 rw, which provides the read-write attribute for the JFFS2 file system. rootaddr=7 M rootsize=8 M indicates the actual start address and length of the rootfs.img file to be burnt, respectively. The file size must be the same as that of the rootfs.img file in the IDE.

    saveenv

    saveenv means to save the current configuration.

    reset

    reset means to reset the board.

    pri

    pri means to view the displayed parameters.

    NOTICE: 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.

  3. 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.

    Figure 3 Successful system startup and program execution

Follow-up Learning

Congratulations! You have finished all steps! You are advised to go on learning how to develop Cameras with a Screen.

1
https://gitee.com/yougl/docs.git
git@gitee.com:yougl/docs.git
yougl
docs
docs
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891