EE458 - Embedded Systems Lecture 4 Embedded Devel.

Similar documents
Accessing Files in C. Professor Hugh C. Lauer CS-2303, System Programming Concepts

CS113: Lecture 7. Topics: The C Preprocessor. I/O, Streams, Files

Standard C Library Functions

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Standard File Pointers

Lecture 03 Bits, Bytes and Data Types

Link 3. Symbols. Young W. Lim Mon. Young W. Lim Link 3. Symbols Mon 1 / 42

Input/Output and the Operating Systems

CMPT 102 Introduction to Scientific Computer Programming. Input and Output. Your first program

Input / Output Functions

Programming in C. Session 8. Seema Sirpal Delhi University Computer Centre

C Input/Output. Before we discuss I/O in C, let's review how C++ I/O works. int i; double x;

CSci 4061 Introduction to Operating Systems. Input/Output: High-level

File I/O Lesson Outline

Binghamton University. CS-211 Fall Input and Output. Streams and Stream IO

Binghamton University. CS-211 Fall Input and Output. Streams and Stream IO

Binghamton University. CS-220 Spring Includes & Streams

Introduction to Computing Lecture 03: Basic input / output operations

Content. Input Output Devices File access Function of File I/O Redirection Command-line arguments

CS240: Programming in C

Should you know scanf and printf?

UNIT IV-2. The I/O library functions can be classified into two broad categories:

Computer Programming: Skills & Concepts (CP) Files in C

C programming basics T3-1 -

Input/Output: Advanced Concepts

File I/O Lesson Outline

CSE 230 Intermediate Programming in C and C++ Input/Output and Operating System

C for Engineers and Scientists: An Interpretive Approach. Chapter 14: File Processing

Systems Programming. Fatih Kesgin &Yusuf Yaslan Istanbul Technical University Computer Engineering Department 18/10/2005

Files. Programs and data are stored on disk in structures called files Examples. a.out binary file lab1.c - text file term-paper.

Embedded Systems Programming

DATA STRUCTURES USING C

Lecture 7: Files. opening/closing files reading/writing strings reading/writing numbers (conversion to ASCII) command line arguments

File IO and command line input CSE 2451

211: Computer Architecture Summer 2016

System Software Experiment 1 Lecture 7

This code has a bug that allows a hacker to take control of its execution and run evilfunc().

C PROGRAMMING. Characters and Strings File Processing Exercise

Introduction to C An overview of the programming language C, syntax, data types and input/output

Computer Programming: Skills & Concepts (CP1) Files in C. 18th November, 2010

CpSc 111 Lab 3 Integer Variables, Mathematical Operations, & Redirection

Basic I/O. COSC Software Tools. Streams. Standard I/O. Standard I/O. Formatted Output

25.2 Opening and Closing a File

CAAM 420 Notes Chapter 2: The C Programming Language

Quick review of previous lecture Ch6 Structure Ch7 I/O. EECS2031 Software Tools. C - Structures, Unions, Enums & Typedef (K&R Ch.

PROGRAMMAZIONE I A.A. 2017/2018

CpSc 1111 Lab 4 Formatting and Flow Control

Layers in a UNIX System. Create a new process. Processes in UNIX. fildescriptors streams pipe(2) labinstructions

Physical Files and Logical Files. Opening Files. Chap 2. Fundamental File Processing Operations. File Structures. Physical file.

SWEN-250 Personal SE. Introduction to C

AMCAT Automata Coding Sample Questions And Answers

Basic and Practice in Programming Lab 10

Topic 8: I/O. Reading: Chapter 7 in Kernighan & Ritchie more details in Appendix B (optional) even more details in GNU C Library manual (optional)

CSI 402 Lecture 2 Working with Files (Text and Binary)

Classes and Objects. Instructor: 小黑

Computational Methods of Scientific Programming Fall 2007

Introduction to Programming

UNIT-V CONSOLE I/O. This section examines in detail the console I/O functions.

CpSc 1011 Lab 3 Integer Variables, Mathematical Operations, & Redirection

Linking. Explain what ELF format is. Explain what an executable is and how it got that way. With huge thanks to Steve Chong for his notes from CS61.

CSE 12 Spring 2018 Week One, Lecture Two

Library Functions. General Questions

sends the formatted data to the standard output stream (stdout) int printf ( format_string, argument_1, argument_2,... ) ;

CSCI 171 Chapter Outlines

Goals of this Lecture

C++ basics Getting started with, and Data Types.

Linking and Loading. ICS312 - Spring 2010 Machine-Level and Systems Programming. Henri Casanova

I/O Management! Goals of this Lecture!

I/O Management! Goals of this Lecture!

Fundamentals of Programming. Lecture 3: Introduction to C Programming

CS201 Lecture 2 GDB, The C Library

CS 220: Introduction to Parallel Computing. Input/Output II. Lecture 8

Mode Meaning r Opens the file for reading. If the file doesn't exist, fopen() returns NULL.

UNIX input and output

File I/O. Arash Rafiey. November 7, 2017

CpSc 1111 Lab 5 Formatting and Flow Control

Programming Language B

Today s Learning Objectives

File (1A) Young Won Lim 11/25/16

File I/O Christian Schumacher, Info1 D-MAVT 2013

Writing to and reading from files

CS 61C: Great Ideas in Computer Architecture CALL continued ( Linking and Loading)

Department of Computer Science and Engineering Yonghong Yan

Organization of a file

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 12

Review (1/2) IEEE 754 Floating Point Standard: Kahan pack as much in as could get away with. CS61C - Machine Structures

Layers of Abstraction CS 3330: C. Compilation Steps. What s in those files? Higher-level language: C. Assembly: X86-64.

CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting

Introduction to the C programming language

CSE 351. GDB Introduction

ECE 471 Embedded Systems Lecture 4

CSE 124 Discussion (10/3) C/C++ Basics

CMPE-013/L. File I/O. File Processing. Gabriel Hugh Elkaim Winter File Processing. Files and Streams. Outline.

LAB 13 FILE PROCESSING

Chapter 1 Introduction to Computers and C++ Programming

CS 261 Fall Mike Lam, Professor. Structs and I/O

BİL200 TUTORIAL-EXERCISES Objective:

C Basics And Concepts Input And Output

JTSK Programming in C II C-Lab II. Lecture 3 & 4

Lectures 5-6: Introduction to C

Transcription:

EE458 - Embedded Lecture 4 Embedded Devel. Outline C File Streams References RTC: Chapter 2 File Streams man pages 1

Cross-platform Development Environment 2

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 a debug agent., and One or more connections allow downloading of program images and debugging. 3

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

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

The different tools that are used on the host to create an executable image. 6

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

The Symbol and Relocation Tables 8

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

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

The readelf command displays section types and (edited for readability): $ i386-rtems-readelf -a hello.exe ELF 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

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

Target System Memory Map 13

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