Zilogic Systems 1 Embedded Programming with the GNU Toolchain Vijay Kumar B.

Slides:



Advertisements
Similar presentations
Programs in Memory Bryce Boe 2012/08/29 CS32, Summer 2012 B.
Advertisements

UEE072HM Linking HLL and ALP An example on ARM. Embedded and Real-Time Systems We will mainly look at embedded systems –Systems which have the computer.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 3: ISA, Assembly, and Toolchains September 13, 2011.
Program Development Tools The GNU (GNU’s Not Unix) Toolchain The GNU toolchain has played a vital role in the development of the Linux kernel, BSD, and.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
9.0 EMBEDDED SOFTWARE DEVELOPMENT TOOLS 9.1 Introduction Application programs are typically developed, compiled, and run on host system Embedded programs.
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Characteristics of Realtime and Embedded Systems Chapter 1 6/10/20151.
ARM C Language & Assembler. Using C instead of Java (or Python, or your other favorite language)? C is the de facto standard for embedded systems because.
Software Development and Software Loading in Embedded Systems.
ARM Core Architecture. Common ARM Cortex Core In the case of ARM-based microcontrollers a company named ARM Holdings designs the core and licenses it.
Introduction Purpose Objectives Content Learning Time
Cortex-M3 Programming. Chapter 10 in the reference book.
Atmega32 Architectural Overview
Writing an Assembly-language program Atmel assembly language CS-280 Dr. Mark L. Hornick 1.
Lecture 5. AT91 - Memory Map, Timers, and AIC -
© 2003 Xilinx, Inc. All Rights Reserved Address Management.
AT91RM9200 Boot strategies This training module describes the boot strategies on the AT91RM9200 including the internal Boot ROM and the U-Boot program.
Enabling the ARM Learning in INDIA ARM DEVELOPMENT TOOL SETUP.
Introduction: Exploiting Linux. Basic Concepts Vulnerability A flaw in a system that allows an attacker to do something the designer did not intend,
Topic 2d High-Level languages and Systems Software
This material exempt per Department of Commerce license exception TSU Address Management.
1 CS503: Operating Systems Spring 2014 Part 0: Program Structure Dongyan Xu Department of Computer Science Purdue University.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 4: Memory and Memory-Mapped I/O September 16, 2010.
1 EECS 373 Design of Microprocessor-Based Systems Mark Brehob University of Michigan Lecture 3: Toolchain, ABI, Memory Mapped I/O January 14 th, 2016 Slides.
1 Basic Processor Architecture. 2 Building Blocks of Processor Systems CPU.
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 4: Review, Simulation, ABI, and Memory-Mapped I/O September.
CSc 453 Linking and Loading
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Hello world !!! ASCII representation of hello.c.
김민수 Cortex-M4 Processor - Getting Started with the GNU Compiler Collection(gcc)
Intel Xscale® Assembly Language and C. The Intel Xscale® Programmer’s Model (1) (We will not be using the Thumb instruction set.) Memory Formats –We will.
“Atmega32 Architectural Overview” SIGMA INSTITUTE OF ENGINEERING Prepared By: SR.NO NAME OF STUDENT ENROLLMENT 1 Parihar Shipra A Guided By:-
Intel Xscale® Assembly Language and C. The Intel Xscale® Programmer’s Model (1) (We will not be using the Thumb instruction set.) Memory Formats –We will.
Lecture 3 Translation.
Popular Microcontrollers and their Selection by Lachit Dutta
Instruction Set Architectures
Assembly language.
ECE 3430 – Intro to Microcomputer Systems
Chapter 1 Introduction.
Atmega32 Architectural Overview
Microcontrollers & GPIO
ECE 3430 – Intro to Microcomputer Systems
Gunjeet Kaur Dronacharya Group of institutions
System Programming and administration
ARM Registers Register – internal CPU hardware device that stores binary data; can be accessed much more rapidly than a location in RAM ARM has.
ECE 3430 – Intro to Microcomputer Systems
Chapter 4 Addressing modes
Software Development with uMPS
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Topic 2e High-Level languages and Systems Software
Slides developed in part by Prof. Dutta
Introduction to Microprocessors and Microcontrollers
Number Representations and Basic Processor Architecture
ARM Assembly Programming
AT91RM9200 Boot strategies This training module describes the boot strategies on the AT91RM9200 including the internal Boot ROM and the U-Boot program.
9.0 EMBEDDED SOFTWARE DEVELOPMENT TOOLS
Computer Architecture
Embedded System Development Lecture 13 4/11/2007
COMS 361 Computer Organization
Introduction to Microprocessor Programming
Slides developed in part by Mark Brehob
Wireless Embedded Systems
8051 ASSEMBLY LANGUAGE PROGRAMMING
Computer System Laboratory
Program Assembly.
Introduction to Assembly Chapter 2
ICS103 Programming in C 1: Overview of Computers And Programming
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
An Introduction to the ARM CORTEX M0+ Instructions
Presentation transcript:

