Docsity

Understanding the Toolchain for Embedded C Systems: Compilers, Linkers, and Debuggers, Assignments of Computer Science

Toggle sidebar
bg1
Page 1
Assignment for Tues
๎˜Read โ€œGetting the Least out of Your C
Compilerโ€ โ€“ linked to course web page
Last Time
๎˜Looked at ColdFire and ARM in depth
Today
๎˜Tools and toolchains for embedded
systems
๎˜‚Linkers
๎˜‚Programmers
๎˜‚Booting an embedded CPU
๎˜‚Debuggers
๎˜‚JTAG
๎˜All of this stuff is โ€œbelowโ€ the C compiler in
the stack of tools
๎˜‚Subsequent lectures deal with embedded C
๎˜Any weak link in the toolchain will hinder
development
Compiler
m.c
m.o
Compiler
a.c
a.o
Linker
In-system programmer
libwhatever.a
system.hex
Debugger
Linking Background
๎˜Each .c file, plus any headers it includes, is
called a โ€œcompilation unitโ€
๎˜‚Compiler turns compilation unit into an object file
๎˜Each object (.o) file contains:
๎˜‚text segment โ€“ executable code
๎˜‚data segment โ€“ initialized data
๎˜‚BSS segment โ€“ uninitialized data
๎˜‚Other stuff โ€“ debugging symbols, etc.
๎˜Object files:
๎˜‚Relocatable
๎˜‚Code and data addresses are symbolic โ€“ not
yet bound to physical addresses
๎˜‚Contain unresolved references
Linking
๎˜Linker functions
1. Merge text, data, BSS segments of individual
object files
๎˜‚Including libraries
๎˜‚Including processor boot code
2. Resolve references to code and data
๎˜‚Report any errors
3. Locate relocatable code
๎˜‚Follow instructions in linker script
๎˜‚Report any errors
๎˜Result: Binary image ready to be loaded
onto the target system
pf3
pf4
pf5

Partial preview of the text

Download Understanding the Toolchain for Embedded C Systems: Compilers, Linkers, and Debuggers and more Assignments Computer Science in PDF only on Docsity!

Assignment for Tues

 Read โ€œGetting the Least out of Your C

Compilerโ€ โ€“ linked to course web page

Last Time

 Looked at ColdFire and ARM in depth

Today

 Tools and toolchains for embedded

systems

 Linkers  Programmers  Booting an embedded CPU  Debuggers  JTAG

 All of this stuff is โ€œbelowโ€ the C compiler in

the stack of tools

 Subsequent lectures deal with embedded C

 Any weak link in the toolchain will hinder

development

Compiler

m.c

m.o

Compiler

a.c

a.o

Linker

In-system programmer

libwhatever.a

system.hex

Debugger

Linking Background

 Each .c file, plus any headers it includes, is

called a โ€œcompilation unitโ€

 Compiler turns compilation unit into an object file

 Each object (.o) file contains:

 text segment โ€“ executable code  data segment โ€“ initialized data  BSS segment โ€“ uninitialized data  Other stuff โ€“ debugging symbols, etc.

 Object files:

 Relocatable  Code and data addresses are symbolic โ€“ not yet bound to physical addresses  Contain unresolved references

Linking

 Linker functions

1. Merge text, data, BSS segments of individual object files  Including libraries  **Including processor boot code

  1. Resolve references to code and data**  **Report any errors
  2. Locate relocatable code**  Follow instructions in linker script  Report any errors

 Result: Binary image ready to be loaded

onto the target system

Linker Operation

 Classify all program symbols as either:

 Weak โ€“ uninitialized globals  Strong โ€“ functions and initialized globals

 Scan object files in order supplied to the

linker, applying linker rules

 Bizarre consequence: Same object file might have to appear on command line multiple times

int foo=5;

p1() { }

int foo;

p2() { }

p1.c p2.c

strong

weak

strong

strong

Linker Operation

1. A strong symbol can only appear once

 otherwise error

2. A weak symbol is overridden by a strong

symbol of the same name

 I.e. all references to that name resolve to the strong symbol

3. If there are multiple weak symbols, the

linker can pick an arbitrary one

 uh oh

 Lots more details in CS 4400

Linker Scripts

 CodeWarrior linker is flexible and powerful

 Needs a โ€œprogramโ€ to tell it how to link for a given embedded platform  Linker script syntax looks just like GNU linker

 Linker script functionality:

 Put parts of executable into the right parts of memory  Insert padding to meet alignment requirements  Define extra symbols  Do arithmetic  Keep track of current position in memory as โ€œ.โ€

MCF52233 Linker Script

