100% found this document useful (1 vote)
862 views

Build Process of Embedded System

The build process for embedded systems involves three main steps: 1. Preprocessing: The C code is preprocessed by expanding macros and includes. This results in a preprocessed code file. 2. Compilation: The preprocessed code is compiled by parsing and generating an object file and list file. This converts the code to machine-understandable object code. 3. Linking: Multiple object files and libraries are linked to generate the final executable file that can be loaded onto the target processor. The map file provides memory allocation details.

Uploaded by

anitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
862 views

Build Process of Embedded System

The build process for embedded systems involves three main steps: 1. Preprocessing: The C code is preprocessed by expanding macros and includes. This results in a preprocessed code file. 2. Compilation: The preprocessed code is compiled by parsing and generating an object file and list file. This converts the code to machine-understandable object code. 3. Linking: Multiple object files and libraries are linked to generate the final executable file that can be loaded onto the target processor. The map file provides memory allocation details.

Uploaded by

anitha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Build Process

for
Embedded Systems

6/19/2013 1
 Build Process is the process of transforming human understandable code to
machine understandable code.

Human Machine
Understandable code Build Process Understandable code
(High Level Language) (Low Level Language)

 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
Human Communication
Build Machine Target Processor
Understandable Understandable Link
code Process code

6/19/2013 2
 The steps involved in build process are listed as follows:
C language code (.C file) Build Process Outputs at
each step

Computer Preprocessor file


(.cpp file)

Object file (.obj file)


&
List file (.lst file)
Link file (.lkf file)

Final executable file Map File


(.hex, .bin, .elf, etc.) (.map file)

6/19/2013 3
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) Macro ‘SET’ is defined with value = 1

#include “header.h” Header file with name header.h is included in main.c

6/19/2013 4
Following block diagram shows the tasks done during preprocessing:
PRE-PROCESSOR
EXPAND EXPAND MACROS AND
REMOVE ALL Preprocessed
Source Code INCLUDE REPLACE SYMBOLIC
COMMENTS code
FILES CONSTANTS

Let us see through /* Source File (src.C) */


an example: #define radius _cm 2 /* header file (myfile.h) */
#include “myfile.h”
Before
Int main (void) #define pi 3.14
Preprocessing:
{ #define cube(x) (x)^3
float i = radius_cm; extern float j = pi*1.33;
float Volume = j*cube(i);
return 0;
During
}
Preprocessing:
#define radius _cm 2
#define radius _cm 2 #define pi 3.14
extern float j= 3.14*1.33;
#include “myfile.h” #define cube(x) (x)^3
int main(void)
int main(void) extern float j= pi*1.33; Preprocessed
Source {
{ int main(void) code
Code float i= 2;
float i= radius_cm; {
float Volume= j*i^3;
float Volume= j*cube(i); float i= radius_cm;
return 0;
return 0; float Volume= j*cube(i);
}
}
6/19/2013 return 0; 5
}
 The steps involved in build process are listed as follows:
C language code (.C file) Build Process Outputs at
each step

Computer Preprocessor file


(.cpp file)

Object file (.obj file)


&
List file (.lst file)
Link file (.lkf file)

Final executable file Map File


(.hex, .bin, .elf, etc.) (.map file)

6/19/2013 6
 During compilation, code written in High Level Language is converted into machine understandable
code.
 Compilation process can be split up in 2 steps:

Compilation Object
Preprocessed Object File File
Code Parsing +
Generation
List File
 Tasks done during compilation (Step- 1, Parsing)are as follows:

 Validate the use of variables.


e.g.- Int extern = 1;

Preprocessed  Checks for the semantic errors.


Code Parsed Code
e.g.- Int a= 1

 Checks for the external variables used in the source file.