Zilogic Systems 1 Embedded Programming with the GNU Toolchain Vijay Kumar B.

Zilogic Systems 2 What? C Application OS Hardware C Application Hardware Conventional C ProgramsOur Case

Zilogic Systems 3 Why? ● Embedded Firmware Development ● RTOS development – eCOS, RTEMS,... ● Bootloader development – U-Boot,... ● Programming DSPs ● Testing Microprocessors cores implemented in ASICs / FPGAs

Zilogic Systems 4 How? ● 3 Example Scenarios ● Hello Embedded World – Add 2 numbers in registers in assembly ● Add 2 numbers from memory in assembly ● Add 2 numbers from memory in C

Zilogic Systems 5 Scenario I - Overview ● Cortex-M3 Processor ● Writing Assembly Programs ● Emulating Cortex-M3 with Qemu

Zilogic Systems 6 ARMv7 ● Latest revision of ARM architecture – ARMv7 ● Cortex Processor – ARMv7 implementation ● Profiles – A Profile – GPOS and applications – R Profile – optimized for realtime systems – M Profile – optimized for low cost embedded systems

Zilogic Systems 7 Cortex-M3 Features ● Thumb-2 Instruction Set ● Bit Banding ● Integrated Peripherals – NVIC – Memory Protection Unit (MPU) – Debug Peripherals

Zilogic Systems 8 CM3 SoCs ● SoC vendors license CM3 from ARM ● SoC vendors use it as building block ● Licensees – TI – Stellaris processors – Atmel – ATSAM3U series – STMicroelectronics – STM32 – NXP - LPC1700

Zilogic Systems 9 LM3S811 ● Cortex-M3 core ● Memory – 64KB Flash – 8KB RAM ● Peripherals – 10 bit ADCs – I2C, SPI, UARTs, PWM – 32 GPIOs

Zilogic Systems 10 Registers ● Load Store Architecture ● Data processing instructions – register operands ● Large register file – bit registers

Zilogic Systems 11 Registers (Contd.) R0 R2 R3 R1 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 (SP) R14 (LR) R15 (PC) PSR CONTROL PRIMASK FAULTMASK BASEPRI ● R0 – R12 – General Purpose ● R13 – Stack Pointer ● R14 – Link Register ● R15 – Program Counter

Zilogic Systems 12 Memory Map ● CM3 has a fixed memory map ● Easy to port software ● 4GB Address Space ● LM3S811 – 64KB Flash – 8KB SRAM Flash SRAM 0x0000_0000 0x2000_0000 Peripherals 0x4000_0000

Zilogic Systems 13 Reset ● SP from address 0x0 ● PC from address 0x4 ● Address is mapped to Flash Initial SP Reset Vec. 0x0000 0x0004

Zilogic Systems 14 Assembly ● label: convenient way to refer to the memory location ● instruction: ARM instruction or assembler directive ● comment: starts label:

Zilogic Systems 15 Hello Embedded World.thumb.syntax unified sp:.word 0x100 reset:.word start+1 start: mov r0, #5 mov r1, #4 add r2, r1, r0 stop: b stop

Zilogic Systems 16 Toolchain Assembler (as) Linker (ld) Assembler Source (.s) Object File (.o) Executable (.elf)

Zilogic Systems 17 Toolchain (Contd.) $ arm-none-eabi-as -mcpu=cortex-m3 -o add.o add.s ● Cross toolchain prefix - arm-none-eabi- ● -mcpu=cortex-m3 Specifies the CPU ● -o Specifies the output file

Zilogic Systems 18 Toolchain (Contd.) $ arm-none-eabi-ld -Ttext=0x0 -o add.elf add.o ● Cross toolchain prefix - arm-none-eabi- ● -Ttext=0x0 Addresses should be assigned to instructions starting from 0. ● -o Specifies the output file

