summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDragos Motrea <Dragos.Motrea@enea.com>2018-01-17 10:42:18 +0100
committerDragos Motrea <Dragos.Motrea@enea.com>2018-01-17 10:42:18 +0100
commitfc581a780d145c4624890fa506d9d5386821a507 (patch)
tree7abf83e0f53cb49ca9793b673f15068cc02f795a
parent7b2b8ba045b12b1716d0b4379aeb9bd4f2c4f3da (diff)
downloadel_releases-standard-fc581a780d145c4624890fa506d9d5386821a507.tar.gz
el7_std: Added Application development chapter
Signed-off-by: Dragos Motrea <Dragos.Motrea@enea.com>
-rw-r--r--doc/book-enea-linux-user-guide/doc/application_development.xml266
1 files changed, 263 insertions, 3 deletions
diff --git a/doc/book-enea-linux-user-guide/doc/application_development.xml b/doc/book-enea-linux-user-guide/doc/application_development.xml
index 40bb4d8..c8ee28c 100644
--- a/doc/book-enea-linux-user-guide/doc/application_development.xml
+++ b/doc/book-enea-linux-user-guide/doc/application_development.xml
@@ -5,18 +5,278 @@
5 <section id="cross_comp_apps"> 5 <section id="cross_comp_apps">
6 <title>Cross-Compiling Applications</title> 6 <title>Cross-Compiling Applications</title>
7 7
8 <para></para> 8 <para>Running <command>make</command> cross-compiles your applications
9 according to the environment settings. By installing a Cross-Compilation
10 Toolchain for your target, the environment variables are set up for
11 cross-compilation. For more details, see <xref
12 linkend="install_el_sdk" />.</para>
13
14 <para>Once the cross-compilation environment is set up, you can make your
15 applications as usual and get them compiled for your target. Below you see
16 how to cross-compile from the command line. If Eclipse is installed, you
17 can also cross-compile your code from the Eclipse IDE. For more details,
18 see <xref linkend="enea-linux-eclipse-cross-compile" />.</para>
19
20 <orderedlist>
21 <listitem>
22 <para>Create a Makefile for your application. Example of a simple
23 Makefile and application:</para>
24
25 <programlisting>helloworld:helloworld.o
26 $(CC) -o helloworld helloworld.o
27
28clean:
29 rm -f *.o helloworld</programlisting>
30
31 <programlisting>#include &lt;stdio.h&gt;
32
33int main(void) {
34 printf("Hello World\n");
35 return 0;
36}</programlisting>
37 </listitem>
38
39 <listitem>
40 <para>Run <command>make</command> to cross-compile your application
41 according to the environment set up:</para>
42
43 <programlisting>$ make</programlisting>
44
45 <tip>
46 <para>If the build fails, check if the GNU Make workaround solves
47 your problem.</para>
48 </tip>
49 </listitem>
50
51 <listitem>
52 <para>Copy the <filename>helloworld</filename> program to your target
53 and run it:</para>
54
55 <programlisting># ./helloworld
56Hello World</programlisting>
57 </listitem>
58 </orderedlist>
9 </section> 59 </section>
10 60
11 <section id="cross_comp_kern_mod"> 61 <section id="cross_comp_kern_mod">
12 <title>Cross-Compiling Kernel modules</title> 62 <title>Cross-Compiling Kernel modules</title>
13 63
14 <para></para> 64 <para>Running <command>make</command> cross-compiles your kernel modules
65 according to the environment settings. By installing a Cross-Compilation
66 Toolchain for your target, the environment variables are set up for
67 cross-compilation. For more details, see <xref
68 linkend="install_el_sdk" />.</para>
69
70 <para>Before cross-compiling kernel modules, you need to make sure the
71 installed toolchain includes the kernel source tree, which should be
72 available at:
73 <literal>&lt;sdkdir&gt;/sysroots/&lt;targetarch&gt;-enea-linux/usr/src/kernel</literal>.
74 If the kernel source tree is not included in the toolchain, you need to
75 add the kernel-dev package into the image recipe enea-image-&lt;name&gt;
76 and build the toolchain again.</para>
77
78 <para>Once the cross-compilation environment is set up, you can make your
79 kernel modules as usual and get them compiled for your target. Below you
80 see how to cross-compile a kernel module.</para>
81
82 <orderedlist>
83 <listitem>
84 <para>Create a Makefile for the kernel module. Example of a simple
85 Makefile and kernel module:</para>
86
87 <programlisting>obj-m := hello.o
88PWD := $(shell pwd)
89
90KERNEL_SRC := &lt;full path to kernel source tree&gt;
91
92all: scripts
93 $(MAKE) -C $(KERNEL_SRC) M=$(PWD) LDFLAGS="" modules
94scripts:
95 $(MAKE) -C $(KERNEL_SRC) scripts
96clean:
97 $(MAKE) -C $(KERNEL_SRC) M=$(PWD) LDFLAGS="" clean</programlisting>
98
99 <programlisting>#include &lt;linux/module.h&gt; /* Needed by all modules */
100#include &lt;linux/kernel.h&gt; /* Needed for KERN_INFO */
101#include &lt;linux/init.h&gt; /* Needed for the macros */
102
103static int __init hello_start(void)
104{
105 printk(KERN_INFO "Loading hello module...\n");
106 printk(KERN_INFO "Hello, world\n");
107 return 0;
108}
109
110static void __exit hello_end(void)
111{
112 printk(KERN_INFO "Goodbye, world\n");
113}
114
115module_init(hello_start);
116module_exit(hello_end);
117
118MODULE_LICENSE("GPL");</programlisting>
119 </listitem>
120
121 <listitem>
122 <para>Run <command>make</command> to cross-compile your kernel module
123 according to the environment set up:</para>
124
125 <programlisting>$ make</programlisting>
126 </listitem>
127
128 <listitem>
129 <para>Copy the kernel module <filename>hello.ko</filename> to your
130 target and install/remove it:</para>
131
132 <programlisting># insmod hello.ko
133# rmmod hello.ko
134# dmesg
135[...] Loading hello module...
136[...] Hello, world
137[...] Goodbye, world</programlisting>
138 </listitem>
139 </orderedlist>
15 </section> 140 </section>
16 141
17 <section id="use_devtool"> 142 <section id="use_devtool">
18 <title>Add an Application using devtool</title> 143 <title>Add an Application using devtool</title>
19 144
20 <para></para> 145 <para>As a prerequisite, you need to install the SDK and set up the
146 environment. For this, see <xref linkend="install_el_sdk" />.</para>
147
148 <para>The following section, <ulink
149 url="http://www.yoctoproject.org/docs/2.3/sdk-manual/sdk-manual.html#sdk-use-devtool-to-add-an-application">Use
150 devtool add to Add an Application</ulink>, in Yocto Project Software
151 Development Kit (SDK) Developer's Guide, explains how to use devtool to
152 generate recipes from existing application code, edit and build recipes,
153 and deploy the output on target. If needed, replace the Yocto version in
154 the link.</para>
155
156 <para>This example will show how to generate a recipe from the existing
157 application code and Makefile, edit the recipe in order to provide an
158 installation path for the application, build the recipe, and deploy the
159 output on a target, or create a DEB package from the recipe and install
160 the package.</para>
161
162 <orderedlist>
163 <listitem>
164 <para>Create a simple application and Makefile in
165 <literal>&lt;workspace_dir&gt;/my_app</literal>:</para>
166
167 <para><literal>&lt;workspace_dir&gt;/my_app/my_hello_app.c</literal></para>
168
169 <programlisting>#include &lt;stdio.h&gt;
170
171int main(void)
172{
173 printf("Hello world!\n");
174 return 0;
175}</programlisting>
176
177 <para><literal>&lt;workspace_dir&gt;/my_app/Makefile</literal></para>
178
179 <programlisting>my_hello_app:</programlisting>
180 </listitem>
181
182 <listitem>
183 <para>Generate a recipe (my-hello-recipe) using the source tree of the
184 application (<literal>&lt;workspace_dir&gt;/my_app</literal>):</para>
185
186 <programlisting>$ devtool add my-hello-recipe &lt;workspace_dir&gt;/my_app
187NOTE: Using source tree as build directory since that would be the default for this
188recipe
189NOTE: Recipe &lt;SDK_dir&gt;/workspace/recipes/my-hello-recipe/my-hello-recipe.bb has been
190automatically created; further editing may be required to make it fully functional</programlisting>
191
192 <programlisting>$ cat &lt;SDK_dir&gt;/workspace/recipes/my-hello-recipe/my-hello-recipe.bb
193# Recipe created by recipetool
194# This is the basis of a recipe and may need further editing in order to be fully
195# functional.
196# (Feel free to remove these comments when editing.)
197#
198# Unable to find any files that looked like license statements. Check the
199# accompanying documentation and source headers and set LICENSE and
200# LIC_FILES_CHKSUM accordingly.
201#
202# NOTE: LICENSE is being set to "CLOSED" to allow you to at least start building - if
203# this is not accurate with respect to the licensing of the software being built (it
204# will not be in most cases) you must specify the correct value before using this
205# recipe for anything other than initial testing/development!
206LICENSE = "CLOSED"
207LIC_FILES_CHKSUM = ""
208
209# No information for SRC_URI yet (only an external source tree was specified)
210SRC_URI = ""
211
212
213# NOTE: this is a Makefile-only piece of software, so we cannot generate much of the
214# recipe automatically - you will need to examine the Makefile yourself and ensure
215# that the appropriate arguments are passed in.
216
217do_configure () {
218 # Specify any needed configure commands here
219 :
220}
221
222do_compile () {
223 # You will almost certainly need to add additional arguments here
224 oe_runmake
225}
226
227do_install () {
228 # NOTE: unable to determine what to put here - there is a Makefile but no
229 # target named "install", so you will need to define this yourself
230 :
231}</programlisting>
232 </listitem>
233
234 <listitem>
235 <para>Edit the recipe to provide an installation path for the
236 application:</para>
237
238 <programlisting>$ devtool edit-recipe my-hello-recipe</programlisting>
239
240 <programlisting>$ cat &lt;SDK_dir&gt;/workspace/recipes/my-hello-recipe/my-hello-recipe.bb
241...
242do_install () {
243 # NOTE: unable to determine what to put here - there is a Makefile but no
244 # target named "install", so you will need to define this yourself
245 install -d ${D}${bindir}
246 install -m 0777 ${S}/my_hello_app ${D}${bindir}
247}
248...</programlisting>
249 </listitem>
250
251 <listitem>
252 <para>Build the recipe:</para>
253
254 <programlisting>$ devtool build my-hello-recipe</programlisting>
255
256 <para>The recipe build results can be seen here:
257 <literal>&lt;SDK_dir&gt;/tmp/work/&lt;arch&gt;-enea-linux/my-hello-recipe/1.0-r0/</literal></para>
258 </listitem>
259
260 <listitem>
261 <para>Deploy the output (in this case, the application) on
262 target:</para>
263
264 <programlisting>$ devtool deploy-target my-hello-recipe root@&lt;target_ip_address&gt;
265Parsing recipes..done.
266NOTE: Successfully deployed
267&lt;SDK_dir&gt;/tmp/work/&lt;arch&gt;-enea-linux/my-hello-recipe/1.0-r0/image</programlisting>
268
269 <para>As an alternative you can create a DEB package:</para>
270
271 <programlisting>$ devtool package my-hello-recipe
272...
273NOTE: Your packages are in &lt;SDK_dir&gt;/tmp/deploy/deb</programlisting>
274
275 <para>Then copy the DEB package on the target and install it using
276 dpkg:</para>
277
278 <programlisting># dpkg -i my-hello-recipe-1.0-r0.1.&lt;arch&gt;.deb</programlisting>
279 </listitem>
280 </orderedlist>
21 </section> 281 </section>
22</chapter> \ No newline at end of file 282</chapter> \ No newline at end of file