1 |
786 |
skrzyp |
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
Overview
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
&eCos; was designed from the very beginning as a configurable
|
42 |
|
|
component architecture. The core &eCos; system consists of a number of
|
43 |
|
|
different components such as the kernel, the C library, an
|
44 |
|
|
infrastructure package. Each of these provides a large number of
|
45 |
|
|
configuration options, allowing application developers to build a
|
46 |
|
|
system that matches the requirements of their particular application.
|
47 |
|
|
To manage the potential complexity of multiple components and lots of
|
48 |
|
|
configuration options, &eCos; comes with a component framework: a
|
49 |
|
|
collection of tools specifically designed to support configuring
|
50 |
|
|
multiple components. Furthermore this component framework is
|
51 |
|
|
extensible, allowing additional components to be added to the system
|
52 |
|
|
at any time.
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
Terminology
|
60 |
|
|
|
61 |
|
|
The &eCos; component architecture involves a number of key concepts.
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
Component Framework
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
The phrase component framework is used to describe
|
71 |
|
|
the collection of tools that allow users to configure a system and
|
72 |
|
|
administer a component repository. This includes the
|
73 |
|
|
class="software">ecosconfig command line tool, the
|
74 |
|
|
graphical configuration tool, and the package administration tool.
|
75 |
|
|
Both the command line and graphical tools are based on a single
|
76 |
|
|
underlying library, the &CDL; library.
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
Configuration Option
|
86 |
|
|
|
87 |
|
|
The option is the basic unit of configurability. Typically each option
|
88 |
|
|
corresponds to a single choice that a user can make. For example there
|
89 |
|
|
is an option to control whether or not assertions are enabled, and the
|
90 |
|
|
kernel provides an option corresponding to the number of scheduling
|
91 |
|
|
priority levels in the system. Options can control very small amounts
|
92 |
|
|
of code such as whether or not the C library's
|
93 |
|
|
strtok gets inlined. They can also control quite
|
94 |
|
|
large amounts of code, for example whether or not the
|
95 |
|
|
printf supports floating point conversions.
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
Many options are straightforward, and the user only gets to choose
|
99 |
|
|
whether the option is enabled or disabled. Some options are more
|
100 |
|
|
complicated, for example the number of scheduling priority levels is a
|
101 |
|
|
number that should be within a certain range. Options should always
|
102 |
|
|
start off with a sensible default setting, so that it is not necessary
|
103 |
|
|
for users to make hundreds of decisions before any work can start on
|
104 |
|
|
developing the application. Once the application is running the
|
105 |
|
|
various configuration options can be used to tune the system for the
|
106 |
|
|
specific needs of the application.
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
The component framework allows for options that are not directly
|
110 |
|
|
user-modifiable. Consider the case of processor endianness: some
|
111 |
|
|
processors are always big-endian or always little-endian, while with
|
112 |
|
|
other processors there is a choice. Depending on the user's choice of
|
113 |
|
|
target hardware, endianness may or may not be user-modifiable.
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
Component
|
122 |
|
|
|
123 |
|
|
A component is a unit of functionality such as a particular kernel
|
124 |
|
|
scheduler or a device driver for a specific device. A component is
|
125 |
|
|
also a configuration option in that users may want to enable
|
126 |
|
|
or disable all the functionality in a component. For example, if a
|
127 |
|
|
particular device on the target hardware is not going to be used by
|
128 |
|
|
the application, directly or indirectly, then there is no point in
|
129 |
|
|
having a device driver for it. Furthermore disabling the device driver
|
130 |
|
|
should reduce the memory requirements for both code and data.
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
Components may contain further configuration options. In the case of a
|
134 |
|
|
device driver, there may be options to control the exact behavior of
|
135 |
|
|
that driver. These will of course be irrelevant if the driver as a
|
136 |
|
|
whole is disabled. More generally options and components live in a
|
137 |
|
|
hierarchy, where any component can contain options specific to that
|
138 |
|
|
component and further sub-components. It is possible to view the
|
139 |
|
|
entire &eCos; kernel as one big component, containing sub-components
|
140 |
|
|
for scheduling, exception handling, synchronization primitives, and so
|
141 |
|
|
on. The synchronization primitives component can contain further
|
142 |
|
|
sub-components for mutexes, semaphores, condition variables, event
|
143 |
|
|
flags, and so on. The mutex component can contain configuration
|
144 |
|
|
options for issues like priority inversion support.
|
145 |
|
|
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
Package
|
153 |
|
|
|
154 |
|
|
A package is a special type of component. Specifically, a package is
|
155 |
|
|
the unit of distribution of components. It is possible to create a
|
156 |
|
|
distribution file for a package containing all of the source code,
|
157 |
|
|
header files, documentation, and other relevant files. This
|
158 |
|
|
distribution file can then be installed using the appropriate tool.
|
159 |
|
|
Afterwards it is possible to uninstall that package, or to install a
|
160 |
|
|
later version. The core &eCos; distribution comes with a number of
|
161 |
|
|
packages such as the kernel and the infrastructure. Other packages
|
162 |
|
|
such as network stacks can come from various different sources and can
|
163 |
|
|
be installed alongside the core distribution.
|
164 |
|
|
|
165 |
|
|
|
166 |
|
|
Packages can be enabled or disabled, but the user experience is a
|
167 |
|
|
little bit different. Generally it makes no sense for the tools to
|
168 |
|
|
load the details of every single package that has been installed. For
|
169 |
|
|
example, if the target hardware uses an ARM processor then there is no
|
170 |
|
|
point in loading the HAL packages for other architectures and
|
171 |
|
|
displaying choices to the user which are not relevant. Therefore
|
172 |
|
|
enabling a package means loading its configuration data into the
|
173 |
|
|
appropriate tool, and disabling a package is an unload operation. In
|
174 |
|
|
addition, packages are not just enabled or disabled: it is also
|
175 |
|
|
possible to select the particular version of a package that should be
|
176 |
|
|
used.
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
|
183 |
|
|
|
184 |
|
|
Configuration
|
185 |
|
|
|
186 |
|
|
A configuration is a collection of user choices. The various
|
187 |
|
|
tools that make up the component framework deal with entire
|
188 |
|
|
configurations. Users can create a new configuration, output a
|
189 |
|
|
savefile (by default ecos.ecc), manipulate a
|
190 |
|
|
configuration, and use a configuration to generate a build tree prior
|
191 |
|
|
to building &eCos; and any other packages that have been selected.
|
192 |
|
|
A configuration includes details such as which packages have been
|
193 |
|
|
selected, in addition to finer-grained information such as which
|
194 |
|
|
options in those packages have been enabled or disabled by the user.
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
|
199 |
|
|
|
200 |
|
|
|
201 |
|
|
|
202 |
|
|
Target
|
203 |
|
|
|
204 |
|
|
The target is the specific piece of hardware on which the application
|
205 |
|
|
is expected to run. This may be an off-the-shelf evaluation board, a
|
206 |
|
|
piece of custom hardware intended for a specific application, or it
|
207 |
|
|
could be something like a simulator. One of the steps when creating a
|
208 |
|
|
new configuration is need to specify the target. The component
|
209 |
|
|
framework will map this on to a set of packages that are used to
|
210 |
|
|
populate the configuration, typically HAL and device driver packages,
|
211 |
|
|
and in addition it may cause certain options to be changed from their
|
212 |
|
|
default settings to something more appropriate for the
|
213 |
|
|
specified target.
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
Template
|
222 |
|
|
|
223 |
|
|
A template is a partial configuration, aimed at providing users with
|
224 |
|
|
an appropriate starting point. &eCos; is shipped with a small number
|
225 |
|
|
of templates, which correspond closely to common ways of using the
|
226 |
|
|
system. There is a minimal template which provides very little
|
227 |
|
|
functionality, just enough to bootstrap the hardware and then jump
|
228 |
|
|
directly to application code. The default template adds additional
|
229 |
|
|
functionality, for example it causes the kernel and C library packages
|
230 |
|
|
to be loaded as well. The uitron template adds further functionality
|
231 |
|
|
in the form of a &uITRON; compatibility layer. Creating a new
|
232 |
|
|
configuration typically involves specifying a template as well as a
|
233 |
|
|
target, resulting in a configuration that can be built and linked with
|
234 |
|
|
the application code and that will run on the actual hardware. It is
|
235 |
|
|
then possible to fine-tune configuration options to produce something
|
236 |
|
|
that better matches the specific requirements of the application.
|
237 |
|
|
|
238 |
|
|
|
239 |
|
|
|
240 |
|
|
|
241 |
|
|
|
242 |
|
|
|
243 |
|
|
|
244 |
|
|
Properties
|
245 |
|
|
|
246 |
|
|
The component framework needs a certain amount of information about
|
247 |
|
|
each option. For example it needs to know what the legal values are,
|
248 |
|
|
what the default should be, where to find the on-line documentation if
|
249 |
|
|
the user needs to consult that in order to make a decision, and so on.
|
250 |
|
|
These are all properties of the option. Every option (including
|
251 |
|
|
components and packages) consists of a name and a set of properties.
|
252 |
|
|
|
253 |
|
|
|
254 |
|
|
|
255 |
|
|
|
256 |
|
|
|
257 |
|
|
|
258 |
|
|
|
259 |
|
|
Consequences
|
260 |
|
|
|
261 |
|
|
Choices must have consequences. For an &eCos; configuration the main
|
262 |
|
|
end product is a library that can be linked with application code, so
|
263 |
|
|
the consequences of a user choice must affect the build process. This
|
264 |
|
|
happens in two main ways. First, options can affect which files get
|
265 |
|
|
built and end up in the library. Second, details of the current option
|
266 |
|
|
settings get written into various configuration header files using C
|
267 |
|
|
preprocessor #define directives, and package source
|
268 |
|
|
code can #include these configuration headers and
|
269 |
|
|
adapt accordingly. This allows options to affect a package at a very
|
270 |
|
|
fine grain, at the level of individual lines in a source file if
|
271 |
|
|
desired. There may be other consequences as well, for example there
|
272 |
|
|
are options to control the compiler flags that get used during the
|
273 |
|
|
build process.
|
274 |
|
|
|
275 |
|
|
|
276 |
|
|
|
277 |
|
|
|
278 |
|
|
|
279 |
|
|
|
280 |
|
|
|
281 |
|
|
Constraints
|
282 |
|
|
|
283 |
|
|
Configuration choices are not independent. The C library can provide
|
284 |
|
|
thread-safe implementations of functions like
|
285 |
|
|
rand, but only if the kernel provides support for
|
286 |
|
|
per-thread data. This is a constraint: the C library option has a
|
287 |
|
|
requirement on the kernel. A typical configuration involves a
|
288 |
|
|
considerable number of constraints, of varying complexity: many
|
289 |
|
|
constraints are straightforward, option A requires
|
290 |
|
|
option B, or option C precludes
|
291 |
|
|
option D. Other constraints can be more
|
292 |
|
|
complicated, for example option E may require the
|
293 |
|
|
presence of a kernel scheduler but does not care whether it is the
|
294 |
|
|
bitmap scheduler, the mlqueue scheduler, or something else.
|
295 |
|
|
|
296 |
|
|
|
297 |
|
|
Another type of constraint involves the values that can be used for
|
298 |
|
|
certain options. For example there is a kernel option related to the
|
299 |
|
|
number of scheduling levels, and there is a legal values constraint on
|
300 |
|
|
this option: specifying zero or a negative number for the number of
|
301 |
|
|
scheduling levels makes no sense.
|
302 |
|
|
|
303 |
|
|
|
304 |
|
|
|
305 |
|
|
|
306 |
|
|
|
307 |
|
|
|
308 |
|
|
|
309 |
|
|
Conflicts
|
310 |
|
|
|
311 |
|
|
As the user manipulates options it is possible to end up with an
|
312 |
|
|
invalid configuration, where one or more constraints are not
|
313 |
|
|
satisfied. For example if kernel per-thread data is disabled but the C
|
314 |
|
|
library's thread-safety options are left enabled then there are
|
315 |
|
|
unsatisfied constraints, also known as conflicts. Such conflicts will
|
316 |
|
|
be reported by the configuration tools. The presence of conflicts does
|
317 |
|
|
not prevent users from attempting to build &eCos;, but the
|
318 |
|
|
consequences are undefined: there may be compile-time failures, there
|
319 |
|
|
may be link-time failures, the application may completely fail to run,
|
320 |
|
|
or the application may run most of the time but once in a while there
|
321 |
|
|
will be a strange failure… Typically users will want to resolve
|
322 |
|
|
all conflicts before continuing.
|
323 |
|
|
|
324 |
|
|
|
325 |
|
|
To make things easier for the user, the configuration tools contain an
|
326 |
|
|
inference engine. This can examine a conflict in a particular
|
327 |
|
|
configuration and try to figure out some way of resolving the
|
328 |
|
|
conflict. Depending on the particular tool being used, the inference
|
329 |
|
|
engine may get invoked automatically at certain times or the user may
|
330 |
|
|
need to invoke it explicitly. Also depending on the tool, the
|
331 |
|
|
inference engine may apply any solutions it finds automatically or it
|
332 |
|
|
may request user confirmation.
|
333 |
|
|
|
334 |
|
|
|
335 |
|
|
|
336 |
|
|
|
337 |
|
|
|
338 |
|
|
|
339 |
|
|
|
340 |
|
|
CDL
|
341 |
|
|
|
342 |
|
|
The configuration tools require information about the various options
|
343 |
|
|
provided by each package, their consequences and constraints, and
|
344 |
|
|
other properties such as the location of on-line documentation. This
|
345 |
|
|
information has to be provided in the form of &CDL; scripts. CDL
|
346 |
|
|
is short for Component Definition Language, and is specifically
|
347 |
|
|
designed as a way of describing configuration options.
|
348 |
|
|
|
349 |
|
|
|
350 |
|
|
A typical package contains the following:
|
351 |
|
|
|
352 |
|
|
|
353 |
|
|
|
354 |
|
|
Some number of source files which will end up in a library. The
|
355 |
|
|
application code will be linked with this library to produce an
|
356 |
|
|
executable. Some source files may serve other purposes, for example to
|
357 |
|
|
provide a linker script.
|
358 |
|
|
|
359 |
|
|
|
360 |
|
|
Exported header files which define the interface provided by the
|
361 |
|
|
package.
|
362 |
|
|
|
363 |
|
|
|
364 |
|
|
On-line documentation, for example reference pages for each exported
|
365 |
|
|
function.
|
366 |
|
|
|
367 |
|
|
|
368 |
|
|
Some number of test cases, shipped in source format, allowing users to
|
369 |
|
|
check that the package is working as expected on their particular
|
370 |
|
|
hardware and in their specific configuration.
|
371 |
|
|
|
372 |
|
|
|
373 |
|
|
One or more &CDL; scripts describing the package to the configuration
|
374 |
|
|
system.
|
375 |
|
|
|
376 |
|
|
|
377 |
|
|
|
378 |
|
|
Not all packages need to contain all of these. For example some
|
379 |
|
|
packages such as device drivers may not provide a new interface,
|
380 |
|
|
instead they just provide another implementation of an existing
|
381 |
|
|
interface. However all packages must contain a &CDL; script that
|
382 |
|
|
describes the package to the configuration tools.
|
383 |
|
|
|
384 |
|
|
|
385 |
|
|
|
386 |
|
|
|
387 |
|
|
|
388 |
|
|
|
389 |
|
|
|
390 |
|
|
Component Repository
|
391 |
|
|
|
392 |
|
|
All &eCos; installations include a component repository. This is a
|
393 |
|
|
directory structure where all the packages get installed. The
|
394 |
|
|
component framework comes with an administration tool that allows new
|
395 |
|
|
packages or new versions of a package to be installed, old packages to
|
396 |
|
|
be removed, and so on. The component repository includes a simple
|
397 |
|
|
database, maintained by the administration tool, which contains
|
398 |
|
|
details of the various packages.
|
399 |
|
|
|
400 |
|
|
|
401 |
|
|
Generally application developers do not need to modify anything inside
|
402 |
|
|
the component repository, except by means of the administration tool.
|
403 |
|
|
Instead their work involves separate build and install trees. This
|
404 |
|
|
allows the component repository to be treated as a read-only resource
|
405 |
|
|
that can be shared by multiple projects and multiple users. Component
|
406 |
|
|
writers modifying one of the packages do need to manipulate files in
|
407 |
|
|
the component repository.
|
408 |
|
|
|
409 |
|
|
|
410 |
|
|
|
411 |
|
|
|
412 |
|
|
|
413 |
|
|
|
414 |
|
|
|
415 |
|
|
|
416 |
|
|
|
417 |
|
|
|
418 |
|
|
|
419 |
|
|
Why Configurability?
|
420 |
|
|
|
421 |
|
|
The &eCos; component framework places a great deal of emphasis on
|
422 |
|
|
configurability. The fundamental goal is to allow large parts of
|
423 |
|
|
embedded applications to be constructed from re-usable software
|
424 |
|
|
components, which does not a priori require that those components be
|
425 |
|
|
highly configurable. However embedded application development often
|
426 |
|
|
involves some serious constraints.
|
427 |
|
|
|
428 |
|
|
|
429 |
|
|
Many embedded applications have to work with very little memory, to
|
430 |
|
|
keep down manufacturing costs. The final application image that will
|
431 |
|
|
get blown into EPROM's or used to manufacture ROMs should contain only
|
432 |
|
|
the code that is absolutely necessary for the application to work, and
|
433 |
|
|
nothing else. If a few tens of kilobytes are added unnecessarily to a
|
434 |
|
|
typical desktop application then this is regrettable, but is quite
|
435 |
|
|
likely to go unnoticed. If an embedded application does not fit on the
|
436 |
|
|
target hardware then the problem is much more serious. The component
|
437 |
|
|
framework must allow users to configure the components so that any
|
438 |
|
|
unnecessary functionality gets removed.
|
439 |
|
|
|
440 |
|
|
|
441 |
|
|
Many embedded applications need deterministic behavior so that they
|
442 |
|
|
can meet real-time requirements. Such deterministic behavior can
|
443 |
|
|
often be provided, but at a cost in terms of code size, slower
|
444 |
|
|
algorithms, and so on. Other applications have no such real-time
|
445 |
|
|
requirements, or only for a small part of the overall system, and the
|
446 |
|
|
bulk of the system should not suffer any penalties. Again the
|
447 |
|
|
component framework must allow the users control over the timing
|
448 |
|
|
behavior of components.
|
449 |
|
|
|
450 |
|
|
|
451 |
|
|
Embedded systems tend to be difficult to debug. Even when it is
|
452 |
|
|
possible to get information out of the target hardware by means other
|
453 |
|
|
than flashing an LED, the more interesting debugging problems are
|
454 |
|
|
likely to be timing-related and hence very hard to reproduce and track
|
455 |
|
|
down. The re-usable components can provide debugging assistance in
|
456 |
|
|
various ways. They can provide functionality that can be exploited by
|
457 |
|
|
source level debuggers such as gdb, for example per-thread debugging
|
458 |
|
|
information. They can also contain various assertions so that problems
|
459 |
|
|
can be detected early on, tracing mechanisms to figure out what
|
460 |
|
|
happened before the assertion failure, and so on. Of course all of
|
461 |
|
|
these involve overheads, especially code size, and affect the timing.
|
462 |
|
|
Allowing users to control which debugging features are enabled for any
|
463 |
|
|
given application build is very desirable.
|
464 |
|
|
|
465 |
|
|
|
466 |
|
|
However, although it is desirable for re-usable components to provide
|
467 |
|
|
appropriate configuration options this is not required. It is possible
|
468 |
|
|
to produce a package which does not provide a single configuration
|
469 |
|
|
option — although the user still gets to choose
|
470 |
|
|
whether or not to use the package. In such cases it is still necessary
|
471 |
|
|
to provide a minimal CDL script, but its main purpose would be to
|
472 |
|
|
integrate the package with the component framework's build system.
|
473 |
|
|
|
474 |
|
|
|
475 |
|
|
|
476 |
|
|
|
477 |
|
|
|
478 |
|
|
|
479 |
|
|
|
480 |
|
|
Approaches to Configurability
|
481 |
|
|
|
482 |
|
|
|
483 |
|
|
The purpose of configurability is to control the behavior of
|
484 |
|
|
components. A scheduler component may or may not support time slicing;
|
485 |
|
|
it may or may not support multiple priorities; it may or may not
|
486 |
|
|
perform error checking on arguments passed to the scheduler routines.
|
487 |
|
|
In the context of a desktop application a button widget may contain
|
488 |
|
|
some text or it may contain a picture; the text may be displayed in a
|
489 |
|
|
variety of fonts; the foreground and background color may vary. When
|
490 |
|
|
an application uses a component there must be some way of specifying
|
491 |
|
|
the desired behavior. The component writer has no way of knowing in
|
492 |
|
|
advance exactly how a particular component will end up being used.
|
493 |
|
|
|
494 |
|
|
|
495 |
|
|
One way to control the behavior is at run time. The application
|
496 |
|
|
creates an instance of a button object, and then instructs this object
|
497 |
|
|
to display either text or a picture. No special effort by the
|
498 |
|
|
application developer is required, since a button can always support
|
499 |
|
|
all desired behavior. There is of course a major disadvantage in
|
500 |
|
|
terms of the size of the final application image: the code that gets
|
501 |
|
|
linked with the application has to provide support for all possible
|
502 |
|
|
behavior, even if the application does not require it.
|
503 |
|
|
|
504 |
|
|
|
505 |
|
|
Another approach is to control the behavior at link-time, typically
|
506 |
|
|
by using inheritance in an object-oriented language. The button
|
507 |
|
|
library provides an abstract base class Button
|
508 |
|
|
and derived classes TextButton and
|
509 |
|
|
PictureButton. If an application only uses text
|
510 |
|
|
buttons then it will only create objects of type
|
511 |
|
|
TextButton, and the code for the
|
512 |
|
|
PictureButton class does not get used. In
|
513 |
|
|
many cases this approach works rather well and reduces the final image
|
514 |
|
|
size, but there are limitations. The main one is that you can only
|
515 |
|
|
have so many derived classes before the system gets unmanageable: a
|
516 |
|
|
derived class
|
517 |
|
|
TextButtonUsingABorderWidthOfOnePlusAWhiteBackgroundAndBlackForegroundAndATwelvePointTimesFontAndNoErrorCheckingOrAssertions
|
518 |
|
|
is not particularly sensible as far as most application developers are
|
519 |
|
|
concerned.
|
520 |
|
|
|
521 |
|
|
|
522 |
|
|
The &eCos; component framework allows the behavior of components to
|
523 |
|
|
be controlled at an even earlier time: when the component source code
|
524 |
|
|
gets compiled and turned into a library. The button component could
|
525 |
|
|
provide options, for example an option that only text buttons need to
|
526 |
|
|
be supported. The component gets built and becomes part of a library
|
527 |
|
|
intended specifically for the application, and the library will
|
528 |
|
|
contain only the code that is required by this application and nothing
|
529 |
|
|
else. A different application with different requirements would need
|
530 |
|
|
its own version of the library, configured separately.
|
531 |
|
|
|
532 |
|
|
|
533 |
|
|
In theory compile-time configurability should give the best possible
|
534 |
|
|
results in terms of code size, because it allows code to be controlled
|
535 |
|
|
at the individual statement level rather than at the function or
|
536 |
|
|
object level. Consider an example more closely related to embedded
|
537 |
|
|
systems, a package to support multi-threading. A standard routine
|
538 |
|
|
within such a package allows applications to kill threads
|
539 |
|
|
asynchronously: the POSIX routine for this is
|
540 |
|
|
pthread_cancel; the equivalent routine in &uITRON;
|
541 |
|
|
is ter_tsk. These routines themselves tend to
|
542 |
|
|
involve a significant amount of code, but that is not the real
|
543 |
|
|
problem: other parts of the system require extra code and data for the
|
544 |
|
|
kill routine to be able to function correctly. For example if a thread
|
545 |
|
|
is blocked while waiting on a mutex and is killed off by another
|
546 |
|
|
thread then the kill operation may have to do two things: remove the
|
547 |
|
|
thread from the mutex's queue of waiting threads; and undo the
|
548 |
|
|
effects, if any, of priority inheritance. The implementation requires
|
549 |
|
|
extra fields in the thread data structure so that the kill routine
|
550 |
|
|
knows about the thread's current state, and extra code in the mutex
|
551 |
|
|
routines to fill in and clear these extra fields correctly.
|
552 |
|
|
|
553 |
|
|
|
554 |
|
|
Most embedded applications do not require the ability to kill off a
|
555 |
|
|
thread asynchronously, and hence the kill routine will not get linked
|
556 |
|
|
into the final application image. Without compile-time configurability
|
557 |
|
|
this would still mean that the mutex code and similar parts of the
|
558 |
|
|
system contain code and data that serve no useful purpose in this
|
559 |
|
|
application. The &eCos; approach allows the user to select that the
|
560 |
|
|
thread kill functionality is not required, and all the components can
|
561 |
|
|
adapt to this at compile-time. For example the code in the mutex lock
|
562 |
|
|
routine contains statements to support the killing of threads, but
|
563 |
|
|
these statements will only get compiled in if that functionality is
|
564 |
|
|
required. The overall result is that the final application image
|
565 |
|
|
contains only the code and data that is really needed for the
|
566 |
|
|
application to work, and nothing else.
|
567 |
|
|
|
568 |
|
|
|
569 |
|
|
Of course there are complications. To return to the button example,
|
570 |
|
|
the application code might only use text buttons directly, but it
|
571 |
|
|
might also use some higher-level widget such as a file selector and
|
572 |
|
|
this file selector might require buttons with pictures. Therefore the
|
573 |
|
|
button code must still be compiled to support pictures as well as
|
574 |
|
|
text. The configuration tools must be aware of the dependencies
|
575 |
|
|
between components and ensure that the internal constraints are met,
|
576 |
|
|
as well as the external requirements of the application code. An area
|
577 |
|
|
of particular concern is conflicting requirements: a button component
|
578 |
|
|
might be written in such a way that it can only support either text
|
579 |
|
|
buttons or picture buttons, but not both in one application; this
|
580 |
|
|
would represent a weakness in the component itself rather than in the
|
581 |
|
|
component framework as a whole.
|
582 |
|
|
|
583 |
|
|
|
584 |
|
|
Compile-time configurability is not intended to replace the other
|
585 |
|
|
approaches but rather to complement them. There will be times when
|
586 |
|
|
run-time selection of behavior is desirable: for example an
|
587 |
|
|
application may need to be able to change the baud rate of a serial
|
588 |
|
|
line, and the system must then provide a way of doing this at
|
589 |
|
|
run-time. There will also be times when link-time selection is
|
590 |
|
|
desirable: for example a C library might provide two different random
|
591 |
|
|
number routines rand and
|
592 |
|
|
lrand48; these do not affect other code so there
|
593 |
|
|
is no good reason for the C library component not to provide both of
|
594 |
|
|
these, and allow the application code to use none, one, or both of
|
595 |
|
|
them as appropriate; any unused functions will just get eliminated at
|
596 |
|
|
link-time. Compile-time selection of behavior is another option, and
|
597 |
|
|
it can be the most powerful one of the three and the best suited to
|
598 |
|
|
embedded systems development.
|
599 |
|
|
|
600 |
|
|
|
601 |
|
|
|
602 |
|
|
|
603 |
|
|
|
604 |
|
|
|
605 |
|
|
|
606 |
|
|
|
607 |
|
|
Degrees of Configurability
|
608 |
|
|
|
609 |
|
|
|
610 |
|
|
Components can support configurability in varying degrees. It is not
|
611 |
|
|
necessary to have any configuration options at all, and the only user
|
612 |
|
|
choice is whether or not to load a particular package. Alternatively
|
613 |
|
|
it is possible to implement highly-configurable code. As an example
|
614 |
|
|
consider a typical facility that is provided by many real-time
|
615 |
|
|
kernels, mutex locks. The possible configuration options include:
|
616 |
|
|
|
617 |
|
|
|
618 |
|
|
|
619 |
|
|
|
620 |
|
|
|
621 |
|
|
|
622 |
|
|
If no part of the application and no other component requires mutexes
|
623 |
|
|
then there is no point in having the mutex code compiled into a
|
624 |
|
|
library at all. This saves having to compile the code. In addition
|
625 |
|
|
there will never be any need for the user to configure the detailed
|
626 |
|
|
behavior of mutexes. Therefore the presence of mutexes is a
|
627 |
|
|
configuration option in itself.
|
628 |
|
|
|
629 |
|
|
|
630 |
|
|
|
631 |
|
|
|
632 |
|
|
|
633 |
|
|
Even if the application does make use of mutexes directly or
|
634 |
|
|
indirectly, this does not mean that all mutex functions have to be
|
635 |
|
|
included. The minimum functionality consists of lock and unlock
|
636 |
|
|
functions. However there are variants of the locking primitive such as
|
637 |
|
|
try-lock and try-with-timeout which may or may not be needed.
|
638 |
|
|
|
639 |
|
|
|
640 |
|
|
Generally it will be harmless to compile the try-lock function even if
|
641 |
|
|
it is not actually required, because the function will get eliminated
|
642 |
|
|
at link-time. Some users might take the view that the try-lock
|
643 |
|
|
function should never get compiled in unless it is actually needed, to
|
644 |
|
|
reduce compile-time and disk usage. Other users might argue that there
|
645 |
|
|
are very few valid uses for a try-lock function and it should not be
|
646 |
|
|
compiled by default to discourage incorrect uses. The presence of a
|
647 |
|
|
try-lock function is a possible configuration option, although it may
|
648 |
|
|
be sensible to default it to true.
|
649 |
|
|
|
650 |
|
|
|
651 |
|
|
The try-with-timeout variant is more complicated because it adds a
|
652 |
|
|
dependency: the mutex code will now rely on some other component to
|
653 |
|
|
provide a timer facility. To make things worse the presence of this
|
654 |
|
|
timer might impact other components, for example it may now be
|
655 |
|
|
necessary to guard against timer interrupts, and thus have an
|
656 |
|
|
insidious effect on code size. The presence of a lock-with-timeout
|
657 |
|
|
function is clearly a sensible configuration option, but the default
|
658 |
|
|
value is less obvious. If the option is enabled by default then the
|
659 |
|
|
final application image may end up with code that is not actually
|
660 |
|
|
essential. If the option is disabled by default then users will have
|
661 |
|
|
to enable the option somehow in order to use the function, implying
|
662 |
|
|
more effort on the part of the user. One possible approach is to
|
663 |
|
|
calculate the default value based on whether or not a timer component
|
664 |
|
|
is present anyway.
|
665 |
|
|
|
666 |
|
|
|
667 |
|
|
|
668 |
|
|
|
669 |
|
|
|
670 |
|
|
The application may or may not require the ability to create and
|
671 |
|
|
destroy mutexes dynamically. For most embedded systems it is both less
|
672 |
|
|
error-prone and more efficient to create objects like mutexes
|
673 |
|
|
statically. Dynamic creation of mutexes can be implemented using a
|
674 |
|
|
pre-allocated pool of mutex objects, involving some extra code to
|
675 |
|
|
manipulate the pool and an additional configuration option to define
|
676 |
|
|
the size of the pool. Alternatively it can be implemented using a
|
677 |
|
|
general-purpose memory allocator, involving quite a lot of extra code
|
678 |
|
|
and configuration options. However this general-purpose memory
|
679 |
|
|
allocator may be present anyway to support the application itself or
|
680 |
|
|
some other component. The ability to create and destroy mutexes
|
681 |
|
|
dynamically is a configuration option, and there may not be a sensible
|
682 |
|
|
default that is appropriate for all applications.
|
683 |
|
|
|
684 |
|
|
|
685 |
|
|
|
686 |
|
|
|
687 |
|
|
|
688 |
|
|
An important issue for mutex locks is the handling of priority
|
689 |
|
|
inversion, where a high priority thread is prevented from running
|
690 |
|
|
because it needs a lock owned by a lower priority thread. This is only
|
691 |
|
|
an issue if there is a scheduler with multiple priorities: some
|
692 |
|
|
systems may need multi-threading and hence synchronization primitives,
|
693 |
|
|
but a single priority level may suffice. If priority inversion is a
|
694 |
|
|
theoretical possibility then the application developer may still want
|
695 |
|
|
to ignore it because the application has been designed such that the
|
696 |
|
|
problem cannot arise in practice. Alternatively the developer may want
|
697 |
|
|
some sort of exception raised if priority inversion does occur,
|
698 |
|
|
because it should not happen but there may still be bugs in the code.
|
699 |
|
|
If priority inversion can occur legally then there are three main ways
|
700 |
|
|
of handling it: priority ceilings, priority inheritance, and ignoring
|
701 |
|
|
the problem. Priority ceilings require little code but extra effort on
|
702 |
|
|
the part of the application developer. Priority inheritance requires
|
703 |
|
|
more code but is automatic. Ignoring priority inversion may or may not
|
704 |
|
|
be acceptable, depending on the application and exactly when priority
|
705 |
|
|
inversion can occur. Some of these choices involve additional
|
706 |
|
|
configuration options, for example there are different ways of raising
|
707 |
|
|
an exception, and priority inheritance may or may not be applied
|
708 |
|
|
recursively.
|
709 |
|
|
|
710 |
|
|
|
711 |
|
|
|
712 |
|
|
|
713 |
|
|
|
714 |
|
|
As a further complication some mutexes may be hidden inside a
|
715 |
|
|
component rather than being an explicit part of the application. For
|
716 |
|
|
example, if the C library is configured to provide a
|
717 |
|
|
malloc call then there may be an associated mutex
|
718 |
|
|
to make the function automatically thread-safe, with no need for
|
719 |
|
|
external locking. In such cases the memory allocation component of the
|
720 |
|
|
C library can impose a constraint on the kernel, requiring that
|
721 |
|
|
mutexes be provided. If the user attempts to disable mutexes anyway
|
722 |
|
|
then the configuration tools will report a conflict.
|
723 |
|
|
|
724 |
|
|
|
725 |
|
|
|
726 |
|
|
|
727 |
|
|
|
728 |
|
|
The mutex code should contain some general debugging code such as
|
729 |
|
|
assertions and tracing. Usually such debug support will be enabled or
|
730 |
|
|
disabled at a coarse level such as the entire system or everything
|
731 |
|
|
inside the kernel, but sometimes it will be desirable to enable the
|
732 |
|
|
support more selectively. One reason would be memory requirements: the
|
733 |
|
|
target may not have enough memory to hold the system if all debugging
|
734 |
|
|
is enabled. Another reason is if most of the system is working but
|
735 |
|
|
there are a few problems still to resolved; enabling debugging in the
|
736 |
|
|
entire system might change the system's timing behavior too much, but
|
737 |
|
|
enabling some debug options selectively can still be useful. There
|
738 |
|
|
should be configuration options to allow specific types of debugging
|
739 |
|
|
to be enabled at a fine-grain, but with default settings inherited
|
740 |
|
|
from an enclosing component or from global settings.
|
741 |
|
|
|
742 |
|
|
|
743 |
|
|
|
744 |
|
|
|
745 |
|
|
|
746 |
|
|
The mutex code may contain specialized code to interact
|
747 |
|
|
with a debugging tool running on the host. It should be
|
748 |
|
|
possible to enable or disable this debugging code, and there may
|
749 |
|
|
be additional configuration options controlling the detailed
|
750 |
|
|
behavior.
|
751 |
|
|
|
752 |
|
|
|
753 |
|
|
|
754 |
|
|
|
755 |
|
|
|
756 |
|
|
|
757 |
|
|
Altogether there may be something like ten to twenty configuration
|
758 |
|
|
options that are specific to the mutex code. There may be a similar
|
759 |
|
|
number of additional options related to assertions and other debug
|
760 |
|
|
facilities. All of the options should have sensible default values,
|
761 |
|
|
possibly fixed, possibly calculated depending on what is happening
|
762 |
|
|
elsewhere in the configuration. For example the default setting for
|
763 |
|
|
an assertion option should generally inherit from a kernel-wide
|
764 |
|
|
assertion control option, which in turn inherits from a global option.
|
765 |
|
|
This allows users to enable or disable assertions globally or at
|
766 |
|
|
a more fine-grained level, as desired.
|
767 |
|
|
|
768 |
|
|
|
769 |
|
|
Different components may be configurable to different degrees, ranging
|
770 |
|
|
from no options at all to the fine-grained configurability of the
|
771 |
|
|
above mutex example (or possibly even further). It is up to component
|
772 |
|
|
writers to decide what options should be provided and how best to
|
773 |
|
|
serve the needs of application developers who want to use that
|
774 |
|
|
component.
|
775 |
|
|
|
776 |
|
|
|
777 |
|
|
|
778 |
|
|
|
779 |
|
|
|
780 |
|
|
|
781 |
|
|
|
782 |
|
|
Warnings
|
783 |
|
|
|
784 |
|
|
Large parts of &eCos; were developed concurrently with the development
|
785 |
|
|
of the configuration technology, or in some cases before design work
|
786 |
|
|
on that technology was complete. As a consequence the various &eCos;
|
787 |
|
|
packages often make only limited use of the available functionality.
|
788 |
|
|
This situation is expected to change over time. It does mean that many
|
789 |
|
|
of the descriptions in this guide will not correspond exactly to how
|
790 |
|
|
the &eCos; packages work right now, but rather to how they could work.
|
791 |
|
|
Some of the more extreme discrepancies such as the location of on-line
|
792 |
|
|
documentation in the component repository will be mentioned in the
|
793 |
|
|
appropriate places in the guide.
|
794 |
|
|
|
795 |
|
|
|
796 |
|
|
A consequence of this is that developers of new components can look at
|
797 |
|
|
existing &CDL; scripts for examples, and discover discrepancies
|
798 |
|
|
between what is recommended in this guide and what actually happens at
|
799 |
|
|
present. In such cases this guide should be treated as authoritative.
|
800 |
|
|
|
801 |
|
|
|
802 |
|
|
It is also worth noting that the current component framework is not
|
803 |
|
|
finished. Various parts of this guide will refer to possible changes
|
804 |
|
|
and enhancements in future versions. Examining the source code of the
|
805 |
|
|
configuration tools may reveal hints about other likely developments,
|
806 |
|
|
and there are many more possible enhancements which only exist at a
|
807 |
|
|
conceptual level right now.
|
808 |
|
|
|
809 |
|
|
|
810 |
|
|
|
811 |
|
|
|
812 |
|
|
|
813 |
|
|
|
814 |
|
|
|