MEMORY {

code (RX) : ORIGIN = 0x00000500, LENGTH = 0x0003FB userram (RWX) : ORIGIN = 0x20000400, LENGTH = 0x00007C }

SECTIONS {

___heap_size = 0x1000; ___stack_size = 0x1000; }

More Linker Script

RAMBAR = 0x20000000; RAMBAR_SIZE = 0x00008000;

FLASHBAR = 0x00000000; FLASHBAR_SIZE = 0x00040000;

.vectors : { mcf5xxx_vectors.s (.text)

. = ALIGN (0x4); } >> vectorrom

*.text : { (.text)

*. = ALIGN (0x4); (.rodata) . = ALIGN (0x4); ___ROM_AT = .; ___DATA_ROM = .; } >> code

More Linker Script

.data : { ___DATA_RAM = .;

. = ALIGN(0x4);

_sinit = .; STATICINIT __START_DATA = .;

*(.data)

. = ALIGN (0x4); __END_DATA = .;

} >> userram

More Boot Code

move.l #___SP_INIT, sp

jsr _SYSTEM_SysInit

movea.l #0, A

link A6,

jsr _main

nop

nop

halt

Linker Scripts and Boot Code

 All code I showed you is in your

CodeWarrior project

 Plus lots more

 You can read it, modify it, etc.

 Example: disassemble fp_coldfire.a and

take a look

Debugging

 Important capabilities:

 Observability โ€“ See internal processor state  Real-time analysis โ€“ Follow execution without slowing it down or stopping it  Run control โ€“ Start and stop the processor, set breakpoints, watches, etc.

 For each debugging method:

 Which capabilities does it provide?  What are its other pros and cons?

Debugging Methods

 LEDs under software control

 Minimal workable debugging environment  A most unpleasant way to debug complex software

 printf() to serial console or LCD

 Severely perturbs timing, typically  Generally, a debug printf() is synchronous  Means: Hangs the system until the printf completes  Why?

More Debugging

 Logic analyzer hooked to external pins

 Timing mode โ€“ displays logic transitions on pins  State mode โ€“ decode executing instructions, bus transactions, etc.  Triggers โ€“ give the analyzer conditions on which to start a detailed trace  Triggers can be highly elaborate

 Remote debugger

 Debugging stub runs on embedded processor  Main debugger (e.g., GDB) runs on a separate machine  The two communicate using Ethernet, serial line, or whatever

More Debugging

 JTAG, BDM, Nexus

 Basically just hardware implementations of debugging stubs

 ICE โ€“ in-circuit emulator

 Acts like your embedded processor but provides lots of extra functionality  Runs at full speed  Typically expensive

More Debugging

 ROM emulator

 Looks like ROM, actually RAM + processor  At minimum supports rapid loading of new SW  Can implement breakpoints, execution tracing

 Simulator

 Maximum controllability and observability  Often slow  Hard to interface to the real world  Easy to simulate the CPU, hard to simulate everything else

JTAG โ€“ IEEE1149.

 Initially for hardware testing, evolved to

support software testing

 Basic idea:

 Each I/O pin, register, etc. can be โ€œsniffedโ€ by a JTAG cell  JTAG cells are connected in a โ€œJTAG loopโ€  Contents of entire JTAG loop can be read using a shift register  Can also be written  External tool can reconstruct machine state from the JTAG bit stream

JTAG Hardware Debugging

Each JTAG cell โ€œsniffsโ€ the state of the corresponding output bit of the IC

JTAG bit stream in JTAG bit stream out

Bit stream forms one long shift-register

PC Board

JTAG Connector

JTAG Software Debugging

Processor Core

Program Counter - PC

Register R

Register R

Register Rn

Addr Bus Interface

Data Bus Interface

Status Bus Interface

JTAG Control State Machine

JTAG in

Clock in (^) JTAG out

โ€œSPECIALโ€ REGISTER SET

More JTAG

 Advantages of shift-register approach:

 Simple  Requires few pins

 Disadvantage of shift-register approach:

 End up reading and writing a lot of data just to change one register

 JTAG optimizations:

 Commands โ€“ Directly change a single register or memory cell  Addressable loops โ€“ smaller JTAG loops each containing a subset of the machine state

More JTAG

 Pins:

 TCK โ€“ clock  TDI โ€“ input data stream, sampled on rising edge of TCK  TDO โ€“ output data stream, updated on falling edge of TCK  TRST โ€“ Resets JTAG state machine (optional)  TMS โ€“ Test mode select: advances JTAG state machine

 JTAG interface modules tend to be

expensive

 โ€œLow costโ€ solutions may be $  However, all-software solutions (on the host side) exist  MCF52233 has JTAG