Mod4 Notes
Mod4 Notes
The embedded firmware is responsible for controlling the various peripherals of the
embedded hardware and generating response in accordance with the functional
requirements.
Firmware is considered as the master brain of the embedded system.
Imparting intelligence to an Embedded system is a one time process and it can happen at
any stage.
It can be immediately after the fabrication of the embedded hardware or at a later
stage.
For most of the embedded products, the embedded firmware is stored at a permanent
memory (ROM) and they are non-alterable by end users.
Some of the embedded products used in the Control and Instrumentation domain
are adaptive.
Designing embedded firmware requires understanding of the particular embedded product
hardware, like various component interfacing, memory map details, I/O port details,
configuration and register details of various hardware chips used and some programming
language.
Embedded firmware development process starts with the conversion of the firmware
requirements into a program model using modelling tools.
Once the program model is created, the next step is the implementation of the tasks and
actions by capturing the model using a language which is understandable by the target
processor/controller.
The firmware design approaches for embedded product is purely dependent on the
complexity of the functions to be performed, the speed of operation required, etc.
Two basic approaches are used for embedded firmware design:
Super Loop Based Approach (Conventional Procedural Based Design)
Embedded Operating System (OS) Based Approach
The Super Loop based firmware development approach is adopted for applications that
are not time critical and where the response time is not so important.
It is very similar to a conventional procedural programming where the code is executed
task by task.
The task listed at the top of the program code is executed first and the tasks just below the
top are executed after completing the first task.
In a multiple task based system, each task is executed in serial in this approach.
The firmware execution flow for this will be
AJIET | D E P T . O F CSE
INTRODUCTION TO EMBEDDED SYSTEMS | MODULE 4:
Embedded Firmware Design and Development
Configure the common parameters and perform initialisation for various hardware
components memory, registers, etc.
D E P T . O F CSE | AJIET
INTRODUCTION TO EMBEDDED SYSTEMS | M O D U L E 4 :
Embedded Firmware Design and Development
Almost all tasks in embedded applications are non-ending and are repeated infinitely
throughout the operation.
This repetition is achieved by using an infinite loop.
Hence the name 'Super loop based approach’.
The only way to come out of the loop is either a hardware reset or an interrupt assertion.
Advantage of Super Loop Based Approach:
It doesn't require an operating system
There is no need for scheduling which task is to be executed and assigning priority
to each task.
The priorities are fixed and the order in which the tasks to be executed are also
fixed.
Hence the code for performing these tasks will be residing in the code memory
without an operating system image.
Applications of Super Loop Based Approach:
This type of design is deployed in low-cost embedded products and products
where response time is not time critical.
Some embedded products demands this type of approach if some tasks itself are
sequential.
AJIET | D E P T . O F CSE
INTRODUCTION TO EMBEDDED SYSTEMS | MODULE 4:
Embedded Firmware Design and Development
For example, reading/writing data to and from a card using a card reader requires
a sequence of operations like checking the presence of card, authenticating the
operation, reading/writing, etc.
It should strictly follow a specified sequence and the combination of these series
of tasks constitutes a single task-namely data read/write.
A typical example of a 'Super loop based’ product is an electronic video game toy
containing keypad and display unit.
The program running inside the product may be designed in such a way that it
reads the keys to detect whether the user has given any input and if any key press
is detected the graphic display is updated.
The keyboard scanning and display updating happens at a reasonably high rate.
Even if the application misses a key press, it won't create any critical issues; rather
it will be treated as a bug in the firmware.
Drawbacks of Super Loop Based Approach:
Any failure in any part of a single task will affect the total system.
If the program hangs up at some point while executing a task, it will remain
there forever and ultimately the product stops functioning.
Watch Dog Timers (WDTs) can be used to overcome this, but this, in turn,
may cause additional hardware cost and firmware overheads.
Lack of real timeliness.
If the number of tasks to be executed within an application increases, the
time at which each task is repeated also increases.
This brings the probability of missing out some events.
The Embedded Operating System (OS) based approach contains operating systems, which
can be either a General Purpose Operating System (GPOS) or a Real Time Operating
System (RTOS) to host the user written application firmware.
The General Purpose OS (GPOS) based design is very similar to a conventional PC based
application development where the device contains an operating system
(Windows/Unix/Linux, etc. for Desktop PCs) and you will be creating and running user
applications on top of it.
Example of a GPOS used in embedded product development is Microsoft
Windows XP Embedded.
Examples of Embedded products using Microsoft Windows XP OS are Personal
Digital Assistants (PDAs), Hand held devices/Portable devices and Point of Sale
(POS) terminals.
Use of GPOS in embedded products merges the demarcation of Embedded Systems and
general computing systems in terms of OS.
For developing applications on top of the OS, the OS supported APIs are used.
Similar to the different hardware specific drivers, OS based applications also require
'Driver software' for different hardware present on the board to communicate with them.
D E P T . O F CSE | AJIET
INTRODUCTION TO EMBEDDED SYSTEMS | M O D U L E 4 :
Embedded Firmware Design and Development
Real Time Operating System (RTOS) based design approach is employed in embedded
products demanding Real-time response.
RTOS responds in a timely and predictable manner to events.
Real Time operating system contains a Real Time kernel responsible for performing pre-
emptive multitasking, scheduler for scheduling tasks, multiple threads, etc.
A Real Time Operating System (RTOS) allows flexible scheduling of system resources like
the CPU and memory and offers some way to communicate between tasks. 'Windows CE',
'pSOS', 'VxWorks', 'ThreadX', 'MicroC/OS-II’, 'Embedded Linux', 'Symbian’, etc. are
examples of RTOS employed in embedded product development.
Mobile phones, PDAs (Based on Windows CE/Windows Mobile Platforms), handheld
devices, etc. are examples of 'Embedded Products' based on RTOS.
Each source module is written in Assembly and is stored as .src file or .asm file.
Each file can be assembled separately to examine the syntax errors and incorrect assembly
instructions.
On successful assembling of each .src/.asm file a corresponding object file is created with
extension '.obj’.
D E P T . O F CSE | AJIET
INTRODUCTION TO EMBEDDED SYSTEMS | M O D U L E 4 :
Embedded Firmware Design and Development
The object file does not contain the absolute address of where the generated code
needs to be placed on the program memory and hence it is called a re-locatable
segment.
It can be placed at any code memory location and it is the responsibility. of the
linker/locater to assign absolute address for this module.
Libraries are specially formatted, ordered program collections of object modules that may
be used by the linker at a later time.
Library files are generated with extension '. lib’.
When the linker processes a library, only those object modules in the library that are
necessary to create the program are used.
Library file is some kind of source code hiding technique.
For example, 'LIB51' from Keil Software is an example for a library creator and it
is used for creating library files for A51 Assembler/C51 Compiler for 8051 specific
controllers.
Linker and Locater is another software utility responsible for "linking the various object
modules in a multi-module project and assigning absolute address to each module".
Linker generates an absolute object module by extracting the object modules from the
library, if any, and those obj files created by the assembler, which is generated by
assembling the individual modules of a project.
It is the responsibility of the linker to link any external dependent variables or functions
declared on various modules and resolve the external dependencies among the modules.
An absolute object file or module does not contain any re-locatable code or data.
All code and data reside at fixed memory locations.
The absolute object file is used for creating hex files for dumping into the code memory
of the processor/controller.
'BL51' from Keil Software is an example for a Linker & Locater for A51
Assembler/C51 Compiler for 8051 specific controller.
This is the final stage in the conversion of Assembly language (mnemonics) to machine
understandable language (machine code).
Hex File is the representation of the machine code and the hex file is dumped into the
code memory of the processor/controller.
The hex file representation varies depending on the target processor/controller make.
HEX files are ASCII files that contain a hexadecimal representation of target application.
AJIET | D E P T . O F CSE
INTRODUCTION TO EMBEDDED SYSTEMS | MODULE 4:
Embedded Firmware Design and Development
Hex file is created from the final 'Absolute Object File' using the Object to Hex File
Converter utility.
'OH51' from Keil software is an example for Object to Hex File Converter utility
for A51 Assembler/C51 Compiler for 8051 specific controller.
D E P T . O F CSE | AJIET
INTRODUCTION TO EMBEDDED SYSTEMS | M O D U L E 4 :
Embedded Firmware Design and Development
Also more lines of assembly code are required for performing an action which can
be done with a single instruction in a high-level language like 'C'.
Developer Dependency
Unlike high level languages, there is no common written rule for developing
assembly language based applications.
In assembly language programming, the developers will have the freedom to
choose the different memory location and registers.
Also the programming approach varies from developer to developer depending on
his/her taste.
For example, moving data from a memory location to accumulator can be achieved
through different approaches.
If the approach done by a developer is not documented properly at the
development stage, he/she may not be able to recollect why this approach is
followed at a later stage or when a new developer is instructed to analyse this code,
he/she also may not be able to understand what is done and why it is done.
Hence upgrading an assembly program or modifying it on a later stage is very
difficult.
Non-Portable
Target applications written in assembly instructions are valid only for that
particular family of processors (e.g. Application written for Intel x86 family of
processors) and cannot be re-used for another target processors/controllers (Say
ARM11 family of processors).
If the target processor/controller changes, a complete re-writing of the application
using the assembly instructions for the new target processor/controller is required.
Any high level language (like C, C++ or Java) with a supported cross compiler for the
target processor can be used for embedded firmware development.
The most commonly used high level language for embedded firmware application
development is 'C’.
‘C’ is well defined, easy to use high level language with extensive cross platform
development tool support.
Nowadays cross-compilers for C++ is also emerging out and embedded developers are
making use of C++ for embedded application development.
The various steps involved in high level language based embedded firmware development
is same as that of assembly language based development except that the conversion of
source file written in high level language to object file is done by a cross-compiler.
In Assembly language based development it is carried out by an assembler.
The various steps involved in the conversion of a program written in high level language
to corresponding binary file/machine language is illustrated in the figure.
AJIET | D E P T . O F CSE
INTRODUCTION TO EMBEDDED SYSTEMS | MODULE 4:
Embedded Firmware Design and Development
The program written in any of the high level languages is saved with the corresponding
language extension (.c for C, .cpp for C++ etc).
Any text editor like ‘Notepad' or 'WordPad' from Microsoft or the text editor provided by
an Integrated Development (IDE) tool can be used for writing the program.
Most of the high level languages support modular programming approach and hence we
can have multiple source files called modules written in corresponding high level language.
The source files corresponding to each module is represented by a file with corresponding
language extension.
Translation of high level source code to executable object code is done by across-compiler.
Each high level language should have a cross-compiler for converting the high level source
code into the target processor machine code.
C51 Cross-compiler from Keil software is an example for Cross-compiler used for
'C' language for the 8051 family of microcontroller.
Conversion of each module's source code to corresponding object file is performed by the
cross-compiler.
Rest of the steps involved in the conversion of high level language to target processor's
machine code are same as that of the steps involved in assembly language based
development.
D E P T . O F CSE | AJIET
INTRODUCTION TO EMBEDDED SYSTEMS | M O D U L E 4 :
Embedded Firmware Design and Development
Bare minimal knowledge of the memory organisation and register details of the
target processor in use and syntax of the high level language are the only pre-
requisites for high level language based firmware development.
With high level language, each task can be accomplished by lesser number of lines
of code compared to the target processor/controller specific assembly language
based development.
Developer Independency
The syntax used by most of the high level languages are universal and a program
written in the high level language can easily be understood by a second person
knowing the syntax of the language.
High level languages always instruct certain set of rules for writing the code and
commenting the piece of code.
If the developer strictly adheres to the rules, the firmware will be 100% developer
independent.
Portability
Target applications written in high level languages are converted to target
processor/controller understandable format (machine codes) by a cross-compiler.
An application written in high level language for a particular target processor can
easily be converted to another target processor/controller specific application,
with little or less effort by simply re-compiling/little code modification followed
by recompiling the application for the required target processor/controller,
provided, the cross-compiler has support for the processor/controller selected.
This makes applications written in high level language highly portable.
Little effort may be required in the existing code to replace the target processor
specific files with new header files, register definitions with new ones, etc.
This is the major flexibility offered by high level language based design.
AJIET | D E P T . O F CSE
INTRODUCTION TO EMBEDDED SYSTEMS | MODULE 4:
Embedded Firmware Design and Development
Certain embedded firmware development situations may demand the mixing of high level
language with Assembly and vice versa.
High level language and assembly languages are usually mixed in three ways:
Mixing Assembly Language with High Level Language
Mixing High Level Language with Assembly Language
Inline Assembly programming
D E P T . O F CSE | AJIET
INTRODUCTION TO EMBEDDED SYSTEMS | M O D U L E 4 :
Embedded Firmware Design and Development
Mixing the code written in a high level language like 'C' and Assembly language is useful
in the following scenarios:
The source code is already available in Assembly language and a routine written in
a high level language like 'C' needs to be included to the existing code.
The entire source code is planned in Assembly code for various reasons like
optimised code, optimal performance, efficient code memory utilisation and
proven expertise in handling the Assembly, etc. But some portions of the code may
be very difficult and tedious to code in Assembly. For example, 16-bit
multiplication and division in 8051 Assembly Language.
To include built in library functions written in 'C' language provided by the cross
compiler. For example, Built in Graphics library functions and String operations
supported by 'C’.
Most often the functions written in 'C' use parameter passing to the function and returns
value/s to the calling functions.
Parameters are passed to the function and values are returned from the function using
CPU registers, stack memory and fixed memory.
Its implementation is cross compiler dependent and it varies across cross compilers.
AJIET | D E P T . O F CSE
INTRODUCTION TO EMBEDDED SYSTEMS | MODULE 4:
Embedded Firmware Design and Development
on the host PC used for development activities. These tools can be either freeware or licensed copy
or evaluation versions. Licensed versions of the tools are fully featured and fully functional whereas
trial versions fall into two categories, tools with limited features, and full featured copies with
limited period of usage.
The conversion of the code is done by software running on a processor/controller (e.g. x86
processor based PC) which is different from the target processor. The software performing
this operation is referred as the ‘Cross-compiler’. In a single word cross-compilation is the
process of cross platform software/firmware development.
The various fi les generated during the crosscompilation/cross-assembling process are: List
File (.lst), Hex File (.hex), Pre-processor Output file, Map File (File extension linker
dependent), Object File (.obj)
meaning their location in the code memory is not fixed. It is the responsibility of a linker
to link all these object files. The locater is responsible for locating absolute address to
each module in the code memory. Linking and locating of re-locatable object files will
also generate a list file called ‘linker list file’ or ‘map file’.
V. HEX File (.HEX)
Hex file is the binary executable file created from the source code. The absolute object
file created by the linker/locater is converted into processor understandable binary code.
The utility used for converting an object file to a hex file is known as Object to Hex file
converter. Hex files embed the machine code in a particular format.
DISASSEMBLER/DECOMPILER
Disassembler is a utility program which converts machine codes into target processor
specific Assembly codes/instructions.
The process of converting machine codes into Assembly code is known as ‘Disassembling’.
In operation, disassembling is complementary to assembling/crossassembling.
Decompiler is the utility program for translating machine codes into corresponding high level
language instructions.
Decompiler performs the reverse operation of compiler/cross-compiler. The disassemblers/
decompilers for different family of processors/controllers are different.
Disassemblers/decompilers help the reverse-engineering process by translating the embedded
firmware into Assembly/high level language instructions.
Disassemblers/ Decompilers are powerful tools for analysing the presence of malicious codes
(virus information) in an executable image.
However disassemblers/decompilers generate a source code which is somewhat matching to
the original source code from which the binary code is generated.
i. Simulators
Simulators simulate the target hardware and the firmware execution can be
inspected using simulators. The features of simulator based debugging are listed
below. Purely software based 2. Doesn’t require a real target system 3. Very
primitive (Lack of featured I/O support. Everything is a simulated one) 4. Lack
of Real-time behavior.
Advantages of Simulator Based Debugging
Simulator based debugging techniques are simple and straightforward.
No Need for Original Target Board Simulator based debugging technique is
purely software oriented.
Simulate I/O Peripherals, s. Using simulator’s I/O support you can edit the
values for I/O registers and can be used as the input/output value in the firmware
execution.
Simulates Abnormal Conditions: With simulator’s simulation support you can
input any desired value for any parameter during debugging the firmware and
can observe the control flow of firmware.
Limitations of Simulator based Debugging
Deviation from Real Behaviour: Simulation-based firmware debugging is
always carried out in a development environment where the developer may not
be able to debug the firmware under all possible combinations of input.
Under certain operating conditions we may get some particular result and it need
not be the same when the firmware runs in a production environment.
Lack of Real Timeliness : The major limitation of simulator based debugging is
that it is not real-time in behaviour.
Hardware debugging deals with the monitoring of various bus signals and
checking the status lines of the target hardware.
AJIET | D E P T . O F CSE
INTRODUCTION TO EMBEDDED SYSTEMS | MODULE 4:
Embedded Firmware Design and Development
D E P T . O F CSE | AJIET
INTRODUCTION TO EMBEDDED SYSTEMS | M O D U L E 4 :
Embedded Firmware Design and Development
The emulator application for emulating the operation of a PDA phone for application
development is an example of a ‘Software Emulator’. A hardware emulator is controlled
by a debugger application running on the development PC. The debugger application
may be part of the Integrated Development Environment (IDE) or a third party supplied
tool.
emulator POD using ribbon cables. The adaptor type varies depending on the target
processor’s chip package. DIP, PLCC, etc. are some commonly used adaptors.
QUESTIONS:
1.What is Firmware? Mention the Embedded Firmware Design Approaches.
2. Explain the Embedded Firmware Development Languages.
3. With a neat diagram explain Source File to Object File Translation(Assemly/HLL)
4. Compare Linker and Locator.
5. Explain the Mixing High Level Language with Assembly Language.
6.Mention the steps involved in Keil C51 cross compiler for 8051 controller
7.Explain briefly the Embedded System Development Environment with a neat diagram.
8. Explain the The Keil μVision IDE for 8051 debugging technique.
9. Mention the various files generated during the cross compilation . explain briefly.
D E P T . O F CSE | AJIET
INTRODUCTION TO EMBEDDED SYSTEMS | M O D U L E 4 :
Embedded Firmware Design and Development
10 compare
A) Decompiler and disassembler
B) Emulator and Simulator
11. Mention the Advantages and limitations of Simulator Based Debugging
12. Illustrate with a diagram Monitor Program Based Firmware Debugging technique.
13. With a neat figure explain the In Circuit Emulator ( ICE) Based Firmware Debugging technique.
14, Explain On Chip Firmware Debugging (OCD) technique.
15.Mention the signal lines of JTAG protocol.
AJIET | D E P T . O F CSE