Text Data
int main (void) extern float j = 4.17;
float i = 2;
In step-2(Object Code Generation) of compilation, float Volume = j*i^3; /* Contains initialized
object code and list file are generated. return 0; global variables*/
/*Contains code and
local variables*/
Stack BSS
int j;
extern float j = 4.17; /*Contains data
int j; Compilation produced during /*Contains uninitialized
program execution*/ global variables*/
int main(void)
{
Object File
4066 ; 12 int main(void)
float i = 2; Generation 4066 ; 13 {
float Volume = j*i^3; 4068 switch .text
return 0; 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;
Parsed Code 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 . Allocation is irrespective of target
 List file contains the all opcodes at an allocated address. memory address.
Example of Compilation process in Integrated Development Environment
Let us take an example of compilation process of LED_Toggle.c

Compilation commands
Cxstm8: Cross Compiler for STM8 family MCUs.

+mods0: Short Stack


+debug: To generate debug information

-pxp: Don’t use absolute paths in debug information

-no: Optimization is disabled


-pp: Enforce prototyping for function

-i: Generate list (.ls) file

-i ..\inc: Add all files from “inc” folder


-i"C:\Program Files\COSMIC\CXSTM8_EVAL\Hstm8“:
Add all files from “Hstm8” folder

-clDebug\: Locating list file in the debug folder

-coDebug\: Locating list file in the debug folder

..\src\led_toggle.c: Add led_toggle.c file from src


folder

9
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.
 The steps involved in build process are listed as follows:
C language code (.C file) Build Process Outputs at
each step

Computer Preprocessor file


(.cpp file)

Object file (.obj file)


&
List file (.lst file)
Link file (.lkf file)

Final executable file Map File


(.hex, .bin, .elf, etc.) (.map file)

6/19/2013 11
 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 Cross-Compiler Object File 1


L
I
C source file 2 Cross-Compiler Object File 2
N Relocatable
K Object File

E
Assembly
source file
Cross-Assembler Object File 3 R

6/19/2013 12
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.

File: one.c Cross-Compiler File: one.obj


………….
Cross-Compiler
int sec; MOVE R1, (sec);
Address File: final.exe
…….. CALL fun1;
…….. ……..
fun1(sec); ………
1000 MOVE R1, 2388
……… ………
1004 CALL 1547

Linker
……. …….
1547 MOVE R5,R1
File: two.c File: two.obj ……. ADD R5, 0x1234
…………. ……. …….
Cross-Compiler

Int time
…….. fun1: 2388 (Value of sec)
fun1 (time) MOV R5,R1
{ ADD R5, 0x1234
……. ………
}

6/19/2013 13
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
 The steps involved in build process are listed as follows:
C language code (.C file) Build Process Outputs at
each step

Computer Preprocessor file


(.cpp file)

Object file (.obj file)


&
List file (.lst file)
Link file (.lkf file)

Final executable file Map File


(.hex, .bin, .elf, etc.) (.map file)

6/19/2013 15
 Locator performs the task of assigning physical memory addresses (either RAM or ROM)
to the data and code sections of relocatable program.
Address File: final.exe
Final.exe
…….. ……..
1000 MOVE R1, 2388 /* RAM */ /* ROM */
1004 CALL 1547
……. ……. - Data - Code
1547 MOVE R5,R1 - Constants
……. ADD R5, 0x1234 - Global Variables
……. ……. …………
2388 (Value of sec)
Locator
LINKER File
MAP File
It contains MCU memory addresses It contains:
available for all segments of code. 1. Code Segments & their MCU
SEGMENTS: CODE memory addresses.
CONSTANTS 2. Functions & their address
EEPROM 3. Required Stack Size
ZERO PAGE 4. Symbol Table
……………
…………..

Locator
6/19/2013can be available as a separate tool or bundled with the linking step. 16
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
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) Object Files (.O)
Hexadecimal interchange format
List Files (.LS) file (.S19)

Map File (.MAP) (.SM8)


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
6/19/2013 20
6/19/2013 21

You might also like