Upload
gourav-kumar
View
118
Download
3
Tags:
Embed Size (px)
DESCRIPTION
Steps and details of a Build Process and a bit description of build process using ST Visual Develop
Citation preview
16/19/2013
Build Processfor
Embedded Systems
2
What is a build process? Build Process is the process of transforming human understandable code to machine understandable code.
Build ProcessHuman
Understandable code(High Level Language)
Machine Understandable code(Low Level Language)
6/19/2013NOTE: Host and Target Processors may or may not be same.
Target ProcessorCommunication Link
Host Processor
Build Process
Machine Understandable
code
Human Understandable
code
In Embedded systems, there are 2 processors:
1. HOST: On which program is built.
2. TARGET: On which program is to be loaded.
36/19/2013
Disintegration of build process The steps involved in build process are listed as follows:
Preprocessing
Compiling (Assembling)
Locator
Linker
C language code (.C file)
Final executable file (.hex, .bin, .elf, etc.)
Link file (.lkf file)
Computer Preprocessor file(.cpp file)
Object file (.obj file)&
List file (.lst file)
Step 2
Step 3
Step 4
Step 1
Build Process Outputs at each step
Map File(.map file)
46/19/2013
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.
NOTE: The output of preprocessing is a temporary file which is usually removed after
compilation process.
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
56/19/2013
/* header file (myfile.h) */
#define pi 3.14#define cube(x) (x)^3extern float j = pi*1.33;
/* 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)^3extern 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;}
#define radius _cm 2#include “myfile.h”int main(void){ float i= radius_cm; float Volume= j*cube(i); return 0;}
Preprocessing
REMOVE ALL COMMENTS
EXPAND INCLUDE
FILES
EXPAND MACROS AND REPLACE SYMBOLIC
CONSTANTS
PRE-PROCESSOR
Source Code Preprocessed code
Following block diagram shows the tasks done during preprocessing:
Before Preprocessing:
Let us see through an example:
During Preprocessing:
Source Code
Preprocessed code
66/19/2013
Disintegration of build process The steps involved in build process are listed as follows:
Preprocessing
Compiling (Assembling)
Locator
Linker
C language code (.C file)
Final executable file (.hex, .bin, .elf, etc.)
Link file (.lkf file)
Computer Preprocessor file(.cpp file)
Object file (.obj file)&
List file (.lst file)
Step 2
Step 3
Step 4
Step 1
Build Process Outputs at each step
Map File(.map file)
Compiling During compilation, code written in High Level Language is converted into machine understandable code. Compilation process can be split up in 2 steps:
Parsing Object File Generation
CompilationPreprocessed
Code
Object File
+List File
NOTE: Compiler works on a single source file at a time.
Parsing
Preprocessed Code Parsed Code
Tasks done during compilation (Step- 1, Parsing)are as follows:
Any keyword cannot be used as a variable name
Colon is missing
Validate the use of variables. e.g.- Int extern = 1;
Checks for the semantic errors. e.g.- Int a= 1
Checks for the external variables used in the source file.
Compiling
Object File Generation
Compilationextern 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 .text4069 0000 _main:4071 0000 520c subw sp, #124072 0000000c OFST : set 124075 ; 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
4080 ; .. .. .. .. ..
Object file contains ‘binary’ image of code divided into multiple segments .
List file contains the all opcodes at an allocated address.
Textint main (void)float i = 2;float Volume = j*i^3;return 0;/*Contains code and local variables*/
Dataextern float j = 4.17;
/* Contains initialized global variables*/
BSSint j;
/*Contains uninitialized global variables*/
Stack
/*Contains data produced during program execution*/
Object File
List File
Allocation is irrespective of target memory address.
NOTE: Typically, Object file contain more segments than shown here.
In step-2(Object Code Generation) of compilation, object code and list file are generated.
9
Example of Compilation process in Integrated Development EnvironmentLet us take an example of compilation process of LED_Toggle.c
ProcessorProject Name
Workspace
Output Window:Toolset
No. of errors and Warnings
Code in C language
Cxstm8: Cross Compiler for STM8 family MCUs.
+mods0: Short Stack
+debug: To generate debug information
-no: Optimization is disabled
-i ..\inc: Add all files from “inc” folder
-pp: Enforce prototyping for function
-clDebug\: Locating list file in the debug folder
-i"C:\Program Files\COSMIC\CXSTM8_EVAL\Hstm8“:Add all files from “Hstm8” folder
..\src\led_toggle.c: Add led_toggle.c file from src folder
-coDebug\: Locating list file in the debug folder
-pxp: Don’t use absolute paths in debug information
Compilation commands
-i: Generate list (.ls) file
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.
Example of Compilation process in Integrated Development Environment
Also take a look at the files and folders in the directory after compiling.
List File
Object File
Folders in IDE workspace
116/19/2013
Disintegration of build process The steps involved in build process are listed as follows:
Preprocessing
Compiling (Assembling)
Locator
Linker
C language code (.C file)
Final executable file (.hex, .bin, .elf, etc.)
Link file (.lkf file)
Computer Preprocessor file(.cpp file)
Object file (.obj file)&
List file (.lst file)
Step 2
Step 3
Step 4
Step 1
Build Process Outputs at each step
Map File(.map file)
126/19/2013
Linking The object file is not a executable file due to following issues:1. No references to external variables or functions2. No unique address for each opcode (in case of multiple source files).
C source file 1
C source file 2
Assembly source file
Cross-Compiler
Cross-Compiler
Cross-Assembler Object File 3
Object File 2
Object File 1
Linker produces a ‘relocatable copy’ of the program by merging all the code and data sections from all the object files.
LINKER
Relocatable Object File
136/19/2013
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.
Linking
File: two.cInt time……..fun1 (time) {…….}
File: one.c
int sec;……..fun1(sec);………
Address……..10001004…….
1547…….…….
2388
File: final.exe……..MOVE R1, 2388CALL 1547…….MOVE R5,R1ADD R5, 0x1234…….(Value of sec)
Link
er
File: one.obj………….MOVE R1, (sec);CALL fun1; ……… ………
File: two.obj………….fun1: MOV R5,R1ADD R5, 0x1234 ………
Cros
s-Co
mpi
ler
Cros
s-Co
mpi
ler
Cros
s-Co
mpi
ler
146/19/2013
Is our build process complete?
For Software programmers, the answer is YES. The build process finishes with linking.
NOYES or
The answer is both.
?Let us see how…
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.
156/19/2013
Disintegration of build process The steps involved in build process are listed as follows:
Preprocessing
Compiling (Assembling)
Locator
Linker
C language code (.C file)
Final executable file (.hex, .bin, .elf, etc.)
Link file (.lkf file)
Computer Preprocessor file(.cpp file)
Object file (.obj file)&
List file (.lst file)
Step 2
Step 3
Step 4
Step 1
Build Process Outputs at each step
Map File(.map file)
166/19/2013
Locating Locator performs the task of assigning physical memory addresses (either RAM or ROM) to the data and code sections of relocatable program.
NOTE: Locator can be available as a separate tool or bundled with the linking step.
Address……..10001004…….
1547…….…….
2388
File: final.exe……..MOVE R1, 2388CALL 1547…….MOVE R5,R1ADD R5, 0x1234…….(Value of sec)
LocatorMAP File It contains:1. Code Segments & their MCU
memory addresses.2. Functions & their address3. Required Stack Size4. Symbol Table ……………
/* RAM */
- Data
/* 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
176/19/2013
Example of complete build process in IDE
Code in C language
Output Window
Final Executable File
Compiling source file
Clnk: Combines relocatable object files from cosmic library.
-o: Outputs following files to the specified directory.1. (.sm8): SM8 file2. (.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.
Linker commands
-l: Specify library path
Compiling ISR source file
Linking
-o: Outputs following files to the specified directory.1. (.s19): S19 file2. (.sm8): SM8 file
Example of complete build process in IDE
Also take a look at the files and folders in the directory after build process.
Folders in IDE workspace
Final Executable File (.ELF)
Linker File (.LKF)
List Files (.LS)
Map File (.MAP)
Object Files (.O)Hexadecimal interchange format
file (.S19)
(.SM8)
196/19/2013
Bibliography1. “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.
206/19/2013
216/19/2013