1
/** @page build_sys Build system
3
@section overview Overview
5
Building an Etherboot image consists of three stages:
7
-# @ref compilation : Compiling all the source files into object files
8
-# @ref linking : Linking a particular image from selected object files
9
-# @ref finalisation : Producing the final output binary
11
Though this is a remarkably complex process, it is important to note
12
that it all happens automatically. Whatever state your build tree is
13
in, you can always type, for example
21
and know that you will get a floppy disk image with an RTL8139 driver
22
built from the current sources.
24
@section compilation Compilation
26
@subsection comp_overview Overview
28
Each source file (a @c .c or a @c .S file) is compiled into a @c .o
29
file in the @c bin/ directory. Etherboot makes minimal use of
30
conditional compilation (see @ref ifdef_harmful), and so you will find
31
that all objects get built, even the objects that correspond to
32
features that you are not intending to include in your image. For
33
example, all network card drivers will be compiled even if you are
34
just building a ROM for a 3c509 card. This is a deliberate design
35
decision; please do @b not attempt to "fix" the build system to avoid
38
Source files are defined to be any @c .c or @c .S files found in a
39
directory listed in the Makefile variable #SRCDIRS. You therefore do
40
@b not need to edit the Makefile just because you have added a new
41
source file (although you will need to edit the Makefile if you have
42
added a new source directory). To see a list of all source
43
directories and source files that the build system currently knows
44
about, you can use the commands
53
Rules for compiling @c .c and @c .S files are defined in the Makefile
54
variables #RULE_c and #RULE_S. Makefile rules are automatically
55
generated for each source file using these rules. The generated rules
56
can be found in the @c .d file corresponding to each source file;
57
these are located in <tt>bin/deps/</tt>. For example, the rules
58
generated for <tt>drivers/net/rtl8139.c</tt> can be found in
59
<tt>bin/deps/drivers/net/rtl8139.c.d</tt>. These rules allow you to
68
and have <tt>rtl8139.o</tt> be built from
69
<tt>drivers/net/rtl8139.c</tt> using the generic rule #RULE_c for
70
compiling @c .c files.
72
You can see the full list of object files that will be built using
80
@subsection comp_ar After compilation
82
Once all objects have been compiled, they will be collected into a
83
build library ("blib") in <tt>bin/blib.a</tt>.
85
@subsection comp_custom Customising compilation
87
The Makefile rules for a particular object can be customised to a
88
certain extent by defining the Makefile variable CFLAGS_@<object@>.
89
For example, if you were to set
93
CFLAGS_rtl8139 = -DFOO
97
then <tt>bin/rtl8139.o</tt> would be compiled with the additional
98
flags <tt>-DFOO</tt>. To see the flags that will be used when
99
compiling a particular object, you can use e.g.
103
make bin/rtl8139.flags
107
If you need more flexibility than the CFLAGS_@<object@> mechanism
108
provides, then you can exclude source files from the automatic rule
109
generation process by listing them in the Makefile variable
110
#NON_AUTO_SRCS. The command
118
will show you which files are currently part of the automatic rule
121
@subsection comp_multiobj Multiple objects
123
A single source file can be used to generate multiple object files.
124
This is used, for example, to generate the decompressing and the
125
non-decompressing prefixes from the same source files.
127
By default, a single object will be built from each source file. To
128
override the list of objects for a source file, you can define the
129
Makefile variable OBJS_@<object@>. For example, the
130
<tt>arch/i386/prefix/dskprefix.S</tt> source file is built into two
131
objects, <tt>bin/dskprefix.o</tt> and <tt>zdskprefix.o</tt> by
132
defining the Makefile variable
136
OBJS_dskprefix = dskprefix zdskprefix
140
Since there would be little point in building two identical objects,
141
customised compilation flags (see @ref comp_custom) are defined as
145
CFLAGS_zdskprefix = -DCOMPRESS
149
Thus, <tt>arch/i386/prefix/dskprefix.S</tt> is built into @c
150
dskprefix.o using the normal set of flags, and into @c zdskprefix.o
151
using the normal set of flags plus <tt>-DCOMPRESS</tt>.
153
@subsection comp_debug Special debugging targets
155
In addition to the basic rules #RULE_c and #RULE_S for compiling
156
source files into object files, there are various other rules that can
157
be useful for debugging.
159
@subsubsection comp_debug_c_to_c Preprocessed C
161
You can see the results of preprocessing a @c .c file (including the
162
per-object flags defined via CFLAGS_@<object@> if applicable) using
171
and examining the resulting file (<tt>bin/rtl8139.c</tt> in this
174
@subsubsection comp_debug_x_to_s Assembler
176
You can see the results of assembling a @c .c file, or of
177
preprocessing a @c .S file, using e.g.
182
make bin/zdskprefix.s
186
@subsubsection comp_debug_dbg Debugging-enabled targets
188
You can build targets with debug messages (DBG()) enabled using e.g.
192
make bin/rtl8139.dbg.o
193
make bin/rtl8139.dbg2.o
197
You will probably not need to use these targets directly, since a
198
mechanism exists to select debugging levels at build time; see @ref
201
@section linking Linking
203
@subsection link_overview Overview
205
Etherboot is designed to be small and extremely customisable. This is
206
achieved by linking in only the features that are really wanted in any
209
There are two places from which the list of desired features is
212
-# @ref link_config_h
215
@subsection link_config_h config.h
217
The config.h file is used to define global build options that are
218
likely to apply to all images that you build, such as the console
219
types, supported download protocols etc. See the documentation for
220
config.h for more details.
222
@subsection link_cmdline The make command line
224
When you type a command such as
232
it is used to derive the following information:
234
- We are building a compressed ROM image
235
- The DFE538 is a PCI NIC, so we need the decompressing PCI ROM prefix
236
- The PCI IDs for the DFE538 are 1186:1300
237
- The DFE538 is an rtl8139-based card, therefore we need the rtl8139 driver
239
You can see this process in action using the command
243
make bin/dfe538.zrom.info
261
LD driver symbols : obj_rtl8139
262
LD prefix symbols : obj_zpciprefix
263
LD ID symbols : pci_vendor_id=0x1186 pci_device_id=0x1300
265
LD target flags : -u obj_zpciprefix --defsym check_obj_zpciprefix=obj_zpciprefix -u obj_rtl8139 --defsym check_obj_rtl8139=obj_rtl8139 -u obj_config --defsym check_obj_config=obj_config --defsym pci_vendor_id=0x1186 --defsym pci_device_id=0x1300
269
This should be interpreted as follows:
278
"Elements" is the list of components preceding the first dot in the
279
target name. "Prefix" is the component following the first dot in the
280
target name. (It's called a "prefix" because the code that makes it a
281
@c .zrom (rather than a @c .dsk, @c .zpxe or any other type of target)
282
usually ends up at the start of the resulting binary image.)
290
"Drivers" is the list of drivers corresponding to the "Elements".
291
Most drivers support several network cards. The PCI_ROM() and
292
ISA_ROM() macros are used in the driver source files to list the cards
293
that a particular driver can support.
301
"ROM name" is the first element in the "Elements" list. It is used to
302
select the PCI IDs for a PCI ROM.
310
"Media" is the "Prefix" minus the leading @c z, if any.
320
These are derived from the "ROM name" and the PCI_ROM() or ISA_ROM()
321
macros in the driver source files.
325
LD driver symbols : obj_rtl8139
326
LD prefix symbols : obj_zpciprefix
330
This is the interesting part. At this point, we have established that
331
we need the rtl8139 driver (i.e. @c rtl8139.o) and the decompressing
332
PCI prefix (i.e. @c zpciprefix.o). Our build system (via the
333
compiler.h header file) arranges that every object exports a symbol
334
obj_@<object@>; this can be seen by e.g.
338
objdump -t bin/rtl8139.o
342
which will show the line
346
00000000 g *ABS* 00000000 obj_rtl8139
350
By instructing the linker that we need the symbols @c obj_rtl8139 and
351
@c obj_zpciprefix, we can therefore ensure that these two objects are
352
included in our build. (The linker will also include any objects that
353
these two objects require, since that's the whole purpose of the
356
In a similar way, we always instruct the linker that we need the
357
symbol @c obj_config, in order to include the object @c config.o. @c
358
config.o is used to drag in the objects that were specified via
359
config.h; see @ref link_config_h.
363
LD target flags : -u obj_zpciprefix --defsym check_obj_zpciprefix=obj_zpciprefix -u obj_rtl8139 --defsym check_obj_rtl8139=obj_rtl8139 -u obj_config --defsym check_obj_config=obj_config --defsym pci_vendor_id=0x1186 --defsym pci_device_id=0x1300
367
These are the flags that we pass to the linker in order to include the
368
objects that we want in our build, and to check that they really get
369
included. (This latter check is needed to work around what seems to
372
The linker does its job of linking all the required objects together
373
into a coherent build. The best way to see what is happening is to
374
look at one of the resulting linker maps; try, for example
378
make bin/dfe538.dsk.map
382
The linker map includes, amongst others:
384
- A list of which objects are included in the build, and why.
385
- The results of processing the linker script, line-by-line.
386
- A complete symbol table of the resulting build.
388
It is worth spending time examining the linker map to see how an
389
Etherboot image is assembled.
391
Whatever format is selected, the Etherboot image is built into an ELF
392
file, simply because this is the default format used by @c ld.
394
@section finalisation Finalisation
396
@subsection final_overview Overview
398
The ELF file resulting from @ref linking "linking" needs to be
399
converted into the final binary image. Usually, this is just a case
404
objcopy -O binary <elf file> <output file>
408
to convert the ELF file into a raw binary image. Certain image
409
formats require special additional treatment.
411
@subsection final_rom ROM images
413
ROM images must be rounded up to a suitable ROM size (e.g. 16kB or
414
32kB), and certain header information such as checksums needs to be
415
filled in. This is done by the @c makerom.pl program.
417
@section debug Debugging-enabled builds