2. Build Process is the process of transforming human understandable code to
machine understandable code.
Build Process
Human
Understandable code
(High Level Language)
Machine
Understandable code
(Low Level Language)
Target Processor
Communication
Link
In Embedded systems, there are 2 processors:
1. HOST: On which program is built.
2. TARGET: On which program is to be loaded.
Host Processor
Build
Process
Machine
Understandable
code
6/19/2013 2
Human
Understandable
code
3. The steps involved in build process are listed as follows:
C language code (.C file)
Final executable file
(.hex, .bin, .elf, etc.)
Build Process Outputs at
each step
Computer Preprocessor file
(.cpp file)
Object file (.obj file)
&
List file (.lst file)
Link file (.lkf file)
Map File
(.map file)
6/19/2013 3
4. Preprocessing
A C preprocessor is a program that accepts C code with preprocessing statements and
produces a pure form of C code that contains no preprocessing statements.
All preprocessing statements in C begin with the # symbol and are at the beginning of a
line.
Format:
#preprocessor directive
e.g. #define SET (1)
#include “header.h”
Macro ‘SET’ is defined with value = 1
Header file with name header.h is included in main.c
6/19/2013 4
5. Following block diagram shows the tasks done during preprocessing:
PRE-PROCESSOR
EXPAND MACROS AND
REPLACE SYMBOLIC
CONSTANTS
/* header file (myfile.h) */
#define pi 3.14
#define cube(x) (x)^3
extern float j = pi*1.33;
REMOVE ALL
COMMENTS
EXPAND
INCLUDE
FILES
/* Source File (src.C) */
#define radius _cm 2
#include “myfile.h”
Int main (void)
{
float i = radius_cm;
float Volume = j*cube(i);
return 0;
}
#define radius _cm 2
#define pi 3.14
#define cube(x) (x)^3
extern float j= pi*1.33;
int main(void)
{
float i= radius_cm;
float Volume= j*cube(i);
return 0;
}
extern float j= 3.14*1.33;
int main(void)
{
float i= 2;
float Volume= j*i^3;
return 0;
}
Source Code
Let us see through
an example:
#define radius _cm 2
#include “myfile.h”
int main(void)
{
float i= radius_cm;
float Volume= j*cube(i);
return 0;
}
Preprocessed
code
6/19/2013 5
Before
Preprocessing:
During
Preprocessing:
Source
Code
Preprocessed
code
6. The steps involved in build process are listed as follows:
C language code (.C file)
Final executable file
(.hex, .bin, .elf, etc.)
Build Process Outputs at
each step
Computer Preprocessor file
(.cpp file)
Object file (.obj file)
&
List file (.lst file)
Link file (.lkf file)
Map File
(.map file)
6/19/2013 6
7. During compilation, code written in High Level Language is converted into machine understandable
code.
Compilation process can be split up in 2 steps:
Compilation
Parsing Object File
Generation
Preprocessed
Code
Object
File
+
List File
Tasks done during compilation (Step- 1, Parsing)are as follows:
Preprocessed
Validate the use of variables.
e.g.- Int extern = 1;
Checks for the semantic errors.
Code Parsed Code
e.g.- Int a= 1
Checks for the external variables used in the source file.
8. Compilation
Object File
Generation
extern float j = 4.17;
int j;
int main(void)
{
float i = 2;
float Volume = j*i^3;
return 0;
}
Parsed Code
4066 ; 12 int main(void)
4066 ; 13 {
4068 switch .text
4069 0000 _main:
4071 0000 520c subw sp, #12
4072 0000000c OFST : set 12
4075 ; 14 float j = pi*1.33;
4077 ; 15 float i = radius_cm;
4079 ; 16 float Volume = j*cube(i);
4081 0002 ce0002 ldw x, L7272+2 1
4079 ; .. .. .. .. ..
Object file contains ‘binary’ image of code divided into multiple segments .
List file contains the all opcodes at an allocated address.
Text
int main (void)
float i = 2;
float Volume = j*i^3;
return 0;
/*Contains code and
local variables*/
Data
extern float j = 4.17;
/* Contains initialized
global variables*/
BSS
int j;
/*Contains uninitialized
global variables*/
Stack
/*Contains data
produced during
program execution*/
Allocation is irrespective of target
memory address.
In step-2(Object Code Generation) of compilation,
object code and list file are generated.
9. Compilation commands
-pxp: Don’t use absolute paths in debug information
-i: Generate list (.ls) file
-i"C:Program FilesCOSMICCXSTM8_EVALHstm8“:
Add all files from “Hstm8” folder
9
Example of Compilation process in Integrated Development Environment
Let us take an example of compilation process of LED_Toggle.c
Cxstm8: Cross Compiler for STM8 family MCUs.
+mods0: Short Stack
+debug: To generate debug information
-no: Optimization is disabled
-pp: Enforce prototyping for function
-i ..inc: Add all files from “inc” folder
-clDebug: Locating list file in the debug folder
-coDebug: Locating list file in the debug folder
..srcled_toggle.c: Add led_toggle.c file from src
folder
10. Example of Compilation process in Integrated Development Environment
Also take a look at the files and folders in the directory after compiling.
Includes and Src folder contains .h files and .C files respectively.
Compilation generates an object and a list file in the debug folder.
Object File: Binary Image file of .C file.
List File: List of opcodes with their addresses.
11. The steps involved in build process are listed as follows:
C language code (.C file)
Final executable file
(.hex, .bin, .elf, etc.)
Build Process Outputs at
each step
Computer Preprocessor file
(.cpp file)
Object file (.obj file)
&
List file (.lst file)
Link file (.lkf file)
Map File
(.map file)
6/19/2013 11
12. The object file is not a executable file due to following issues:
1. No references to external variables or functions
2. No unique address for each opcode (in case of multiple source files).
Linker produces a ‘relocatable copy’ of the program by merging all
the code and data sections from all the object files.
C source file 1
C source file 2
Assembly
source file
Cross-Compiler
Cross-Compiler
Object File 1
Object File 2
Cross-Assembler Object File 3
L
I
N
K
E
R
Relocatable
Object File
6/19/2013 12
13. Tasks performed by Linker:
Linker resolves the external variable or function references.
Linker assigns a unique address to each opcode.
Linker also searches the libraries and link appropriate code to the application.
6/19/2013 13
File: one.c
int sec;
……..
fun1(sec);
………
File: two.c
Int time
……..
fun1 (time)
{
…….
}
Address
……..
1000
1004
…….
1547
…….
…….
2388
File: final.exe
……..
MOVE R1, 2388
CALL 1547
…….
MOVE R5,R1
ADD R5, 0x1234
…….
(Value of sec)
Linker
File: one.obj
………….
MOVE R1, (sec);
CALL fun1;
………
………
File: two.obj
………….
fun1:
MOV R5,R1
ADD R5, 0x1234
………
Cross-Compiler
Cross-Compiler Cross-Compiler
14. YES or NO
The answer is both.
Let us see how…
For Software programmers, the answer is YES.
The build process finishes with linking.
?
For Embedded programmers, the answer is NO.
So what is left for embedded programmers to do?? What is missing?
Address allocation to code and
data segment according to
processor memory organization.
6/19/2013 14
15. The steps involved in build process are listed as follows:
C language code (.C file)
Final executable file
(.hex, .bin, .elf, etc.)
Build Process Outputs at
each step
Computer Preprocessor file
(.cpp file)
Object file (.obj file)
&
List file (.lst file)
Link file (.lkf file)
Map File
(.map file)
6/19/2013 15
16. Locator performs the task of assigning physical memory addresses (either RAM or ROM)
to the data and code sections of relocatable program.
/* RAM */
- Data
Locator can be available as a separate tool or bundled with the linking step.
6/19/2013 16
Address
……..
1000
1004
…….
1547
…….
…….
2388
File: final.exe
……..
MOVE R1, 2388
CALL 1547
…….
MOVE R5,R1
ADD R5, 0x1234
…….
(Value of sec)
Locator
MAP File
It contains:
1. Code Segments & their MCU
memory addresses.
2. Functions & their address
3. Required Stack Size
4. Symbol Table
……………
/* ROM */
- Code
- Constants
- Global Variables
…………
LINKER File
It contains MCU memory addresses
available for all segments of code.
SEGMENTS: CODE
CONSTANTS
EEPROM
ZERO PAGE
…………..
Final.exe
17. Example of complete build process in IDE
Linker commands
Clnk: Combines relocatable object files from cosmic
library.
-l: Specify library path
-o: Outputs following files to the specified directory.
1. (.sm8): SM8 file
2. (.map): MAP file
-m: Generate .map file for the program being built.
3. (.lkf): LINKER file
cvdwarf: Utility to convert file produced by linker to
ELF format.
Chex: Utility to translate executable image file (.sm8)
produced by linker to hexadecimal format.
-o: Outputs following files to the specified directory.
1. (.s19): S19 file
2. (.sm8): SM8 file
6/19/2013 17
18. Example of complete build process in IDE
Also take a look at the files and folders in the directory after build process.
Final Executable File (.ELF)
Linker File (.LKF)
List Files (.LS)
Map File (.MAP)
Object Files (.O)
Hexadecimal interchange format
file (.S19)
(.SM8)
19. Bibliography
1. “Embedded Realtime Systems Programming”, Pankaj Gupta, Sriram
V Iyer, Tata McGraw- Hill publishing Company Ltd, Eighth reprint
2007.
2. “Programming Embedded Systems in C and C++”, Michael Barr,
O’Reilly & Associates, Inc., Eighth Indian Reprint 2003.
3. “An Embedded Software Primer”, David E. Simon, Pearson
Education, ISBN 81-7808-045-1, Twelfth Indian Reprint 2005.
6/19/2013 19