Embedded FreeBSD Cookbook Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com A Volume in the Embedded T echnology ™ Series Embedded FreeBSD Cookbook by Paul Cevoli An imprint of Elsevier Science Amsterdam Boston London New York Oxford Paris San Diego San Francisco Singapore Sydney Tokyo Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com iv Newnes is an imprint of Elsevier Science. Copyright © 2002, Elsevier Science (USA). All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Recognizing the importance of preserving what has been written, Elsevier Science prints its books on acid-free paper whenever possible. Librar y of Congress Cataloging-in-Publication Data ISBN: 1-5899-5004-6 British Librar y Cataloguing-in-Publication Data A catalogue r ecord for this book is available from the British Library. The publisher offers special discounts on bulk orders for this book. For information, please contact: Manager of Special Sales Elsevier Science 200 Wheeler Road Burlington, MA 01803 For information on all Newnes publications available, contact our World Wide Web home page at http://www.newnespress.com 10 9 8 7 6 5 4 3 2 1 Printed in the United States of America Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Preface vii Prerequisites and Other Resources vii 1 Getting Started 1 Overview 1 Embedded Systems 1 Internet Appliances 2 Compatibility of upgrades 3 Time to market 4 Labor pool 4 Licensing 4 The DIO Server Appliance 4 FreeBSD 5 GNU Development Tools 6 Java 7 Server 7 Data Acquisition 7 Boot Device 7 Summary 8 2 Systems Programming 9 Overview 9 Process 9 The 10 System Call 10 The 11 System Call 11 The 12 System Call 12 The 12 System Call 12 An Example 12 Process IDs 13 Security 14 An Example 15 The 16 and 16 System Calls 16 File Descriptors 17 Permissions 17 Current Working Directory 17 The 18 and 18 System Calls 18 The 18 System Call 18 Priority 19 State 20 The 20 Function 20 The 21 System Call 21 Daemons 21 Fork 21 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Create a new session 22 Close file descriptors 22 Change the current working directory 22 Set the file mode creation mask 22 Handle Child Exit Status 22 The 22 Function 22 The 23 Function 23 Summary 25 3 System Calls 27 Overview 27 Library Functions and System Calls 27 Software Interrupt 29 Passing Data 29 An Example 30 Creating a System Call 32 Load Handler 32 System Call Arguments 34 The 34 System Call 34 The 36 Structure 36 The System Call Number 36 The SYSCALL_MODULE Macro 38 Command Definitions 39 Command Table 40 The 40 Function 40 Command Function Handlers 42 The 45 Program 45 An example 47 Summary 48 4 Device Driver 49 Overview 49 Driver Environment 49 Driver Structure 51 The 52 Structure 52 The 53 Structure 53 The 55 Structure 55 The 57 Structure 57 The 57 Structure 57 The 57 Macro 57 The 58 Structure 58 The DIO24 Device Driver 59 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com The 61 Function 61 The 62 Function 62 The 63 Function 63 The 64 Function 64 The 66 Function 66 The 66 Function 66 The 67 Function 67 The 68 Function 68 The 69 Function 69 The 69 Function 69 Register Shadowing 71 The 73 Function 73 Summary 76 5 Midlevel Interface Library 77 Overview 77 Shared Libraries 77 Accessing the Device Driver 79 The 80 System Call 80 The 81 System Call 81 The 81 System Call 81 The 82 System Call 82 The 82 System Call 82 PCI-DIO24 Hardware Registers 82 The DIO24 Application Interface Library 87 The 89 and 90 Functions 90 The 92 and 92 Functions 92 The 94 and 94 Functions 94 The diopolarity 95 The 95 and 95 functions 95 The 97 and 97 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Functions 97 The 98 Function 98 Summary 101 6 Daemons 103 Overview 103 Introduction to TCP/IP 103 IP Addressing 105 ARP 105 RARP 106 ICMP 106 Ports 106 UDP 106 TCP 107 Socket System Calls 107 Connection Initiation 109 The 111 System Call 111 The 112 System Call 112 The 112 System Call 112 The 113 System Call 113 The 113 System Call 113 The 114 System Call 114 The 115 System Call 115 The DIO Daemon 115 The 115 Structure 116 The 117 Function 117 The 119 Function 119 The 120 Function 120 Summary 122 7 Remote Management 123 Overview 123 Using Secure Shell (SSH) 123 The DIOShell 130 The 132 Function 132 The 133 Function 133 The 134 Function 134 The 135 Function 135 The 136 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Function 136 The 137 Function 137 The 138 Function 138 The 139 Function 139 The 139 Function 139 The 140 Function 140 The 141 Utility 141 Summary 142 8 JNI Layer 143 Overview 143 The JDK 143 Creating the JNI Layer 145 The DIOLineState Class 147 The DIOLineNumber Class 148 The DIOLineDirection Class 149 The DIOIfJNI Class 150 The 154 Function 154 The 154 Function 154 The 155 Function 155 The Makefile 155 Summary 156 9 Web Access Using Tomcat 157 Overview 157 Tomcat 157 bin 158 JSP Overview 160 Comments 161 Directives 161 Declarations 162 Expressions 162 Code Scriptlets 162 The DIO JSP Page 162 Summary 165 10 Building the Kernel 167 Overview 167 The 168 Keyword 168 The 168 Keyword 168 The 168 Keyword 168 The 168 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Keyword 168 Kernel Options 169 Controllers and Device Drivers 171 Building the DIO Kernel 177 Building the FreeBSD Kernel 180 Summary 182 11 System Startup 183 Overview 183 Disk Geometry 183 Master Boot Record 185 Boot Loader 185 Partition Table 185 Magic Number 187 An Example 187 Unix Partitions 189 PC BIOS 189 FreeBSD Boot Loader 190 init 192 Starting DIO Components 194 Summary 196 12 The CompactFlash Boot Device 197 Overview 197 Solid-state Devices 197 Installing the TARC CompactFlash Adapter 198 Configuring the CompactFlash Device 199 Copying the Files to the Boot Device 201 Startup Configuration 201 Summary 205 A The FreeBSD License 207 B PCI Configuration 209 Vendor ID Register 211 Device ID Register 211 Command Register 211 Status Register 212 Revision ID 212 Class Code 212 Cache Line Size 212 Latency Timer 213 Header Type 213 BIST 213 Base Address Registers 213 CardBus CIS Pointer 213 Subsystem Vendor ID 213 Subsystem ID 213 Expansion ROM Address 213 Maximum Latency 214 Minimum Grant 214 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com [...]... the FreeBSD kernel con tains support for many disk and storage management facilities and secure 6 Embedded FreeBSD Simpo PDFCookbook and Split Unregistered Version - http://www.simpopdf.com Merge networking protocols The features and benefits of FreeBSD are summed up in the following paragraphs • Security FreeBSD offers security features that make it suitable for ecommerce applications, secure Internet... name, is available free of charge It can be down loaded directly from the FreeBSD website at ftp://ftp .FreeBSD. org/pub /FreeBSD/ Or, if you're like me and want to have an actual CD, as well as support the FreeBSD effort, there are a number of retail outlets where FreeBSD can be purchased, such as the BSD Mall, http://www.bsdmall.com /freebsd1 .html, or a number of local retail outlets such as Staples, CompUSA... yet another way to support FreeBSD The FreeBSD distribution is an open source project If you’re interested, you can contribute time and source code development Information about contributing to FreeBSD development can be found on the FreeBSD website, http://www .freebsd. org/doc/en_US.ISO8859-1/articles/contributing/index.html In addition to its mature networking technology, the FreeBSD kernel con tains... the product markets and requirements have evolved Classic embedded systems have been considered dedicated solutions to a single application In these classic systems, the hardware was custom designed to solve a specific application and the operating system was 2 Embedded FreeBSD Simpo PDFCookbook and Split Unregistered Version - http://www.simpopdf.com Merge developed internally All the software was self-contained... PRIO_USER user ID The setpriority and getpriority system calls return 0 on success and –1 on error 20 Embedded FreeBSD Simpo PDFCookbook and Split Unregistered Version - http://www.simpopdf.com Merge State A process is in one of five states at any time The process state is used internally by the FreeBSD kernel to organize processes Process states and their definitions are described below Description... The write Function 225 225 225 226 Commands 226 vii Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Preface Discussing embedded systems in general is difficult, because each embedded system is unique Rather than presenting a list of general principles for handling embedded development issues, this book presents examples of problems encountered and... resources toward developing their application, rather than keeping resources focused on maintaining the operating system or developing the next hardware platform 4 Embedded FreeBSD Simpo PDFCookbook and Split Unregistered Version - http://www.simpopdf.com Merge Time to market An open-source operating system reduces the time to qualify and develop the software solution The server appliances address increased... IDE drive In order to use a CompactFlash device as a boot device, a CompactFlash adapter is required There are numerous CompactFlash-toIDE adapters available 8 Embedded FreeBSD Simpo PDFCookbook and Split Unregistered Version - http://www.simpopdf.com Merge TAPR CompactFlash Adapter II The Tucson Amateur Packet Radio (TAPR) Club sells an IDE CompactFlash Adapter that can be used with generally available... of the DIO Internet appliance using FreeBSD Each chapter discusses a topic related to embedded system develop ment and provides a solution By the end of the book, we will have developed a working appliance Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 2 CHAPTER TWO 9 Systems Programming Overview Fundamental to any programming task in FreeBSD is the process, which is an... protected memory, the process is terminated A process running in memory consists of five segments: text, initialized data, uninitialized data, stack and heap 10 Embedded FreeBSD Simpo PDFCookbook and Split Unregistered Version - http://www.simpopdf.com Merge Text is typically read only and contains the machine instructions for the program Initial ized data contains variables that are preinitial ized . Embedded FreeBSD Cookbook Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com A Volume. system or developing the next hardware platform. Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 4 Embedded FreeBSD Cookbook T ime to market An open-sour ce operating. Commands 226 Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com vii Preface Discussing embedded systems in general is dif ficult, because each embedded system is unique.