Zilogic Systems 19 Toolchain (Contd.) $ arm-none-eabi-nm add.elf t reset t sp t start t stop ● List symbols from object file ● Verify initial SP and reset vector are located at required address

Zilogic Systems 20 Toolchain (Contd.) ● ELF file format contains meta information for OS ● Binary format contains consecutive bytes starting from an address ● Convenient for flashing tools

Zilogic Systems 21 Toolchain (Contd.) $ arm-none-eabi-objcopy -O binary add.elf add.bin ● objcopy – converts between different executable file formats ● -O specifies that output file format

Zilogic Systems 22 Qemu ● Open source machine emulator - the processor and the peripherals ● Architectures – i386, ARM, MIPS, SPARC... ● Used by various open source projects – OLPC – OpenMoko – Linux Kernel Testing

Zilogic Systems 23 Emulating in Qemu $ qemu-system-arm -M lm3s811evb -kernel add.bin ● -M lm3s811evb specifies the machine to be emulated ● -kernel specifies data to be loaded in Flash from address 0x0 ● monitor interface – control and status ● can be used to view the registers

Zilogic Systems 24 Review ● Writing simple assembly programs ● Building and linking them using GNU Toolchain ● Emulating Cortex-M3 processor using Qemu

Zilogic Systems 25 Scenario II - Overview ● Role of Linker ● Linker Scripts ● Placing data in RAM

Zilogic Systems 26 Linker assembler a.s a.o assembler b.sb.o assembler c.s c.o linker abc.o ● In multi-file programs – combines multiple object files to form executable

Zilogic Systems 27 Linker (Contd.) Linker Symbol Resolution Relocation Section Merging Section Placement

Zilogic Systems 28 Linker (Contd.) Linker Symbol Resolution Relocation Section Merging Section Placement

Zilogic Systems 29 Symbol Resolution ● Functions are defined in one file ● Referenced in another file ● References are marked unresolved by the compiler ● Linker patches the references

Zilogic Systems 30 Linker Symbol Resolution Relocation Section Merging Section Placement

Zilogic Systems 31 Relocation ● Code generated assuming it starts from address X ● Code should start from address Y ● Change addresses assigned to labels ● Patch label references

Zilogic Systems 32 Sections ● Placing related bytes at a particular location. ● Example: – instructions in Flash – data in RAM ● Related bytes are grouped together using sections ● Placement of sections can be specified

Zilogic Systems 33 Sections (Contd.) ● Most programs have atleast two sections,.text and.data ● Data or instructions can be placed in a section using directives ● Directives –.text –.data –.section

Zilogic Systems 34 Sections (Contd.) ● Source – sections can be interleaved ● Bytes of a section – contiguous addresses

Zilogic Systems 35 Linker Symbol Resolution Relocation Section Merging Section Placement

Zilogic Systems 36 Section Merging ● Linker merges sections in the input files into sections in the output file ● Default merging – sections of same name ● Symbols get new addresses, and references are patched ● Section merging can be controlled by linker script files

Zilogic Systems 37 Linker Symbol Resolution Relocation Section Merging Section Placement

Zilogic Systems 38 Section Placement ● Bytes in each section is given addresses starting from 0x0 ● Labels get addresses relative to the start of section ● Linker places section at a particular address ● Labels get new address, label references are patched

strlen

Zilogic Systems 42 Linker Script Linker Symbol Resolution Relocation Section Merging Section Placement Can be controlled through Linker scripts.

Zilogic Systems 43 Simple Linker Script MEMORY { FLASH (rx) : ORIGIN = 0x , LENGTH = 0x10000 SRAM (rwx) : ORIGIN = 0x , LENGTH = 0x2000 } SECTIONS {.text : { abc.o (.text); def.o (.text); } > FLASH } abc.o (.text) def.o (.text) 0x0 0xFFFF

Zilogic Systems 44 Simple Linker Script MEMORY { FLASH (rx) : ORIGIN = 0x , LENGTH = 0x10000 SRAM (rwx) : ORIGIN = 0x , LENGTH = 0x2000 } SECTIONS {.text : { abc.o (.text); def.o (.text); } > FLASH } Section Merging

