Bootloader
Bootloader
David Pehrsson
Jesús Garza
Date: 2012-12-18
Acknowledgements
We would like to thank everyone at QRTECH for the help they have given us and
we would especially like to thank Andreas Käck for the technical support he
provided when we needed it. We will also like to thank Lars Carlsson on
QRTECH for all the help regarding the master thesis. We would also like to thank
the teachers at JTH, Alf Johansson and Shashi Kumar for their support.
i
Abstract
Abstract
In an automotive context today’s need of testing functions while in factory,
correcting faults in the workshop or adding extra value in the aftermarket makes it
very important to easily be able to download new software to the electronic
control units in vehicles. In the platform for standard automotive software
development called AUTOSAR, two known protocols are presented to specify the
procedure on how to implement this download operation: Unified Diagnostic
Services (UDS) and the Universal Measurement and Calibration Protocol (XCP).
However the part of the UDS and XCP standards that is about reprogramming is
not completely a part of the AUTOSAR standard yet. In this thesis, UDS and
XCP have been compared to evaluate which of the two that has most support in
AUTOSAR today and are most likely to be fully integrated into AUTOSAR in the
future. Since UDS already has support in AUTOSAR for some of the functions
needed for reprogramming and because of the fact that UDS is a part of the
extensively used On-board Diagnostic standard (OBD-II), UDS is chosen to be
the most suitable protocol for implementing reprogramming functionality
according to AUTOSAR.
A bootloader with the ability to download data has been developed using only
relevant functions from UDS and following the AUTOSAR specifications where
it is applicable.
ii
Sammanfattning
Sammanfattning
För att kunna testa fordonsfunktioner i fabriken, åtgärda mjukvarufel under
service eller för att uppgradera fordonet med nya funktioner är det viktigt att
kunna ladda ner ny mjukvara till fordonets styrsystem. Den standardiserade
mjukvaruplattformen för fordonsindustrin, AUTOSAR, innehåller två protokoll
som båda specificerar hur mjukvara kan laddas ner: Unified Diagnostic Services
(UDS) och Universal Measurement and Calibration Protocol (XCP).
Tyvärr är de delarna av UDS och XCP som beskriver mjukvarunerladdning inte
en del av AUTOSAR än. I det här examensarbetet har UDS och XCP jämförts för
att utvärdera vilken av de båda som i dagsläget har störst stöd för nerladdning av
mjukvara i AUTOSAR och vilken som troligast kommer att bli en del av
AUTOSAR i framtiden. Eftersom AUTOSAR redan stödjer några av de
funktioner i UDS som behövs för nerladdning av mjukvara samt på grund av att
UDS är en del av branschstandarden för fordonsdiagnostik OBD-II, har UDS
valts som den mest lämpade att i dagsläget användas för att implementera
nerladdning av mjukvara enligt AUTOSAR.
En bootloader som stödjer nerladdning av mjukvara via UDS har sedan
implementerats enligt AUTOSAR-specifikationen så långt som möjligt.
iii
Keywords
Keywords
AUTOSAR
UDS
XCP
Bootloader
Reprogramming
ECU
Software Downloads
CAN
iv
Table of Contents
Table of Contents
1 Introduction ............................................................................. 1
1.1 BACKGROUND ............................................................................................................................. 1
1.2 PURPOSE AND RESEARCH QUESTIONS .......................................................................................... 1
1.3 DELIMITATIONS .......................................................................................................................... 2
1.4 OUTLINE ..................................................................................................................................... 2
2 Theoretical background .......................................................... 3
2.1 BOOTLOADER.............................................................................................................................. 3
2.2 CONTROLLER AREA NETWORK ................................................................................................... 5
2.2.1 Concept of CAN ................................................................................................................ 5
2.3 AUTOSAR ................................................................................................................................. 6
2.4 UNIFIED DIAGNOSTIC SERVICES (UDS) ...................................................................................... 9
2.4.1 Relationship between UDS and AUTOSAR .................................................................... 14
2.4.2 An UDS use case: Flash Reprogramming ...................................................................... 19
2.5 UNIVERSAL MEASUREMENT AND CALIBRATION PROTOCOL (XCP) .......................................... 20
2.5.1 Packets ............................................................................................................................ 21
2.5.2 Security ........................................................................................................................... 22
2.5.3 Flash programming ........................................................................................................ 22
2.5.4 Flash memory access ...................................................................................................... 23
2.5.5 Relationship between XCP and AUTOSAR .................................................................... 25
2.6 ODEEP QR5567 DEVELOPMENT PLATFORM ............................................................................ 28
2.6.1 MPC5567 ........................................................................................................................ 29
v
Table of Contents
6 References .............................................................................. 79
vi
List of Figures
List of Figures
FIGURE 1 - EXAMPLE OF BOOTSTRAP OVERVIEW 4
FIGURE 2 - CAN FRAME LAYOUT [5] 6
FIGURE 3 - OVERVIEW OF AUTOSAR 7
FIGURE 4 - MAIN SOFTWARE LAYERS IN THE AUTOSAR ARCHITECTURE [8] 8
FIGURE 5 - LAYER DIVISION OF THE BSW LAYER [8] 9
FIGURE 6 - THE MODULES THAT RESIDES IN THE LAYERS [8] 9
FIGURE 7 - UDS NETWORK 11
FIGURE 8 - THE CLIENT AS AN OFF-BOARD TESTER. 11
FIGURE 9 - UDS ALSO DEFINES A SECURITY LAYER IN ORDER TO ENCRYPT DATA. 13
FIGURE 10 - POSITION OF THE DCM MODULE IN THE AUTOSAR ARCHITECTURE 16
FIGURE 11 - INTERACTION BETWEEN DCM AND OTHER MODULES 18
FIGURE 12 - XCP FRAME 21
FIGURE 13 - COMMUNICATION OBJECTS BETWEEN MASTER AND SLAVE 22
FIGURE 14 - ABSOLUTE ACCESS MODE IN XCP 24
FIGURE 15 - FUNCTIONAL ACCESS MODE IN XCP 25
FIGURE 16 - XCP IN AUTOSAR 26
FIGURE 17 - ODEEP QR5567 DEVELOPMENT PLATFORM 28
FIGURE 18 - DIAGNOSTIC SESSION TRANSITIONS 37
FIGURE 19: VIEW OF PEEDI DEVICE 58
FIGURE 20: LAYOUT OF CONNECTIONS FOR COMMUNICATING WITH PEEDI AND
TARGET 58
FIGURE 21: MAIN WINDOW IN CANALYZER VER.7.5.66 60
FIGURE 22: CANCASEXL DEVICE AND INTERFACE CABLE 61
FIGURE 23: NETWORK HARDWARE CONFIGURATION WINDOW 61
FIGURE 24: MEASUREMENT SETUP CONFIGURATION WINDOW 62
FIGURE 25: CAPL BROWSER 62
FIGURE 26 - COMMUNICATION BETWEEN CANTP, PDU ROUTER AND DCM MODULES. 68
FIGURE 27 - PROGRAM FLOW WHEN THE ECU IS IN THE DEFAULT SESSION 69
FIGURE 28 - PROGRAM FLOW WHEN THE ECU IS IN THE EXTENDED SESSION. 70
FIGURE 29 - PROGRAM FLOW WHEN THE ECU IS IN THE PROGRAMMING SESSION, PART
1 71
FIGURE 30 - PROGRAM FLOW WHEN THE ECU IS IN THE PROGRAMMING SESSION, PART
2 72
FIGURE 31 - PROGRAM FLOW WHEN THE ECU IS IN THE PROGRAMMING SESSION, PART
3 73
FIGURE 32 - SCOPE OF THE MCU DRIVER SPECIFICATION [36] 76
vii
List of Tables
List of Tables
TABLE 1: DIAGNOSTIC SPECIFICATIONS APPLICABLE TO THE OSI LAYERS 10
TABLE 2 - SERVICES PROVIDED BY DIFFERENT FUNCTIONAL UNITS DEFINED IN THE
UDS STANDARD APPLIED TO THEIR RESPECTIVE USE CASES. 14
TABLE 3 - OSI MODEL 15
TABLE 4 - BOOT MODES 30
TABLE 5 - RCWD LOCATIONS 31
TABLE 6 - FRAME LAYOUT 35
TABLE 7 - DIAGNOSTIC SESSION CONTROL REQUEST MESSAGE LAYOUT 38
TABLE 8 - DIAGNOSTIC SESSION CONTROL RESPONSE MESSAGE LAYOUT 39
TABLE 9 - CONTROL DTC SETTINGS REQUEST MESSAGE LAYOUT 40
TABLE 10 - CONTROL DTC SETTINGS RESPONSE MESSAGE LAYOUT 41
TABLE 11 - COMMUNICATION CONTROL REQUEST MESSAGE LAYOUT 42
TABLE 12 - COMMUNICATION CONTROL RESPONSE MESSAGE LAYOUT 43
TABLE 13 - SECURITY ACCESS REQUEST MESSAGE LAYOUT 44
TABLE 14 - SECURITY ACCESS RESPONSE MESSAGE LAYOUT 46
TABLE 15 - REQUEST DOWNLOAD REQUEST MESSAGE LAYOUT 47
TABLE 16 - REQUEST DOWNLOAD RESPONSE MESSAGE LAYOUT 48
TABLE 17 - TRANSFER DATA REQUEST MESSAGE LAYOUT 49
TABLE 18 - TRANSFER DATA RESPONSE MESSAGE LAYOUT 50
TABLE 19 - REQUEST TRANSFER EXIT REQUEST MESSAGE LAYOUT 52
TABLE 20 - REQUEST TRANSFER EXIT RESPONSE MESSAGE LAYOUT 52
TABLE 21 - ROUTINE CONTROL REQUEST MESSAGE LAYOUT 53
TABLE 22 - ECU RESET REQUEST MESSAGE LAYOUT 54
TABLE 23 - ECU RESET RESPONSE MESSAGE LAYOUT 55
TABLE 24 - COMPARISON OF FUNCTIONS BETWEEN UDS AND XCP 64
viii
List of Abbreviations
List of Abbreviations
AUTOSAR Automotive Open System Architecture
BAM Boot Assist Module
CAN Controller Area Network
ExtRAM External Random Access Memory
MCU Microcontroller Unit
MMU Memory Management Unit
PBL Primary Bootloader
PCI Protocol Control Information
SID Service Identifier
PDU Protocol Data Unit
CANTp CAN Transport Protocol
RCHW Reset Configuration Half Word
ROM Read-Only Memory
SBL Secondary Bootloader
SPE Signal Processing Extension
SRAM Internal Static Random Access Memory
UDS Unified Diagnostic Services
XCP Universal Measurement and Calibration Protocol
DCM Diagnostic Communication Manager
PPC PowerPC
EABI Embedded Application Binary Interface
Tx Process of data transmission
Rx Process of data reception
ix
Introduction
1 Introduction
1.1 Background
Within the automotive industry there is a recurrent need of loading new
application software to the embedded units responsible of vehicle functions,
whether it is under development, during maintenance or as a post-sales upgrade.
For this to be possible it is required that these embedded units (also known as
“ECU”) support reprogramming through a standard communication interface
such as CAN, FlexRay, LIN, Ethernet, etc.
In recent years, several car manufacturers, suppliers and tool developers have
adopted a standard for the management of vehicle functions within both future
applications and standard software modules; such standard is named AUTOSAR
(Automotive Open System Architecture). One case of software module
management is precisely the area of ECU reprogramming. The AUTOSAR
standard, however, does not exactly specify how to download a new application
program to a target processor within a vehicle’s Electronic Control Unit (ECU).
AUTOSAR supports two standards for diagnostic and calibration of vehicle
parameters (UDS and XCP, respectively) which can also provide resources for
reprogramming an ECU’s processor. An analysis of compatibility between each of
those standards and AUTOSAR will be done for selecting the best of both. Such
selection will lead to the development of a bootloader that will support system
start-up and software functionality for reprogramming the QR5567 platform via
the standard communication interface CAN. This development shall meet the
requirements imposed by AUTOSAR where it is applicable.
The functionality of the bootloaders will provide a solution that can be applied to
load and start software onto the platform QR5567, which can then be used for
further prototyping. This development will intend to satisfy the need expressed
above since its operation can emulate the process of reprogramming a car’s ECU
while still during development in the factory, or while correcting a failure in a
service workshop or even when some extra functionality is provided in the
aftermarket.
1
Introduction
1.3 Delimitations
In the analysis of communication protocols UDS and XCP only functions
regarding reprogramming will be covered, other part of UDS and XCP will not be
taken into consideration when comparing them. Only relevant parts regarding
reprogramming of AUTOSAR will be implemented. This report will only focus
on CAN as the communication interface, even though other communication
interfaces are supported in hardware, and XCP, UDS and AUTOSAR.
1.4 Outline
The first part of the report, theoretical background, covers the bootloader concept
and the concepts and the standards CAN, AUTOSAR, UDS and XCP. The next
part, Method and implementation, describes the features of UDS from an
AUTOSAR perspective and how UDS and AUTOSAR are used in the
implementation. In the third part, Findings and Analysis, the outcome of the
functions of the software that has been implemented is presented. The last part,
Discussion and Conclusions, includes a comment on the coverage of bootloaders
provided by AUTOSAR, summarizes the work and proposes how it can be
further developed.
2
Theoretical background
2 Theoretical background
2.1 Bootloader
Among the multiple conceptions that exist regarding the definition of a
bootloader one common approach is that it is considered to be a fixed piece of
software or firmware residing at least partially in the non-volatile memory area of
a microprocessor, such as ROM or Flash. The “firm” condition of the bootloader
is based on the idea that once designed and developed it’s not supposed to be
object of many changes or maintenance during the processor lifetime as an
application program would eventually undergo.
The different views that exist towards the features and operation that a bootloader
should perform are often motivated, for instance, by the following factors:
Usually embedded processors fetch and execute code from the reset vector at a
defined address in ROM or Flash, to further jump to another section of memory
where the initialization code resides. This is done to keep the reset vector small.
Minimal hardware initialization. Especially since it’s the first code the CPU
executes upon power up. It might include:
o Enabling access to / initializing internal RAM
o Default initialization of MCU system clock for provision of
timebase and prescalers.
o Setting up Phase Lock Loops (PLL’s)
o Initialization of base addresses for Interrupt and Exception Trap
Vector
3
Theoretical background
In the book Real-Time Concepts for Embedded Systems [1] for example, a typical flow is
shown for a bootloader that is very similar to the one previously described. Such
flow can be appreciated in Figure 1.
Because of its key role, the bootloader usually occupies special boot blocks in the
flash ROM, which have hardware protection against accidental erasure and
corruption.
4
Theoretical background
In this regard, the authors of Best Practices in Boot Loader Design [2] consider a “good
trait” to have the ability to perform network boot to quickly download a firmware
image to the target device over a network using standard Internet protocols.
The CAN protocol covers two layers in the ISO/OSI Reference Model, Physical
Layer and Data Link Layer, all Layers above is implementation specific. The Data
Link Layer consists of two sublayers, Logic Link Control sublayer, which for
example decides which messages that are received are accepted, and Medium
Access Control sublayer, which is controlling Framing, Arbitration, Error
Checking, Error Signaling and Fault Confinement. The Physical layer handles the
actual transfer of bits between the nodes with respect to all electrical properties.
[5]
A CAN network consists of nodes which are identified by an id number in the
arbitration field. The arbitration field is used for prioritization of messages when
multiple nodes want to send messages at the same time. The message with most
dominant bits in the arbitration field has highest priority and will be transmitted
without interrupt. CAN is specified to transmit data with a bit rate up to 1 Mbit/s
in a network with a length below 40 m. The speed has to be decreased when long
distance networks are used. [5]
5
Theoretical background
2.3 AUTOSAR
AUTOSAR (AUTomotive Open System ARchitecture) is a partnership between
different OEM manufacturers and Tier 1 suppliers in the automotive industry that
are working together to develop and establish an open industry standard for the
automotive electrical and electronic architecture. The cooperation for an open
system architecture begun in august 2002 when BMW, Bosch, Continental,
DaimlerChrysler and Volkswagen started to discuss common challenges and
objectives in the automotive industry. In November the same year a joint technical
team was put together to establish strategies for the technical implementation and
in May 2003 the partnership between the core partners was formally signed and
AUTOSAR was born. In May 2010 the AUTOSAR cooperation consisted of 9
core members, 39 premium members, 11 development members, 57 associated
members and 5 attendees. [6]
6
Theoretical background
The basic goals of AUTOSAR are to be able to reuse software components so the
rise in complexity of future automotive systems can be handled easily as well as
aiming for optimization to be done at system level instead of component level.
The benefit of having a standardized interfaces are the high degree of reuse of
software and the ability to change to a different solutions from different suppliers
but still have the same functionality. This reflects in the working principle of
AUTOSAR, “Cooperate on standards, compete on implementation”. Goals that
are set up by the AUTOSAR development cooperation are [7]:
Implementation and standardization of basic functions as OEM "Standard
Core" solution
Scalability to different vehicle and platform variants
Transferability of functions throughout network
Integration of functional modules from multiple suppliers
Consideration of availability and safety requirements
Redundancy activation
Maintainability throughout the whole "Product Life Cycle"
Increased use of "Commercial off the shelf hardware"
Software updates and upgrades over vehicle lifetime
7
Theoretical background
Software architecture
The software architecture includes specifications for communications stacks,
system services, diagnostic services, memory stacks, peripherals, implementation
integration and real-time environments. This is all called AUTOSAR Basic
Software.
Methodology
The methodology part of AUTOSAR aims to make the configuration process
between the basic software stack and the application software in the ECUs as
seamless as possible by defining exchange formats and description templates.
Application interfaces
The application interfaces topic includes specifications of typical automotive
application interfaces in terms of syntax and semantics. This should serve as a
standard for application software developed for AUTOSAR.
The architecture of AUTOSAR is built into three main software layers: the
Application Layer, the Runtime Environment (RTE) Layer and the Basic Software
(BSW) Layer which run in a microcontroller. [8]
8
Theoretical background
9
Theoretical background
In Table 1 it is possible to see the mapping between the OSI layers and the
corresponding standards that specify services for each layer in an example
implementation of diagnostics.
10
Theoretical background
In the context of diagnostics, the following concepts are useful for a better
understanding of the semantics handled on the UDS standard environment:
11
Theoretical background
Diagnostic Session: Current mode of the server, which affects the level
of diagnostic functionality.
12
Theoretical background
Besides specifying services’ primitives and protocols that describe the client-server
interaction, UDS also defines within its framework a number of functional units
that comprise several services each, identified with a hexadecimal code. These
units are intended for different individual purposes that support the overall
diagnostic function/task. Such units are:
The following table shows specific examples of use cases for diagnostics, some of
the services that could be employed for such purposes and the corresponding
functional units that implement them:
13
Theoretical background
Table 2 - Services provided by different functional units defined in the UDS standard applied
to their respective use cases.
The DCM module ensures diagnostic data flow and manages the diagnostic states,
especially diagnostic sessions and security states. Furthermore, the DCM module
checks if the diagnostic service request is supported and if the service may be
executed in the current session according to the diagnostic states.
There’s a close relationship between the services established in the UDS standard
and the DCM. The DCM module provides the OSI layers 5 to 7 of an
implementation of diagnostics. At OSI-level 7, the DCM provides an extensive set
of ISO 14229-1 services (21 of 25 possible). At OSI-level 5, the DCM module
handles the network-independent sections of the following specifications:
14
Theoretical background
6: Presentation ---
This arrangement matches the mapping of layers established by the UDS standard
in the ISO 14229-1 specification, which was also shown before. In addition, to
remark the support of AUTOSAR to UDS, it will be pointed later where are the
UDS services included within the overall functionalities provided by the DCM
module. [10]
15
Theoretical background
The DCM module has the capability of being network-independent. All network-
specific functionality (the specifics of networks like CAN, LIN, FlexRay or
MOST) is handled outside of the DCM module. The Protocol Data Unit Router
(PduR) module provides a network-independent interface to the DCM module.
The DCM module receives a diagnostic message from the PduR module. The
DCM module processes and checks internally the diagnostic message. As part of
processing the requested diagnostic service, the DCM will interact with other
BSW modules or with SW-components (through the RTE) to obtain requested
data or to execute requested commands. This processing is very service specific.
Typically, the DCM will assemble the gathered information and send a message
back through the PduR module. [10]
16
Theoretical background
Protocol Data Unit Router (PduR module): The PduR module provides
functions to transmit and receive diagnostic data. Specifically, it provides
DCM with data of incoming diagnostic requests. [12] Proper operation of
the DCM module presumes that the PduR interface supports all service
primitives defined for the Service Access Point (SAP) between diagnostic
application layer and underlying transport layer. [9]
SW-C and RTE: The DCM module has the capability to analyze the
received diagnostic request data stream and handles all functionalities
related to diagnostic communication such as protocol handling and timing.
Based on the analysis of the request data stream the DCM module
assembles the response data stream and delegates routines or IO-Control
executions to SW-Cs .If any of the data elements or functional states
cannot be provided by the DCM module itself the DCM requests data or
functional states from SW-Cs via port-interfaces or from other BSW
modules through direct function-calls. [14]
BswM: The BswM allows the DCM to request a mode change, e.g. in case
of reset or session change
In Figure 11, the dependencies between the DCM module and other AUTOSAR
modules are visible.
17
Theoretical background
a) The syntax and semantics of the functions that are provided and required
form other Basic Software (BSW) modules. These take the form of API’s
reminiscent to C language.
b) The syntax and semantics of a subset of those functions which are used by
software components through the Run Time Environment (RTE).
18
Theoretical background
The purpose of this section is to show the process and items that could be used in
terms of data transfer between a client and a server, as suggested by UDS.
Despite the fact that AUTOSAR does not explicitly specify, and thus still does not
fully support the process of flash reprogrammming as stated in
AUTOSAR Specification of Flash Driver [15], the newest AUTOSAR version 4.0 has
just included in the DCM the support of some crucial UDS services that can be
applied for taking care of most of the reprogramming-related actions written
above:
ReadMemoryByAddress
WriteMemoryByAddress
RequestDownload
RequestUpload
TransferData
RequestTransferExit
CommunicationControl
ResponseOnEvent
It can be seen then that the AUTOSAR specification relies strongly on UDS to
perform flash reprogramming.
19
Theoretical background
XCP is constructed in two layers, a transport layer and a protocol layer and is a
Single-Master Multi-Slave system. The protocol layer is interface independent and
describes the architecture, syntax and settings of the protocol. The protocol layer
is the same whatever communication interface that is used. The transport layer
specifies how XCP should transport data over the network and changes
depending on what communication interface is used.
In May 2010 the ASAM XCP standard supported XCP on CAN, SPI, SCI,
TCP/IP, UDP/IP, USB and FlexRay.
The XCP Single-Master is the measurement and calibration system, often a PC,
and the ECUs operates as Slaves. The master establishes a communication
channel, a point-to-point connection, with the slave. The connection must be
point-to-point between master and slave and broadcasting XCP messages is not
allowed, except XCP message GET_SLAVE_ID, which can be broadcasted.
Multiple masters are not allowed but a master can have multiple communication
channels active in the same network at the same time.
Every slave in the system have a ECU description file, A2L-file, which specifies
what checksum method that is used, the physical meaning of the data, the link
between variable names and their address range and so on. The XCP master can
access these descriptions files and read out all the necessary information it might
need.
20
Theoretical background
The communication between master and slave is done through the XCP driver
that is integrated in the master. In XCP Standard communication mode each
request packet send form the master, the slave will respond with a response packet
or an error packet. The master will not send a new packet until it receives a
response or error packet from the slave regarding previous sent request.
To speed up the process of uploading and downloading to memory and
programming the flash, Block Transfer Communication Mode can be applied.
This communication mode is similar to the one that is used in UDS. In this mode
multiple requests are sent at the same time as a block of data and the slave
responds by sending a block of responses back to the master.
A XCP message consists of three parts, Header, Packet and Tail, see Figure 12.
The Header and the Tail is part of the Transport layer and consist of a Control
Field which content depends on what bus is used. The Packet part of a XCP
message consists of an Identification Field, Timestamp Field (optional) and a Data
Field and is a generic part of the protocol layer.
2.5.1 Packets
Two different types of packets are used in the communication via XCP,
Command Transfer Object (CTO) and Data Transfer Object (DTO).
The CTO have five types of objects:
CMD (Command)
RES (Response)
ERR (Error)
EV (Event)
SERV (Service Request Processor)
21
Theoretical background
The DTO have two types of objects that are both used for event driven reading of
variables from, or writing values to, the memory of the slave.
2.5.2 Security
In XCP the object called SECTORS describes the physical layout of the ECU
memory. The start addresses and sizes of the SECTOR are of high important
when reprogramming the ECU.
Programming of flash memory in a slave device can be divided into three parts.
22
Theoretical background
The XCP standard does not support special commands for version control
because the administration steps are very project specific and depends on the
ECU, but the ECU functional description can specify which standard XCP
commands can be used for administration actions like version control.
The XCP standard offers seven commands to be used special for programming:
PROGRAM_START
PROGRAM_CLEAR
PROGRAM_FORMAT
PROGRAM
PROGRAM_VERIFY
PROGRAM_RESET
How these commands are used in a project must be specified in a project specific
“programming flow control” document. [16]
There are two different flash access methods supported by the XCP protocol to
be used in the flash process. Absolute access mode and Functional access mode
which both uses the same commands but with some different parameters.
23
Theoretical background
24
Theoretical background
After when the flash process is finished a checksum control to verify the data can
be performed with the BUILD_CHECKSUM and PROGRAM_VERIFY
commands. The end of a programming session is indicated by sending a
PROGRAM_RESET command and the slave will then go into a disconnect state
and often a hardware reset of the slave is executed after that. [18]
25
Theoretical background
OS
The time stamped feature of XCP uses the AUTOSAR OS counter.
Diagnostic Event Manager
The DEM module provides function to retrieve all information related to fault
memory such that the DCM module is able to respond to tester requests by
reading data from the fault memory. [11]
Development Error Tracer
XCP has to have access to the error hook of the Development Error Tracer to be
able to report development errors.
26
Theoretical background
AUTOSAR supports XCP on CAN, FlexRay and Ethernet and the following
features of XCP version 1.1:
A2L IF_DATA Section Support
Synchronous data acquisition
Synchronous data stimulation
Block communication mode
Interleaved communication mode
Dynamic data transfer configuration
Timestamped Data transfer
Bypassing
Seed & Key
Online Calibration Data Page Switching
DAQ configuration storing with power-up data transfer (RESUME mode)
The XCP feature of flash programming of the ECU is currently not a part of the
AUTOSAR specification. The use of XCP or CCP is an alternative to
reprogramming with the Flash Bootloader. This variant is primarily used to
optimize ECU parameters. Since XCP/CCP programming is generally used in the
development phase, unlike the Flash Bootloader, security aspects play a
subordinate role here. [20]
27
Theoretical background
28
Theoretical background
2.6.1 MPC5567
The MCU has internal SRAM and FLASH and externally available RAM.
29
Method and implementation
The e200z6 core within the MPC5567 microcontroller makes use of the Boot
Assist Module (BAM) and the status of the BOOTCFG pins to start the execution
of code after reset. The BAM contains the MCU’s most basic boot program code.
Boot Assist Module startup procedure
The Boot Assist Module (BAM) configures the Memory Management Unit
(MMU) of the processor to allow access to all internal resources of the MCU and
access to the external memory space as well. In the next step the BAM reads the
status of the BOOTCFG pins in the reset status register (SIU_RST) and the
defined boot sequence is started. Internal boot mode configuration is to be used
in this project. [22]
BOOTCFG Censorship Serial Boot Mode Internal JTAG Serial
[0:1] Control Boot Name Flash State State Password
Control
11 - - Not Available - - -
30
Method and implementation
Internal boot mode sequence starts with the BAM setting up a bus error exception
handler in case of bus error due to accessing flash memory locations that may be
corrupted. Next the BAM tries to find a valid Reset Configuration Half Word
(RCHW) that is placed in six predefined locations in the internal flash memory.
A valid RCHW is a 16-bit value, 8-bit is boot identifier 3-bits are configuration
bits and 5-bits are reserved and not used by RCHW. The first half word in one of
the low address spaces flash blocks is expected to be the RCHW, see Table 5. If a
valid RCHW is found the BAM enables the watchdog timer in the processor with
the RCHW[WTE] bit. The timeout of the watchdog is 2.5x217 system clock
periods.
Block Address
0 0x0000_0000
1 0x0000_4000
2 0x0001_0000
3 0x0001_C000
4 0x0002_0000
5 0x0003_0000
The BAM also fetches the reset vector from the address of the
BOOT_BLOCK_ADDRESS + 0x4 and branches to the reset boot vector. At the
reset boot vector address, valid user application instructions should be placed. If a
valid RCHW is not found, the BAM will proceed to serial boot mode.
For this implementation a memory region was specifically defined for the RCHW
in the linker script file. It was called “flash_rchw” and it starts at address
0x0000000 having a size of 8 bytes. A corresponding memory section identified as
“.rchw” was assigned to this region. In the present work, since it was designed to
boot from internal flash the boot ID of the RCHW must be read as 0x5A. This
was achieved by setting the 4 bytes of that section to the boot ID value. The 4
bytes left are set to the address of the reset vector to which the BAM jumps i.e.
the start address of the initialization part of the Primary Bootloader. [22]
31
Method and implementation
32
Method and implementation
constants. GPR R2 is dedicated for use as a base pointer (anchor) for the
read-only small data area (Containment of variables -> initialized: .sdata2,
non-initialized: .sbss2). GPR R13 is dedicated for use as an anchor for
addressing the read-write small data area. [23]
The bootloader initializes then these small data area anchor registers to the
value of the addresses to which all data in the .sdata and .sbss sections can
be addressed using a 16-bit signed offset. These values are available as
macros automatically during linking.
Initialization of interrupt vector and definition of branch table: To provide
the MCU a mechanism for exception handling in form of traps, configure
the interrupt vector offset registers (IVOR) for all the accepted interrupt
sources, define Interrupt Service Routines (ISR) mapped to IVORs as well
as enabling in the processor the recognition of interrupt events.
Initialization and configuration of Frequency Modulated Phase Locked
Loop (FMPLL): To be able to generate high system clocks from a crystal
oscillator (16 MHz in this project). The configuration of the controlling
parameters was set in order to get a system frequency up to 128 MHz, a
proper value for flash reprogramming (between 25 MHz and a maximum
operating frequency of 132 MHz with the crystal used).
Initialization of Enhanced Modular Input/Output Subsystem: While
completely optional, this module is initialized to provide an easy method
for starting, reading and stopping time counts derived from structures
known as channels.
Initialization of External Bus Interface: To prepare the interface that
controls data transfer and signals to the external SRAM module.
Initialization of External SRAM: To prepare this memory space to store
data.
Copy from flash to RAM of initialized variables found at end of .text
memory section: To have the data from .data and .sdata sections
(corresponding to global and static variables) stored in its runtime address
in RAM, since it’s both readable and writable.
Initialization of uninitialized data (clearing of .bss and .sbss sections): To
ensure that these data doesn’t contain corrupted values that would
compromise the correct execution of code and therefore get unexpected
results.
Jump to “preparation for reprogramming” code: To start the process that
sets the MCU into a preparation state to begin a reprogramming session.
33
Method and implementation
Just as there is a part of code intended for the functions in a primary bootloader
as recently explained, there’s code that on its turn would deal with an eventual
reception of a new application and therefore manage the erase and write
operations performed on flash memory to store that application.
In concrete, for the present work the piece of software that handles the
downloading of the target application and reprogramming of the flash memory is
called the Secondary Bootloader (SBL). The secondary bootloader has to be
downloaded to the target before any application data can be downloaded. It
contains all necessary UDS functions and all flash routines that are needed to
store the downloaded data onto the flash memory.
The primary bootloader will start and give all control over the processor to the
secondary bootloader after it has been downloaded into the RAM memory. At
first, the secondary bootloader initializes the Flash Bus Interface Unit (FBIU) on
the target to enable read/write capabilities for the upcoming reprogramming
operations. Right after that, it reinitializes the communication via CAN to be
ready to receive UDS requests. When the flash reprogramming of the target is
complete and it resets then the secondary bootloader will be automatically
removed from RAM memory and the primary bootloader will again be in control
after the reset cycle is complete.
To create the primary and the secondary bootloader two executable files are
required as the output from the same project build. In order for the secondary
bootloader to function properly it needs to be a part of the same memory layout
as the primary bootloader, in the sense that it must “know” the start address of
the reserved section to which the secondary bootloader shall be mapped. To
achieve this, both bootloaders are programmed under the same project and the
makefile used is programmed to instruct the compiler to compile the source code
files for both the primary and secondary bootloaders on the same run and to be
linked with the same linker script file. However, the set of object files for the
primary bootloader is built separately into an executable file from that for the
secondary bootloader. For convenience, the file that corresponds to the primary
bootloader created is in *.elf format and is loaded onto the processor with a
special programming tool. On its turn, the executable file that is created for the
secondary bootloader is obtained in the Motorola .s19 format. This file includes
sections defined for the primary bootloader in the range of addresses defined for
it, but only the part containing the secondary bootloader is desired so the part
corresponding to the primary bootloader file has to be cropped using a tool called
SRecord and converted to binary format. This binary format is one of the three
accepted file-formats (raw binary, intel-hex and motorola’s .s19) for downloading
boot software, application software or application data, as specified in [24]
34
Method and implementation
3.3.1 Frames
Single Frame (SF) is used when the whole message is shorter or equal to 7 bytes,
PCI byte not included. If the message is longer than 7 bytes, then the message
needs to be divided and send with multiple frames.
When sending multiple frames a First Frame (FF) is send first and then it is
followed by Consecutive Frames (CF). The FF holds information about the length
of the message (FF_DL) and the first six (6) bytes of data. The rest of the message
is sent in CF and every CF consists of one sequence number (SN) and up to seven
(7) bytes of data. The sequence number is used by the receiver to reassemble the
message in the correct order after the reception is complete. [25]
35
Method and implementation
UDS specifies that a CAN data frame shall always contain eight (8) bytes so if a
request message doesn’t fill eight bytes the remaining bytes are filled with 0x55.
Response messages are filled with 0xAA instead of 0x55.
36
Method and implementation
37
Method and implementation
Requests
Default Session (01 hex)
The default session is the normal state for the ECU to be in. Diagnostic
services are not supported in this session only Diagnostic Session Control
and ECU Reset. The ECU is always locked when it is in the default
session.
Extended Session (02 hex)
All diagnostic services can be active in the extended session, it is
implementation specific which services that are supported. Pre-
programming services like Communication Control and Control DTC
Setting are accessible here.
Programming Session (03 hex)
This session enables all services that are required to support
reprogramming of an ECU e.g. Request Download, Routine Control and
Transfer Data.
0 PCI 0x01
Byte # 0 1 2 3 4 5 6 7
38
Method and implementation
Responses
The response message has a response SID and if it’s a positive response the
parameter is an echo of the request message parameter. If it is a negative response
the parameter is one of three negative response codes.
0 PCI 0x01
Byte # 0 1 2 3 4 5 6 7
39
Method and implementation
0 PCI 0x01
Byte # 0 1 2 3 4 5 6 7
40
Method and implementation
Responses
The response message has a response SID and if it’s a positive response the
parameter is an echo of the request message DTCsettingType parameter. If it is a
negative response the parameter is one of four negative response codes.
Negative response codes:
subFunctionNotSupported (12 hex)
Function (session type) in the request message is not supported.
incorrectMessageLengthOrInvalidFormat (13 hex)
The length of the message is wrong.
conditionsNotCorrect (22 hex)
Used when the server is in a critical normal mode activity and therefore
cannot perform the requested DTC control functionality
requestOutOfRange (31 hex)
The server shall use this response code if it detects an error in the
DTCSettingControlOptionRecord.
0 PCI 0x01
Byte # 0 1 2 3 4 5 6 7
41
Method and implementation
0 PCI 0x01
42
Method and implementation
Byte # 0 1 2 3 4 5 6 7
Responses
The response message has a response SID and if it’s a positive response the
parameter is an echo of the request message control type parameter. If it is a
negative response the parameter is one of four negative response codes.
Negative response codes:
subFunctionNotSupported (12 hex)
Function (session type) in the request message is not supported.
incorrectMessageLengthOrInvalidFormat (13 hex)
The length of the message is wrong.
conditionsNotCorrect (22 hex)
Used when the server is in a critical normal mode activity and therefore
cannot disable/enable the requested communication type
requestOutOfRange (31 hex)
The server shall use this response code if it detects an error in the
communicationType parameter.
0 PCI 0x01
43
Method and implementation
Byte # 0 1 2 3 4 5 6 7
0 PCI 0x01
Byte # 0 1 2 3 4 5 6 7
44
Method and implementation
Response
The response message has a response SID and if it is a positive response the
parameter is an echo of the request message parameter. If it is a negative response
the parameter is one of eight negative response codes.
45
Method and implementation
0 PCI 0x01
Byte # 0 1 2 3 4 5 6 7
addressAndLengthFormatIdentifier
bit 7 - 4: Length (number of bytes) of the memorySize parameter.
bit 3 - 0: Lenght (number of bytes) of the memoryAddress parameter.
46
Method and implementation
memoryAddress
The parameter memoryAddress is the starting address of the server memory to
which the data is to be written.
memorySize (unCompressedMemorySize)
This parameter shall be used by the server to compare the uncompressed memory
size with the total amount of data transferred during the TransferData service.
0 PCI 0x01
2 dataFormatIdentifier 0x00-0xFF
3 addressAndLengthFormatIdentifier 0x00-0xFF
Responses
Positive response codes:
lengthFormatIdentifier
bit 7 - 4: length (number of bytes) of the maxNumberOfBlockLength
parameter.
bit 3 - 0: reserved by document, to be set to 0 hex.
maxNumberOfBlockLength
This parameter is used by the requestDownload positive response message
to inform the client how many data bytes (maxNumberOfBlockLength)
shall be included in each TransferData request message from the client.
47
Method and implementation
This length reflects the complete message length, including the service
identifier and the data parameters present in the TransferData request
message. This parameter allows the client to adapt to the receive buffer size
of the server before it starts transferring data to the server.
0 PCI 0x01
2 lengthFormatIdentifier 0x00-0xFF
3 maxNumberOfBlockLength 0x00-0xFF
48
Method and implementation
blockSequenceCounter
The blockSequenceCounter parameter value starts at 01 hex with the first
TransferData request that follows the RequestDownload (34 hex) service. Its
value is incremented by 1 for each subsequent TransferData request. At the value
of FF hex, the blockSequenceCounter rolls over and starts at 00 hex with the next
TransferData request message.
0 PCI 0x01/0x10/0x20-0x2F
2 blockSequenceCounter 0x00-0xFF
49
Method and implementation
Responses
0 PCI 0x01/0x10/0x20-0x2F
2 blockSequenceCounter 0x00-0xFF
50
Method and implementation
51
Method and implementation
0 PCI 0x01
Response
0 PCI 0x01
52
Method and implementation
routineIdentifier
This parameter identifies a server local routine.
0 PCI 0x01
2 routineIdentifier 0x00-0xFF
3 routineControlType 0x01-0x03
Responses
Positive
routineControlType
This parameter is an echo of bits 6 - 0 of the sub-function parameter from
the request message
routineIdentifier
This parameter is an echo of the routineIdentifier from the request
message
53
Method and implementation
0 PCI 0x01
2 resetType 0x01-0x05
54
Method and implementation
Requests
Reset Type
hardReset (01 hex)
Hard reset message triggers a reset that simulates start-up sequence that are
executed when the processor is power up after the power has been
disconnected.
keyOffOnReset (02 hex)
Shall be used when a condition similar to that the driver turns off and on
the ignition key. The reset shall simulate an interruption on the switched
power supply.
softReset (03 hex)
This reset restarts the application program.
enableRapidPowerShutDown (04 hex)
Enables so that the ECU transition to sleep mode after the ignition is
turned off.
disableRapidPowerShutDown (05 hex)
Disables “transition to sleep mode after ignition is turned off”.
Responses
The positive response code for ECU Reset consists of the requested reset type
and the parameter powerDownTime that indicates how long time in seconds the
ECU will remain in the power down sequence before entering sleep mode.
0 PCI 0x01
2 resetType 0x01-0x05
55
Method and implementation
Byte # 0 1 2 3 4 5 6 7
56
Method and implementation
The Integrated Development Environment (IDE) used to write and debug code
was Arctic Studio in its simple version, from the company ArcCore; a software-
developing company whose product line goes from developing tools, code
builders and verifiers, to prototype boards. Their products have a strong focus on
AUTOSAR compliance.
Arctic Studio is built on a well-known IDE; the industry standard Eclipse.
Because of this, besides the common capabilities that it offers for writing and
editing source code, it counts for example with GCC cross compilers for
supported platforms. It also features source code version management plugins
such as SVN or GIT.
The full version of Arctic Studio includes some support tools that cover in great
extent the development of software for a complete AUTOSAR based
implementation. Among these tools, the following are the most relevant:
BSW Builder: Basic Software Builder for editing and generating BSW
configurations for AUTOSAR platforms. It helps on the process of
configuration of Arctic Core components, validating the components and
generating configuration files.
RTE Builder: Real Time Environment Builder that provides
configuration of RTE, mapping of runnable tasks, validation to ensure that
RTE actually runs and generation of RTE source and header files.
Extract Builder: In this tool, the ECU Integrator feature defines the
software architecture with all the software components, ports and
connections between them, thus helping to build an AUTOSAR ECU
software model.
SWC: The Software Component Builder aids on creating, importing,
modifying and validating software components, port interfaces and data
types.
For the present work, Arctic Studio was configured to use a GCC (GNU Cross
Compiler) from the PowerPC EABI toolchain.
57
Method and implementation
3.4.2 PEEDI
PEEDI stands for Powerful Embedded Ethernet Debug Interface and it is a very
useful tool for debugging and downloading program code to the target processor
via the JTAG port. JTAG is a protocol standardized by the IEEE that allows
having full control over the CPU core. Figure [25] shows the appearance of
PEEDI, as developed and commercialized by Ronetix, an austrian company.
In this project, PEEDI was used to start and stop processor’s execution, examine
and store values in registers, to run special commands to manipulate the behavior
and to store program code in the target’s flash memory, MPC5567 in this case.
Most of the commands are entered in a Command Line Interface (CLI) that
instructs PEEDI what to do. More information about PEEDI’s complete set of
features and configuration can be found at: www.ronetix.at/PEEDI.html
Figure 20: Layout of connections for communicating with PEEDI and target
58
Method and implementation
The file server program used for this development is called TFTP32. To start
communicating with the PEEDI, the TFTP32 program must be first set up and
running with the working directory and right IP address of the host. Then a telnet
session is run with the IP address given to the PEEDI as an argument. Once the
session is running when connected, it is possible to start executing commands
directly on the processor.
Worth to mention is the fact that for operating on the target processor, PEEDI
needs to be loaded a configuration file that describes the specifics of the target:
CPU type, flash type and metrics, RAM address and size, etc. In this case, PEEDI
was previously loaded this configuration file with the specific information for
MPC5567.
For debugging from Arctic Studio via PEEDI, a preliminary configuration is also
required on the IDE and this is done by first selecting the command for hardware
debugging available from the GCC toolchain (GDB) which PEEDI recognizes,
then choosing a generic TCP/IP method to reach the JTAG device (PEEDI in
this case) and providing host computer’s IP address and port.
3.4.3 SRecord
From these, srec_cat was the tool employed for resizing the built executable *.s19
file corresponding to the code for the secondary bootloader by using the filter
option “crop” and for further converting the resized output into a *.bin binary
file.
Srec_cat runs directly on DOS, it’s easy to use and it proved to be a very handy
and illustrating tool for manipulating loadable files. More detailed information can
be found at: http://srecord.sourceforge.net/
59
Method and implementation
CANalyzer is a development tool from Vector GmbH for CAN bus based
systems that allows the user to observe, analyze and provide data traffic on the
bus line. Specifically the functions included range from listing bus data traffic
(tracing), displaying data segments of specific messages, transmitting predefined
messages and replaying recorded messages, to statistically evaluating messages, bus
loading and disturbances. The picture below illustrates the main window after
opening CANalyzer.
To start using CANalyzer the bus was first setup. In this case the hardware
interface CANcaseXL USB 2.0 was provided for using it as the gateway that,
when connected to the bus, made possible the transmission and reception of data
frames to and from the target platform QR5567.
The main features of CANcaseXL include the USB 2.0 interface for connecting to
a laptop or PC, a 32-bit microcontroller with 64 MHz, 2 communication channels,
CAN 2.0B and LIN controllers and the bus transceivers which compose the
hardware that handles the signals in the bus at the physical level. The associated
driver for CANcaseXL was also installed in the computer running CANalyzer.
60
Method and implementation
This device can be fully operated from CANalyzer. Figure 22 shows CANcaseXL
and the associated cable to connect between it and the work computer.
61
Method and implementation
62
Findings and analysis
Flash Programming
In AUTOSAR version 4.0 some of the functions that are used for flash
programming via UDS are implemented but the support is not complete. XCP on
the other hand only had its basic functions (officially) implemented in AUTOSAR
4.0 and one of the paragraphs in the section 4.1 “Limitations” in the Specifications of
module XCP AUTOSAR-document states:
“The XCP feature “Flash Programming for ECU development purposes” is currently out of
AUTOSAR scope”. [35] No AUTOSAR roadmaps indicate that remote flash
programming is to be added to the AUTOSAR specification in the coming
revisions or years.
Download of Data
The XCP module as specified in AUTOSAR does not include any of the most
fundamental functions needed for flash programming unlike the UDS module
which counts with services such as RequestDownload andTransferData. The
RequestDownload service by itself is used by the client to initiate a data transfer from
the client to the server. [10] Very important parameters like the starting address
and size of the memory to be reprogrammed are included within this service. Such
basic functionality is not met by XCP according to AUTOSAR.
Standard in OBD
UDS is a part of the international standard ISO 15765: Road vehicles — Diagnostics
on Controller Area Networks (CAN) which further is one of the standards in the
widely spread OBD-II standard for On-Board Diagnostics. This indicates that
UDS already is widely accepted standard for diagnostic communication in the
automotive industry. [4]
63
Findings and analysis
Flash ✔ ✔ ✘ ✘
programming
Download of ✔ ✔ ✔ ✘
data
Upload of data ✔ ✔ ✔ ✘
Reset function ✔ ✔ ✔ ✔
Accept data ✔ ✔ ✔ ✔
transfer state
Access Security ✔ ✔ ✔ ✔
Read ✔ ✔ ✔ ✔
parameters
Write ✔ ✔ ✔ ✔
parameters
Standard in ✔ ✘ ✔ ✘
OBD
CAN interface ✔ ✔ ✔ ✔
LIN interface ✔ ✘ ✔ ✘
FlexRay ✔ ✔ ✔ ✔
interface
Ethernet ✔ ✔ ✘ ✔
interface
64
Findings and analysis
4.3 Communication
The implementation made possible to establish communication over the CAN bus
between the target platform QR5567 and the client program CANalyzer via
CANcaseXL. In addition, the diagnostic session for reprogramming can be started
in the target and the sequence of associated UDS requests sent are served and
responded by it. The following subsections describe firstly the used modules as
defined by AUTOSAR which were implemented or participated in the
communication process (on the server side) and later on the process for carrying
the diagnostic session according to UDS.
UDS messages, and other data, have to pass through the different layers that
AUTOSAR consists of before they can be handled by the correct UDS service.
UDS Services
↕
DCM
↕
PDU Router
↕
CAN TP
↕
CAN Interface
↕
CAN Driver
↕
Physical Bus
65
Findings and analysis
4.3.1.4 CAN Tp
When the CAN Transport layer receives a message from the interface layer it will
read the Protocol Control Information (PCI) of the message to see if it is a single
frame, first frame or a consecutive frame. Depending of what type of frame it is it
will call different functions in the PDU Router layer.
66
Findings and analysis
4.3.1.6 DCM
When the messages arrive to the Diagnostic Communication Manager module
they are examined to see what type of diagnostic service that shall be activated.
The DCM also keeps track of what diagnostic session the ECU is in and if the
requested diagnostic service is available in this session. If the service is not
available then will the DCM module send a negative response message back to the
client who sent the request If the request or the received data is transmitted in
multiple consecutive frames, they are put together into one message here in the
DCM module before the data is sent to the correct diagnostic service.
This example describes the reception of data that are transferred in multiple
frames, figure 19.
When the CAN Interface receives an interrupt that indicates that a new CAN
message have been received it will start to send the data to the
CanTp_RxIndication function. At the arrival of the first message to the
CanTp_RxIndication the CAN Tp module will call the PduR_StartOfReception
function. The PDU Router will just pass on the call to the Dcm_StartOfReception
function. In Dcm_StartOfReception a buffer will be prepared that can hold the
data that will arrive and a response will be sent back to tell that the buffer is ready.
67
Findings and analysis
When CAN Tp receives the next message it will send the message to the
PduR_CopyRxData function. The PDU Router will again just pass on the call to
the Dcm_CopyRxData function. In Dcm_CopyRxData the data will be extracted
from the message and stored into the buffer. The CopyRxData sequence will
continue until all data have been received and placed in the buffer. When all data
have been received, CAN Tp will call PduR_RxIndication function which in turn
will call Dcm_RxIndication function to tell that the copy of data is complete.
Figure 26 - Communication between CanTp, Pdu Router and DCM modules. [12]
68
Findings and analysis
After the primary bootloader has completed its initialization it will wait until a
valid UDS message, Diagnostic Session Control or ECU Reset, is received or until
the “start reprogramming” timeout timer has finished counting. The ECU is now
in the default session and an overview of the paths that the bootloader program
can take are shown in Figure 27. If the timer will time out the bootloader will start
the ECU application stored in the memory by making a jump to a predefined
memory address. If a Diagnostic Session Control message is received the timer be
stopped and a transition to the received session will be made. The program flow
will now on be completely controlled by incoming UDS requests. If there is no
ECU application present in the memory then the bootloader will stay in the
default session until Diagnostic Session Control message is received.
69
Findings and analysis
In the Extended Diagnostic Session the program will wait for UDS requests and
will stay in this session until a request to switch session or a reset message is
received. The program flow can take two different paths, as shown in Figure 28,
either execute Control DTS Setting and/or Communication Control or to switch
to another session. If you choose to execute Control DTS Setting and/or
Communication Control the program will stay in the extended diagnostic session
after execution and wait for new UDS requests.
70
Findings and analysis
In the Programming Session the program can again take two different paths,
execute functions in the programming session or switch to a different session with
a Diagnostic Session Control message or by an ECU Reset message. To be able to
execute any of the session specific functions, e.g. Request Download, they first
have to be unlocked by executing the Security Access function. If access have
been granted the programming sequence can begin when the first Request
Download request message is received; see Figure 29.
Figure 29 - Program flow when the ECU is in the programming session, part 1
71
Findings and analysis
Figure 30 - Program flow when the ECU is in the programming session, part 2
72
Findings and analysis
The Routine Control function will execute the routine that are specified in the
request. In Figure 31 the Routine Control starts a routine that was just
downloaded before, in this example case the “Erase Flash” routine.
Figure 31 - Program flow when the ECU is in the programming session, part 3
73
Findings and analysis
When the secondary bootloader has been downloaded and saved in the RAM
memory the program will make a jump to the secondary bootloader after the
Routine Control message have been received. The secondary bootloader will have
the same program flow as have been described in the Programming Session.
Default and Extended Diagnostic Sessions is not a part of the secondary
bootloader. The secondary bootloader will receive the application to be stored in
flash the same way as the secondary bootloader was received, Request Download -
> Transfer Data -> Request Transfer Exit. When the application is download it is
temporarily stored in RAM before it is written to the flash memory. Prior to
storing the application the flash has to be initialized and unlocked if a writing lock
is applied. Flash memory also has to be erased before new data can be written to it
and both the erasure and the writing of data are verified before the
reprogramming of flash is completed.
Because the part of flash reprogramming stayed in the development phase, in
order to verify the proper operation of the diagnostic session flow according to
UDS over CAN, a binary program (built as if it was the secondary bootloader)
including the same function that blinks the LED but at a lower frequency was
downloaded into SRAM in the target and properly executed afterwards.
4.4 Reprogramming
Since the implementation of the secondary bootloader was delayed and therefore
not fully integrated with the primary bootloader, the flash reprogramming
functionality was tested as a separate program loaded to run directly into RAM, by
using the PEEDI device. This way, the functions corresponding to the flash driver
proved to work well as it was possible to unlock, erase, write and verify flash
memory blocks.
74
Discussion and conclusions
The document then goes on and establishes that “the initialization services allow a
flexible and application related MCU initialization in addition to the start-up code” (quote)
and makes a reference to the picture shown immediately below.
75
Discussion and conclusions
As seen from the picture above, clearly the bootloader is considered a complete
separate block of code that would run after the startup code has finished its
operation and has nothing to do with the MCU driver.
From these statements and illustrations it can be seen that the concept of what a
bootloader doesn’t do (thus left to do by the MCU driver or startup-code)
according to AUTOSAR doesn’t hold to what it could be arguably considered the
“common” model of a bootloader.
At first, some of the features of the MCU driver presented above actually match
those a bootloader would include in its code such as initialization of MCU clock,
PLL, prescalers and RAM sections. In addition, no reasons are given to explain
when the Bootloader is needed and when it’s not. A comparison with [12] helps to
show these matching properties. For example, it is written there that the loader
responsible for the bootstrap process “initializes the RAM memory and possibly the on-
processor cache”(Li, 41) [1]. It is also explained there that part of the minimum
hardware initialization within the boot sequence includes “getting or setting the CPU’s
clock speed” (Li, 48) [1].
76
Discussion and conclusions
While it is a fact that the initialization process is very MCU-specific because of the
different underlying hardware components, memory types and sizes, CPU’s
architectures and available resources for the programmer, still the bootloader can
be recognized as the piece of code that takes care of such process. Because of
reasons like those recently presented it is thought that the idea of what a
bootloader is and does from the perspective of AUTOSAR is not concrete,
unclear, avoided and instead spread among other pieces of code called “driver” or
startup code, while it could well gather the functions these other codes provide
and therefore become standard.
As a result of only have one communication interface, CAN, and only implement
UDS, parts of AUTOSAR seems unnecessary, like for example PDU Router
which only forwarded messages between CAN Tp and DCM. In a more complex
system with multiple communication interfaces the purpose of PDU Router is
clear but when there is only one module above and one below the need of routing
is very limited.
77
Discussion and conclusions
5.3 Conclusions
Reprogramming will most likely be a part of AUTOSAR in the future but if it is
done through UDS or XCP is hard to tell. Even though UDS have more of its
functions needed for reprogramming already implemented today that does not
mean that it will be the preferred method of choice in the future. Only through
the comparison of practical implementations under the same testing conditions it
will be possible to observe which standard offers better results in terms of code
complexity, amount of overhead, reprogramming time and robustness, in case for
example, the communication link is lost while transmitting/receiving data.
The complexity of the electronic systems in a car have increased rapidly over the
last years and the manufacturers and Tier 1 suppliers are often faced with
conflicting requirements from different stakeholders. Because of this, a need to
standardized architectures and interfaces has arisen. Both AUTOSAR and UDS
will be important parts of the automotive industry in the near future and the
ability to easily upgrade the ECU software with new and improved functions will
probably be an even more important feature in the future than it is today.
Continuous work on AUTOSAR will unify the architectures in automotive
software and this will make it easier for automotive manufacturers to combine
technical solutions from different suppliers.
78
References
6 References
[1] Q. Li and C. Yao, "Real-Time Concepts for Embedded Systems," CMP books,
2003, pp. 35-50.
[2] S. Vidyadhara and A. Patil, "Best Practices in Boot Loader Design," Embedded
Systems Conference – San Jose, 2006, pp. 3-9.
[3] "CiA," 2012. [Online]. Available: http://www.can-
cia.org/index.php?id=systemdesign-can-history. [Accessed 11 05 2012].
[4] "Federal Register Environmental Documents," 2005. [Online]. Available:
http://www.epa.gov/fedrgstr/EPA-AIR/2005/December/Day-20/a23669.htm.
[Accessed 10 05 2012].
[5] "CAN Specification version 2.0," ROBERT BOSCH GmbH, Stuttgart, 1991.
[6] AUTOSAR, "Background," AUTOSAR, 2012. [Online]. Available:
http://www.autosar.org/index.php?p=1&up=1&uup=1&uuup=0. [Accessed 11 05
2012].
[7] AUTOSAR, "Basics," AUTOSAR, 2012. [Online]. Available:
http://www.autosar.org/index.php?p=1&up=1&uup=0. [Accessed 11 05 2012].
[8] AUTOSAR, "Layered Software Architecture 3.2.0," AUTOSAR, 2011.
[9] ISO, "ISO 14229-1 Road vehicles - Unified diagnostic services (UDS) Part 1,"
International Standards, 2007.
[10] AUTOSAR, "Specification of Diagnostic Communication Manager 4.0.0,"
AUTOSAR, 2009.
[11] AUTOSAR, "Specification of Diagnostic Event Manager 4.2.0," AUTOSAR,
2011.
[12] AUTOSAR, "Specification of PDU Router 3.2.0," AUTOSAR, 2011.
[13] AUTOSAR, "Specification of Communication Manager," AUTOSAR, 2011.
[14] AUTOSAR, "Specification of RTE," AUTOSAR, 2011.
[15] AUTOSAR, "Specification of Flash Driver 3.0.0," AUTOSAR, 2009.
[16] ASAM, "XCP General," in XCP Part 1 Overview version 1.0, 2003, p. 37.
[17] ASAM, "Absolute Access Mode," in XCP Part 1 Overview version 1.0, 2003, p.
38.
[18] ASAM, "Functional Access Mode," in XCP Part 1 Overview version 1.0, 2003,
p. 39.
[19] AUTOSAR, "Specification of CAN Interface 4.0.0," 2009.
[20] GmbH, Vector Informatik, "Vector Katalog ECU Software," p. 118, 05 2012.
[21] AB, QRTECH, "ODEEP," [Online]. Available: www.odeep.se. [Accessed 11 05
2012].
[22] Freescale, MPC5567 Microcontroller Reference, 2007.
[23] IBM, "developersWorks Technical library," 30 03 2004. [Online]. Available:
http://www.ibm.com/developerworks/linux/library/. [Accessed 01 01 2012].
[24] ISO, "ISO 15765-3 Road Vehicles - Implementation of Unified Diagnostic
Services (UDS on CAN)," International Standard, 2004.
[25] ISO, "ISO 15765-2 Road vehicles - Diagnostic on Controller Area Network
79
References
80