1 | .. SPDX-License-Identifier: CC-BY-SA-4.0 |
---|
2 | |
---|
3 | .. Copyright (C) 2020 Chris Johns |
---|
4 | |
---|
5 | .. _QuickStartAPP: |
---|
6 | |
---|
7 | Build Your Application |
---|
8 | ====================== |
---|
9 | |
---|
10 | You tested a BSP in the previous section. We built the ``erc32`` BSP |
---|
11 | and it is installed under :file:`$HOME/quick-start/rtems/5`. |
---|
12 | |
---|
13 | We will now create a simple hello world application with a Git |
---|
14 | repository and using the `Waf <https://waf.io>`_ build system. |
---|
15 | |
---|
16 | The application is be created in :file:`$HOME/quick-start/app/hello`. |
---|
17 | |
---|
18 | In the output in this section the base directory :file:`$HOME/quick-start` was |
---|
19 | replaced by ``$BASE``. |
---|
20 | |
---|
21 | The steps in this section assume you are in the directory |
---|
22 | :file:`$HOME/quick-start/app/hello` after the first step changes to |
---|
23 | it. |
---|
24 | |
---|
25 | Setup the application work space. Create a new Git repository, download |
---|
26 | the Waf build system, and the `RTEMS Waf |
---|
27 | <https://git.rtems.org/rtems_waf.git/tree/README>`_. |
---|
28 | |
---|
29 | Create the application directory and change into it: |
---|
30 | |
---|
31 | .. code-block:: none |
---|
32 | |
---|
33 | mkdir -p $HOME/quick-start/app/hello |
---|
34 | cd $HOME/quick-start/app/hello |
---|
35 | |
---|
36 | Download the Waf build system and set it to executable: |
---|
37 | |
---|
38 | .. code-block:: none |
---|
39 | |
---|
40 | curl https://waf.io/waf-2.0.19 > waf |
---|
41 | chmod +w waf |
---|
42 | |
---|
43 | Initialise a new Git repository: |
---|
44 | |
---|
45 | .. code-block:: none |
---|
46 | |
---|
47 | git init |
---|
48 | |
---|
49 | Add RTEMS Waf support as a Git sub-module and initialise it: |
---|
50 | |
---|
51 | .. code-block:: none |
---|
52 | |
---|
53 | git submodule add git://git.rtems.org/rtems_waf.git rtems_waf |
---|
54 | |
---|
55 | Create the application source files. Three files are created with an |
---|
56 | editor of your choice. |
---|
57 | |
---|
58 | First create a C file that configures RTEMS. Using an editor create a |
---|
59 | file called :file:`init.c` and copy the following configuration |
---|
60 | settings: |
---|
61 | |
---|
62 | .. code-block:: c |
---|
63 | |
---|
64 | /* |
---|
65 | * Simple RTEMS configuration |
---|
66 | */ |
---|
67 | #include <rtems.h> |
---|
68 | |
---|
69 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
70 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
71 | #define CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM |
---|
72 | |
---|
73 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
74 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
75 | |
---|
76 | #define CONFIGURE_INIT |
---|
77 | |
---|
78 | #include <rtems/confdefs.h> |
---|
79 | |
---|
80 | Create the *hello world* application source file. Using an editor |
---|
81 | create :file:`hello.c` and copy the follow code: |
---|
82 | |
---|
83 | .. code-block:: c |
---|
84 | |
---|
85 | /* |
---|
86 | * Hello world example |
---|
87 | */ |
---|
88 | #include <rtems.h> |
---|
89 | #include <stdlib.h> |
---|
90 | #include <stdio.h> |
---|
91 | |
---|
92 | rtems_task Init( |
---|
93 | rtems_task_argument ignored |
---|
94 | ) |
---|
95 | { |
---|
96 | printf( "\nHello World\n" ); |
---|
97 | exit( 0 ); |
---|
98 | } |
---|
99 | |
---|
100 | Finally create the Waf script. Using an editor create :file:`wscript` |
---|
101 | and copy the Waf script: |
---|
102 | |
---|
103 | .. code-block:: python |
---|
104 | |
---|
105 | # |
---|
106 | # Hello world Waf script |
---|
107 | # |
---|
108 | from __future__ import print_function |
---|
109 | |
---|
110 | rtems_version = "5" |
---|
111 | |
---|
112 | try: |
---|
113 | import rtems_waf.rtems as rtems |
---|
114 | except: |
---|
115 | print('error: no rtems_waf git submodule') |
---|
116 | import sys |
---|
117 | sys.exit(1) |
---|
118 | |
---|
119 | def init(ctx): |
---|
120 | rtems.init(ctx, version = rtems_version, long_commands = True) |
---|
121 | |
---|
122 | def bsp_configure(conf, arch_bsp): |
---|
123 | # Add BSP specific configuration checks |
---|
124 | pass |
---|
125 | |
---|
126 | def options(opt): |
---|
127 | rtems.options(opt) |
---|
128 | |
---|
129 | def configure(conf): |
---|
130 | rtems.configure(conf, bsp_configure = bsp_configure) |
---|
131 | |
---|
132 | def build(bld): |
---|
133 | rtems.build(bld) |
---|
134 | |
---|
135 | bld(features = 'c cprogram', |
---|
136 | target = 'hello.exe', |
---|
137 | cflags = '-g -O2', |
---|
138 | source = ['hello.c', |
---|
139 | 'init.c']) |
---|
140 | |
---|
141 | Configure the application using Waf's ``configure`` command: |
---|
142 | |
---|
143 | .. code-block:: none |
---|
144 | |
---|
145 | ./waf configure --rtems=$HOME/quick-start/rtems/5 --rtems-bsp=sparc/erc32 |
---|
146 | |
---|
147 | The output will be something close to: |
---|
148 | |
---|
149 | .. code-block:: none |
---|
150 | |
---|
151 | Setting top to : $BASE/app/hello |
---|
152 | Setting out to : $BASE/app/hello/build |
---|
153 | RTEMS Version : 5 |
---|
154 | Architectures : sparc-rtems5 |
---|
155 | Board Support Package (BSP) : sparc-rtems5-erc32 |
---|
156 | Show commands : no |
---|
157 | Long commands : no |
---|
158 | Checking for program 'sparc-rtems5-gcc' : $BASE/rtems/5/bin/sparc-rtems5-gcc |
---|
159 | Checking for program 'sparc-rtems5-g++' : $BASE/rtems/5/bin/sparc-rtems5-g++ |
---|
160 | Checking for program 'sparc-rtems5-gcc' : $BASE/rtems/5/bin/sparc-rtems5-gcc |
---|
161 | Checking for program 'sparc-rtems5-ld' : $BASE/rtems/5/bin/sparc-rtems5-ld |
---|
162 | Checking for program 'sparc-rtems5-ar' : $BASE/rtems/5/bin/sparc-rtems5-ar |
---|
163 | Checking for program 'sparc-rtems5-nm' : $BASE/rtems/5/bin/sparc-rtems5-nm |
---|
164 | Checking for program 'sparc-rtems5-objdump' : $BASE/rtems/5/bin/sparc-rtems5-objdump |
---|
165 | Checking for program 'sparc-rtems5-objcopy' : $BASE/rtems/5/bin/sparc-rtems5-objcopy |
---|
166 | Checking for program 'sparc-rtems5-readelf' : $BASE/rtems/5/bin/sparc-rtems5-readelf |
---|
167 | Checking for program 'sparc-rtems5-strip' : $BASE/rtems/5/bin/sparc-rtems5-strip |
---|
168 | Checking for program 'sparc-rtems5-ranlib' : $BASE/rtems/5/bin/sparc-rtems5-ranlib |
---|
169 | Checking for program 'rtems-ld' : $BASE/rtems/5/bin/rtems-ld |
---|
170 | Checking for program 'rtems-tld' : $BASE/rtems/5/bin/rtems-tld |
---|
171 | Checking for program 'rtems-syms' : $BASE/rtems/5/bin/rtems-syms |
---|
172 | Checking for program 'rtems-bin2c' : $BASE/rtems/5/bin/rtems-bin2c |
---|
173 | Checking for program 'tar' : /usr/bin/tar |
---|
174 | Checking for program 'gcc, cc' : $BASE/rtems/5/bin/sparc-rtems5-gcc |
---|
175 | Checking for program 'ar' : $BASE/rtems/5/bin/sparc-rtems5-ar |
---|
176 | Checking for program 'g++, c++' : $BASE/rtems/5/bin/sparc-rtems5-g++ |
---|
177 | Checking for program 'ar' : $BASE/rtems/5/bin/sparc-rtems5-ar |
---|
178 | Checking for program 'gas, gcc' : $BASE/rtems/5/bin/sparc-rtems5-gcc |
---|
179 | Checking for program 'ar' : $BASE/rtems/5/bin/sparc-rtems5-ar |
---|
180 | Checking for c flags '-MMD' : yes |
---|
181 | Checking for cxx flags '-MMD' : yes |
---|
182 | Compiler version (sparc-rtems5-gcc) : 7.5.0 20191114 (RTEMS 5, RSB 5.1.0, Newlib fbaa096) |
---|
183 | Checking for a valid RTEMS BSP installation : yes |
---|
184 | Checking for RTEMS_DEBUG : no |
---|
185 | Checking for RTEMS_MULTIPROCESSING : no |
---|
186 | Checking for RTEMS_NEWLIB : yes |
---|
187 | Checking for RTEMS_POSIX_API : yes |
---|
188 | Checking for RTEMS_SMP : no |
---|
189 | Checking for RTEMS_NETWORKING : no |
---|
190 | 'configure' finished successfully (0.686s) |
---|
191 | |
---|
192 | Build the application: |
---|
193 | |
---|
194 | .. code-block:: none |
---|
195 | |
---|
196 | ./waf |
---|
197 | |
---|
198 | The output will be something close to: |
---|
199 | |
---|
200 | .. code-block:: none |
---|
201 | |
---|
202 | Waf: Entering directory `$BASE/app/hello/build/sparc-rtems5-erc32' |
---|
203 | [1/3] Compiling init.c |
---|
204 | [2/3] Compiling hello.c |
---|
205 | [3/3] Linking build/sparc-rtems5-erc32/hello.exe |
---|
206 | Waf: Leaving directory `$BASE/app/hello/build/sparc-rtems5-erc32' |
---|
207 | 'build-sparc-rtems5-erc32' finished successfully (0.183s) |
---|
208 | |
---|
209 | Run the executable: |
---|
210 | |
---|
211 | .. code-block:: none |
---|
212 | |
---|
213 | $HOME/quick-start/rtems/5/bin/rtems-run --rtems-bsps=erc32-sis build/sparc-rtems5-erc32/hello.exe |
---|
214 | |
---|
215 | The output will be something close to: |
---|
216 | |
---|
217 | .. code-block:: none |
---|
218 | |
---|
219 | RTEMS Testing - Run, 5.1.0 |
---|
220 | Command Line: $BASE/rtems/5/bin/rtems-run --rtems-bsps=erc32-sis build/sparc-rtems5-erc32/hello.exe |
---|
221 | Host: FreeBSD hihi 12.1-RELEASE-p2 FreeBSD 12.1-RELEASE-p2 GENERIC amd64 |
---|
222 | Python: 3.7.6 (default, Jan 30 2020, 01:18:54) [Clang 6.0.1 (tags/RELEASE_601/final 335540)] |
---|
223 | Host: FreeBSD-12.1-RELEASE-p2-amd64-64bit-ELF (FreeBSD hihi 12.1-RELEASE-p2 FreeBSD 12.1-RELEASE-p2 GENERIC amd64 amd64) |
---|
224 | |
---|
225 | SIS - SPARC/RISCV instruction simulator 2.21, copyright Jiri Gaisler 2019 |
---|
226 | Bug-reports to jiri@gaisler.se |
---|
227 | |
---|
228 | ERC32 emulation enabled |
---|
229 | |
---|
230 | Loaded build/sparc-rtems5-erc32/hello.exe, entry 0x02000000 |
---|
231 | |
---|
232 | Hello World |
---|
233 | |
---|
234 | *** FATAL *** |
---|
235 | fatal source: 5 (RTEMS_FATAL_SOURCE_EXIT) |
---|
236 | fatal code: 0 (0x00000000) |
---|
237 | RTEMS version: 5.1.0 |
---|
238 | RTEMS tools: 7.5.0 20191114 (RTEMS 5, RSB 5.1.0, Newlib fbaa096) |
---|
239 | executing thread ID: 0x08a010001 |
---|
240 | executing thread name: UI1 |
---|
241 | cpu 0 in error mode (tt = 0x101) |
---|
242 | 107883 0200b6c0: 91d02000 ta 0x0 |
---|
243 | Run time : 0:00:01.011474 |
---|
244 | |
---|
245 | Commit the application to the repository: |
---|
246 | |
---|
247 | .. code-block:: none |
---|
248 | |
---|
249 | git add init.c hello.c wscript |
---|
250 | git commit -m "My first RTEMS application." |
---|