Zilogic Systems 45 Simple Linker Script MEMORY { FLASH (rx) : ORIGIN = 0x , LENGTH = 0x10000 SRAM (rwx) : ORIGIN = 0x , LENGTH = 0x2000 } SECTIONS {.text : { abc.o (.text); def.o (.text); } > FLASH } Section Placement

Zilogic Systems 46 Making it Generic MEMORY { FLASH (rx) : ORIGIN = 0x , LENGTH = 0x10000 SRAM (rwx) : ORIGIN = 0x , LENGTH = 0x2000 } SECTIONS {.text : { * (.text); } > FLASH } Wildcards to represent.text form all input files

Zilogic Systems 47 Multiple Sections MEMORY { FLASH (rx) : ORIGIN = 0x , LENGTH = 0x10000 SRAM (rwx) : ORIGIN = 0x , LENGTH = 0x2000 } SECTIONS {.text : { * (.text); } > FLASH.rodata : { * (.rodata); } > FLASH } Dealing with mutiple sections.text.rodata 0x0 0xFFFF

Zilogic Systems 48 Data in RAM ● Add two numbers from memory ● Assembly source ● Linker Script

Zilogic Systems 49 RAM is Volatile! ● RAM is volatile ● Data cannot be made available in RAM at power-up ● All code and data should be in Flash at power- up ● Startup code – copies data from Flash to RAM

Zilogic Systems 50 RAM is Volatile! (Contd.) ●.data section should be present in Flash at power-up ● Section has two addresses – load address (aka LMA) – run-time address (aka VMA) ● So far only run-time address – actual address assigned to labels ● Load address defaults to run-time address

Zilogic Systems 51 Linker Script Revisited MEMORY { FLASH (rx) : ORIGIN = 0x , LENGTH = 0x10000 SRAM (rwx) : ORIGIN = 0x , LENGTH = 0x2000 } SECTIONS {.text : { * (.text); } > FLASH.data : { * (.data); } > SRAM }.text 0x x0000FFFF Flash 0x x20001FFF SRAM.data

Zilogic Systems 52 Linker Script Revisited MEMORY { FLASH (rx) : ORIGIN = 0x , LENGTH = 0x10000 SRAM (rwx) : ORIGIN = 0x , LENGTH = 0x2000 } SECTIONS {.text : { * (.text); } > FLASH.data : { * (.data); } > SRAM AT> FLASH }.text 0x x0000FFFF Flash 0x x20001FFF SRAM.data

Zilogic Systems 53 Linker Script Revisited MEMORY { FLASH (rx) : ORIGIN = 0x , LENGTH = 0x10000 SRAM (rwx) : ORIGIN = 0x , LENGTH = 0x2000 } SECTIONS {.text : { * (.text); etext =.; } > FLASH.data : { sdata =.; * (.data); edata =.; } > SRAM AT> FLASH }.text.data etext sdata edata

Zilogic Systems 54 Data in RAM ● Copy.data from Flash to RAM start: ldr r0, Load the address of sdata ldr r1, Load the address of edata ldr r2, Load the address of etext copy: ldrb r3, Load the value from Flash strb r3, Store the value in RAM add r2, r2, Increment Flash pointer add r0, r0, Increment RAM pointer cmp r0, Check if end of data bne Branch if not end of data

Zilogic Systems 55 Review ● Linker Script can control – Section Merging – Section Placement ●.data placed in RAM,.text in Flash ● RAM is volatile ● at load time.data is in Flash ● at startup.data is copied from Flash to RAM

Zilogic Systems 56 Scenario III - Overview ● C Environment Requirements ● C Sections ● C Source Code ● Linker Script

Zilogic Systems 57 Doing it in C ● Environment has to be setup – Stack pointer – Non-initalized global variables, initialized to zero – Initialized global variables must have their initial value

Zilogic Systems 58 C Sections ● Sections created by GCC –.text – for functions –.data – for initialized global data –.bss – for uninitialized global data –.rodata – for strings and global variables defined as const

Zilogic Systems 59 Credits ● Cash Register – Nikola Smolenski ● Cerebral Cortex - ● Reset Button – flattop ● Church Relocation – Fletcher6 ● Rope Image - Markus Bärlocher

Zilogic Systems 60 Further Reading ● Embedded Programming using the GNU Toolchain - ● GNU Linker Manual ● GNU Assembler Manual