编辑
2025-03-30
工作知识
0
请注意,本文编写于 68 天前,最后修改于 68 天前,其中某些信息可能已经过时。

目录

一、准备仓库
二、waf构建工具环境
三、编写应用
四、构建
五、运行
六、提交代码

我们之前构建了RTEMS操作系统,这次继续构建此实时系统的应用程序,以hello kylin为例

一、准备仓库

为了编写应用程序以及管理,需要提前准备一个本地git仓库,如下

# mkdir -p app/hello # cd app/hello # git init .

二、waf构建工具环境

waf作为rtems的构建工具,我们需要为应用程序下载此工具,如下:

# cp ../../waf . # git submodule add https://gitlab.rtems.org/rtems/tools/rtems_waf.git rtems_waf

三、编写应用

编写应用前,需要为RTEMS操作系统提供init.c,如下

/* * Simple RTEMS configuration */ #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER #define CONFIGURE_UNLIMITED_OBJECTS #define CONFIGURE_UNIFIED_WORK_AREAS #define CONFIGURE_RTEMS_INIT_TASKS_TABLE #define CONFIGURE_INIT #include <rtems/confdefs.h>

然后创建hello.c应用程序如下

/* * Hello world example */ #include <rtems.h> #include <stdlib.h> #include <stdio.h> rtems_task Init( rtems_task_argument ignored ) { printf( "\nHello Kylin\n" ); exit( 0 ); }

最后为hello.c和init.c编写waf构建脚本,如下

# # Hello world Waf script # from __future__ import print_function rtems_version = "6" try: import rtems_waf.rtems as rtems except: print('error: no rtems_waf git submodule') import sys sys.exit(1) def init(ctx): rtems.init(ctx, version = rtems_version, long_commands = True) def bsp_configure(conf, arch_bsp): # Add BSP specific configuration checks pass def options(opt): rtems.options(opt) def configure(conf): rtems.configure(conf, bsp_configure = bsp_configure) def build(bld): rtems.build(bld) bld(features = 'c cprogram', target = 'hello.exe', cflags = '-g -O2', source = ['hello.c', 'init.c'])

四、构建

此时一切准备完成之后,构建应用程序和构建操作系统的命令一致,如下:

# ./waf configure --rtems=~/work/rtems/out/ --rtems-bsp=aarch64/zynqmp_qemu # ./waf

五、运行

通过rtems-run可以带起qemu运行应用程序,如下:

# rtems-run --rtems-bsps=zynqmp_qemu build/aarch64-rtems6-zynqmp_qemu/hello.exe

此时运行结果如下

RTEMS Testing - Run, 6.0.not_released Command Line: /root/work/rtems/out/bin/rtems-run --rtems-bsps=zynqmp_qemu build/aarch64-rtems6-zynqmp_qemu/hello.exe Host: Linux tf 6.8.0-47-generic #47-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 27 21:40:26 UTC 2024 x86_64 Python: 2.7.18 (default, Jan 31 2024, 16:23:13) [GCC 9.4.0] Host: Linux-6.8.0-47-generic-x86_64-with-Ubuntu-20.04-focal (Linux tf 6.8.0-47-generic #47-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 27 21:40:26 UTC 2024 x86_64 x86_64) Hello Kylin [ RTEMS shutdown ] CPU: 0 RTEMS version: 6.0.0.87bf49b7156b9ddf45c218e5d4fa01f27b283db7 RTEMS tools: 13.3.0 20240521 (RTEMS 6, RSB b1aec32059aa0e86385ff75ec01daf93713fa382-modified, Newlib 1b3dcfd) executing thread ID: 0x0a010001 executing thread name: UI1 Run time : 0:00:00.756775

至此,一个最简单的rtems的应用程序编写完成

六、提交代码

最后提交相关代码即可

# git add init.c hello.c wscript # git commit -m "My first RTEMS application."