From e79364b045d48efbb712042e032049dd7d3d81d4 Mon Sep 17 00:00:00 2001 From: sanysun Date: Fri, 23 Jul 2021 19:33:34 +0800 Subject: [PATCH 1/2] =?UTF-8?q?docs:=20=E5=A2=9E=E5=8A=A0helloworld?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sanysun --- arm_virt/README_zh.md | 2 + arm_virt/example.md | 120 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) diff --git a/arm_virt/README_zh.md b/arm_virt/README_zh.md index 0fba57b..f8dce18 100755 --- a/arm_virt/README_zh.md +++ b/arm_virt/README_zh.md @@ -105,3 +105,5 @@ Explanation for our system configuration: - [向内核传递调试参数](example.md#sectiondebug) - [用FAT映像传递文件](example.md#sectionfatfs) + +- [添加一个Hello World程序](example.md#sectiondebug) \ No newline at end of file diff --git a/arm_virt/example.md b/arm_virt/example.md index 699365f..26e9f14 100644 --- a/arm_virt/example.md +++ b/arm_virt/example.md @@ -48,6 +48,7 @@ qemu-system-arm ...(正常运行参数) \ 1. 准备FAT映像 ``` + dd if=/dev/zero of=fat.img bs=64M count=1 sudo losetup /dev/loop0 fat.img sudo fdisk /dev/loop0 # 磁盘分区选择MBR格式, FAT16或FAT32 @@ -79,3 +80,122 @@ sudo umount some_dir sudo losetup -d /dev/loop1 # 宿主机时 sudo losetup -d /dev/loop0 # 宿主机时 ``` + +## 添加一个HelloWorld程序 +--- +1. 创建helloworld目录 +``` +helloworld目录结构如下: +applications/sample/helloworld +applications/sample/helloworld/src +``` + +2. 创建helloworld.c文件 +``` +在 applications/sample/helloworld/src下创建helloworld.c文件,并添加如下代码: +``` +``` +#include + +int main(int argc, char **argv) +{ + printf("\n************************************************\n"); + printf("\n\t\tHello OHOS!\n"); + printf("\n************************************************\n\n"); + + return 0; +} +``` + +3. 为helloword创建BUILD.gn文件 +``` +在 applications/sample/helloworld下添加BUILD.gn文件,并添加如下代码: +``` +``` +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 = [] +} +``` + +**提示**:hellworld最后目录结构为 +``` +applications/sample/helloworld +applications/sample/helloworld/BUILD.gn +applications/sample/helloworld/src +applications/sample/helloworld/src/helloworld.c +``` + +4. 在build/lite/components中新建配置文件helloworld.json,并添加如下代码: +``` +{ + "components": [ + { + "component": "hello_world_app", + "description": "Communication related samples.", + "optional": "true", + "dirs": [ + "applications/sample/helloworld" + ], + "targets": [ + "//applications/sample/helloworld:hello-OHOS" + ], + "rom": "", + "ram": "", + "output": [], + "adapted_kernel": [ "liteos_a" ], + "features": [], + "deps": { + "components": [], + "third_party": [] + } + } + ] +} +``` + +**注意**:helloworld.json中dirs和targets的属性值是不带src的 + +5. 在vendor/ohos/display_qemu_liteos_a/config.json配置文件中找到subsystems属性,并下面追加helloworld的subsystem配置,配置参考如下: +``` + { + "subsystem": "helloworld", + "components": [ + { "component": "hello_world_app", "features":[] } + ] + } +``` + +**注意**:vendor/ohemu/display_qemu_liteos_a/config.json对应的编译模板为 display_qemu,后面编译时需要选择这个模板;另外修改JSON配置的时候一定要将多余的逗号去掉,否则编译时会报错 + +6. 编译并构建qemu虚拟环境 + +参考链接: [编译方法](README_zh.md) + +**注意**:helloworld 正常编译后会出现在 out/arm_virt/display_qemu/bin中,如果没有,请返回检查相关配置文件中的路径和名称是否有误,并尝试重新编译直到出现helloword + +``` +提示: qemu-init和qemu-run两个文件已经包含qemu相关的操作指令,可以先执行./qemu-init 然后再执行./qemu-run +``` + +7. 运行helloworld + +helloworld在qemu虚拟机的bin目录下面,进入qemu虚拟机环境后,在bin目录下执行 ./helloword,会出现如下信息,表示Hello World程序添加成功 + +``` +OHOS # ./helloworld +OHOS # +************************************************ + + Hello OHOS! + +************************************************ +``` \ No newline at end of file -- Gitee From 22759f4bbddd6bfd60cbd5ad8900e808292573e3 Mon Sep 17 00:00:00 2001 From: sanysun Date: Fri, 23 Jul 2021 20:07:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?docs:=20=20=E5=A2=9E=E5=8A=A0helloworld?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B=20=E4=BF=AE=E6=94=B9helloword=20=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E9=93=BE=E6=8E=A5id=20addhelloworld?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sanysun --- arm_virt/README_zh.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arm_virt/README_zh.md b/arm_virt/README_zh.md index f8dce18..48a1235 100755 --- a/arm_virt/README_zh.md +++ b/arm_virt/README_zh.md @@ -106,4 +106,4 @@ Explanation for our system configuration: - [用FAT映像传递文件](example.md#sectionfatfs) -- [添加一个Hello World程序](example.md#sectiondebug) \ No newline at end of file +- [添加一个Hello World程序](example.md#addhelloworld) \ No newline at end of file -- Gitee