Upload
others
View
20
Download
0
Embed Size (px)
Citation preview
EE458 - Embedded SystemsLecture 3 – Embedded Devel.
● Outline– Developing for Embedded Systems– C File Streams
● References– RTC: Chapter 2– File Streams man pages
1
Developing for Embedded Systems
2
Cross-platform Development Environment
Developing for Embedded Systems
● Software available on the host system typically includes a cross-compiler, a linker, and a source-level debugger.
● Software on the target might include a dynamic loader, a link loader, a , and a debug agent.
● One or more connections allow downloading of program images and debugging.
3
Developing for Embedded Systems
● Embedded systems development requires much greater knowledge of the target architecture and the compile and link processes than does development for a general purpose OS (GPOS).
● How is the image transferred? How and where is the image loaded at runtime? How do we the program running on the target?
4
Developing for Embedded Systems
● On the host system:
– A compiler or assembler is used to convert source code to object code (.o files).
– The make program may be used to control the compile and linking processes.
– A is used to combine object files into an executable image file.
5
Developing for Embedded Systems
6
The different toolsthat are used on thehost to create anexecutable image.
Developing for Embedded Systems
● Each object file created by the compiler contains a “Symbol Table” and a “ ”.
● The Symbol Table maps variable and function names to their relative address locations.
● The contains a list of all addresses that reference symbols in the Symbol Table.
7
Developing for Embedded Systems
8The Symbol and Relocation Tables
Developing for Embedded Systems
● The linker uses these two tables to convert all relative address references to the actual addresses assigned to the symbols.
● When creating an executable all references are resolved so that each symbol has an absolute memory address.
9
Developing for Embedded Systems
● RTEMS images and object files are in the format (Executable and Linking Format) that is described in the text.
● The binary instructions, binary data, symbol table, relocation table, and debug information are organized and contained in different sections of the file.
10
Developing for Embedded Systems
● The readelf command displays section types and (edited for readability):
$ i386-rtems-readelf -a hello.exeELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 ... Class: ELF32 Data: 2's complement, little endian
Section Headers: [Nr] Name Type Addr Size ES Flg [ 1] .text PROGBITS 00100000 017584 00 WAX [ 4] .data PROGBITS 00117599 002d67 00 WA [ 6] .bss NOBITS 0011a300 002aec 00 WA
11
Developing for Embedded Systems
● Sections of the image can be mapped to particular areas of memory by using MEMORY and commands in a linker script.
● The developer must, of course, know the types of memory available (ROM, RAM, Flash) and the address of each type in order to write a proper linker script.
12
Developing for Embedded Systems
13
Target System Memory Map
Developing for Embedded Systems
● The GNU linker is ld (i386-rtems-ld for RTEMS development). (See “info ld” for additional information.)
● Since we are developing for the PC (whose architecture is well known) we will not have to write special . (You would need to create linker scripts when porting RTEMS to a new BSP.)
14
C File Streams
● Now, on to a completely new topic.
● RTEMS does not provide implementations of the C++ iostream classes (cin, cout, cerr)
● Input and output is performed using the traditional (or FILE) streams.
15
C File Streams
● Here is some example code demonstrating I/O with FILE streams:
#include <stdio.h>
int total = 12000;
FILE *myfile =
fopen(“output.txt”, “w”);
fprintf(myfile, “Sum is %d\n”, total);
fclose(myfile);
16
C File Streams
● The fopen() routine associates a FILE stream with a filename. The first argument is the filename. The second argument is the mode: “r”, “w”, “a”, “r+”, “w+” or “a+”. See the fopen man page for details. (man 3 fopen)
● Three streams are automatically opened: stdin, stdout, .#include <stdio.h>
fprintf(stdout, “Sum is %d\n”, total);
17
C File Streams
● The fprintf() routine (man 3 printf) writes variables to a FILE stream in accordance with a format specifier. The format specifier is a char string that contains ordinary text and conversion specifiers. Conversion specifiers begin with a .fprintf(stdout, “Name: %s %s\n”, fname, lname);
fprintf(stdout, “Age: %d\n”, age);
printf(“Volt=%f, Current=%f\n”, v, i);
18
C File Streams
● The fscanf() routine (man 3 scanf) is used to read variables from a FILE stream in accordance with a format specifier. The of the variable is used as an argument to fscanf():fscanf(stdin, “%s %s”, fname, lname);
fscanf(stdin, “%d”, &age);
// Note %lf for double %f for float
scanf(“%lf %lf”, &v, &i);
19
C File Streams
● The fputc()/putc()/putchar() routines can be used to write a single character to a stream.
● The fgetc()/getc()/getchar() routines can be used to read a single char from a stream.
● sprintf() prints to a char array instead of to a stream. It is useful for converting numbers to . sscanf() can be used to read variables from a char array.
20
C File Streams
● C FILE streams are buffered. Output is not written until the buffer is full or an input routine (fscanf, fgetc, etc) is called. You can flush the output buffer with .
● When using the input routines (fscanf, fgetc, etc) input is normally not returned to the program until a newline is entered. (The termios routines can be used to change this behavior.)
21