jumpstart-xscale
Download
Report
Transcript jumpstart-xscale
MontaVista Linux
Professional Edition
Jump Start Training
Embedded Linux Technology Inc.,
Taiwan Branch
Email: [email protected]
TEL: 02-23784056
1
Agenda
• 10:10 ~ 11:00
– Preparing Development
System
– Development Environment
– Boot ROM
• 11:10 ~ 12:00
– Boot Configure and
Download
– MontaVista Development
Tools (I)
• 13:10 ~ 14:00
– MontaVista Development
Tools (II)
• 14:10 ~ 15:00
– File Systems
– Kernel Modules
• 15:10 ~ 16:00
– MontaVista Realtime
2
Preparing Development System
• MontaVista Software Package Installation
• Supported Host Distributions
– MVL PE 2.1:
•
•
•
•
•
•
MVL PE 3.0:
Mandrake 7.2, 8.0 and 8.1
8.1
RedHat 6.2, 7.0, 7.1 and 7.2
7.2 and 7.3
SuSE 7.3
7.3
Yellow Dog 2.1
2.1
Solaris 7 and 8
7 and 8
VMware[tm] Workstation 3.1 on Windows(R) NT/2000/XP
with a Red Hat 7.2 Host
• Host Configuration
– NFS, bootp, tftp, firewall, $PATH, …
– $PATH: /opt/hardhat/devkit/host/bin
/opt/hardhat/devkit/arm/xscale_be/bin
3
Development Environment
4
Boot ROM
• Possible Duties
– Turn on various chip enables (so RAM
exists)
– Initialize I/O chips possibly including serial
port to report Boot ROM success/fail and a
network or disk device interface to boot the
OS
– Perform system self-test, report results
– Provide an command line interface (CLI)
– Receive S Records into RAM, and then
burn that compressed data into Flash
5
Boot ROM
• Contents
– Board- and CPU architecture-specific
initialization code
– Ability to download the operating system
image through one or more mechanisms
– Transfer control to that software
– May also assist in debugging the
application system, and running system
integrity tests
6
Boot ROM
• Booting the Target System
– Step #1: Press the target Reset button (if it
has one) or apply power to the target
– Boot ROM begins executing for the very
first time
– Step #1A: Boot ROM looks to you for help.
– Step #1B: Configure Boot ROM according
to how you want it to boot your test
software. Tell Boot ROM to remember
those settings.
7
Boot ROM
• Booting the Target System (cont’d)
– Step #2: Press target Reset or cycle the
power
– Boot ROM downloads your test software
and jumps into it
– Your test software is now running
– Repeat Step #2 as needed
8
Boot ROM
• Who, in general, creates Boot ROMs?
• Who is responsible for the Boot ROM you will
be using?
• Redboot: frequently used Xscale bootstrap
–
–
–
–
Developed by RedHat
How to get source and toolchain for Redboot
URL: http://sources.redhat.com/redboot
“Embedded Software Development with eCOS”, A. J.
Massa, Prentice Hall
9
Boot Config. & Download
• Assumptions for the Lab Equipment
– Using BOOTP and TFTP to transfer the booting
operating system from the host system disk to the
target system memory
– A portion of the host’s file system will be available
to the target operating system by an NFS mount
• The Steps
– Step B - Build the target binary (vmlinux)
– Step C - Configure the target & host network
capabilities
– Step D - Download the binary to the target
– Step E - Execute program(s) on the target
10
Boot Config. & Download
• Step B - Build the target binary (vmlinux)
– Linux uses the make utility extensively.
– Sources organized into subdirectories
– vmlinux built from archives and libraries
– If compressed, it is then called vmlinuz
– Booter and optional RAM disk are then added and
the composite is named zvmlinuz, zImage or
bzImage
– Some boards need S-Records / other formats
– Convert as needed (zsrec utility, etc...)
11
Boot Config. & Download
• Step C: Configure the host network
capabilities
– BOOTP (uses DHCP)
– TFTP Daemon
– NFS Information
– Minicom
– Refer to the MontaVista Linux Professional
Edition User’s Guide and Quick Start
Guide for your LSP
12
Boot Config. & Download
• Step D: Download the binary to the target
– Configure the target board (as previously
described)
– Configure any host daemons (as previously
described)
– Interconnect host and target
– Activate the target’s firmware to retrieve the
previously built zImage binary file and transfer
control into it
– The first part of zImage, the Linux Boot Loader,
uncompresses Linux and places it at the
appropriate memory address
13
Boot Config. & Download
• Step D: Download the binary to the target
(cont’d)
– The Linux Boot Loader also uncompresses the
RAM disk image, if present, and places it in
memory
– Finally, the Linux Boot Loader transfers control to
the uncompressed Linux image
– (vmlinux) along with a command line describing
the RAM disk image (if present)
– Linux initializes itself including the hardware
Memory Management Unit (MMU) that translates
logical (or virtual) addresses into physical (or real
addresses.)
14
Loading: Image Loader
15
Loading: Linux Boot Loader
16
Loading: Linux Startup
17
Boot Config. & Download
• Step E: Execute program(s) on the target
– Linux mounts the initial file system from RAM Disk, or NFS
Disk, or Local Disk.
– Linux, in init/main.c searches for the init first as
/sbin/init, then as /etc/init, then /bin/init and
finally /bin/sh (any of which could be a binary executable,
a shell script, or any other file that Linux knows how to
execute) and then executes it.
– Typically, it is the /sbin/init program that is executed at
this point.
– /sbin/init processes the /etc/inittab file. See man
init and man inittab for complete details on starting your
own application programs via the init process.
18
Development Tools
• Kdevelop
– Enhanced for development of remote targets by
MontaVista
– Integrated Development Environment (IDE)
– Microsoft Visual C++ -like
– Brief tutorial included in MontaVista Linux
Professional Edition, Reference Guide
– More extensive instructions are available in the
on-line help within kdevelop itself.
– Works best with C and C++
– Works with Assembler also
19
Development Tools
• GNU gcc and g++
– gcc - C Compiler
– g++ - C++ Compiler
– A family of compilers for various target CPUs
– A front-end for the build process including
preprocessor, compiler, assembler and linker
• Assembler and Linker
– as
– ld
20
Development Tools
• Binutils: a collection of binary tools
– ar - Manages object file archives
– nm - List symbols from object files
– objcopy - Copy and translate object files
– size - List text, data and bss sizes
– strip - Remove symbols
– addr2line - Convert addresses to file
and line
21
Development Tools
• make and Makefile
– Traditional Unix tool
– Almost anything you can do by hand (and then
some) can be done through a Makefile
– Lots of good books from which to learn
– Notably "Managing Projects with Make" (Pub:
O’Reilly)
22
Development Tools
• A simple Makefile example
# Makefile for ferret
CC=xsacle_be-gcc
TARGET=/opt/hardhat/devkit/arm/xscale_b
e/target
all: install
install: ferret
cp ferret $(TARGET)
ferret: ferret.c Makefile
$(CC) -D_REENTRANT -O $< -o $@ lpthread
clean:
23
- rm -f ferret.o ferret
Development Tools
• Source Debugging
– gdb (on host) with gdbserver (on target)
– Preparing the object files (compiling with -g and –
ggdb option)
• No optimization makes it easier to follow execution but
performance may change dramatically when recompiled
with full optimization
• Full optimization may lead to surprising leaps and jumps
when executing and "watching" with gdb
• Optimization is optional for user-level applications but in
the kernel it is mandatory.
24
Development Tools
• Source Debugging
– Starting the gdbserver on the target
• Receives requests from gdb on host
• Sends answers to gdb on host
• gdbserver is very small
• Symbol table and source files on host system
• Full (-g or -ggdb) contents needed only on host
• Only the executable binary is on the target
– Connecting gdb and gdbserver
– DDD: GUI front-end for gdb
25
Development Tools
• Learning more about gdb
– The GNU Web-Site, http://www.gnu.org/
– Books, see “Beginning Linux Programming”,
Richard Stones and Neil Matthew , WROX Press,
Ltd., 1-861002-97-1.
– Use the help command in gdb itself.
26
Development Tools
• Target Configuration Tool (TCT)
– The tool that customize your Kernel and file
system
– Features
•
•
•
•
•
•
Project and Configuration Management
Kernel Configure
Package Selector
Dependencies Check
The targetpkg Utility
Library Optimzation Tool (LOT)
27
Development Tools
• Linux Trace Toolkit (LTT)
– Fully-featured tracing system for the Linux kernel. It
includes both the kernel components required for
tracing and the user-level tools required to view the
traces.
– Micro-second event time-stamps
– Minimal performance overhead (< 2.5 %).
– Multi-platform support
– Friendly GUI with event graph, system and per-process
analysis, and raw event descriptions.
28
Development Tools
• Linux Trace Toolkit (LTT) Usage Steps
– Enable Linux "Kernel Tracing" configuration
– Create the tracer device entry in target's /dev if
they are not available in your file system.
– Start the trace daemon in target:
tracedaemon -ts10 /dev/tracer ./out.trace ./out.proc
– Run "tracevisualizer" in host and load the above
out.trace and out.proc files
29
Development Tools
• Kernel GDB (KGDB)
– Source debugging of the Kernel
– Requirements:
• Enabling the CONFIG_KGDB entry in the Kernel Hacking
section
• Recompile with -ggdb
• Enable frame pointers
• Connect serial port
• Download and boot target
• Launch DDD and gdb to use the serial port
• Upon connection, set breakpoints and go
– Kernel Modules Debugging
30
File Systems
• File Systems Supported (partial list)
–
–
–
–
–
–
EXT2/3
ReiserFS
XFS
CramFS
JFFS/JFFS2
Network File System (NFS)
31
File Systems
• How Do I Enable a Local Root File System?
• A practice: Use ramdisk as root file system
– Kernel configuration:
• Edit kernel bootup command line option: “root=/dev/ram”
• Block devices: enable RAMDISK support, init ramdisk
support, default ramdisk size 4096kB
• File Systems: Disable network file system as root option
• Networking Options: Disable IP auto configuration in bootp
32
File Systems
• Use ramdisk as root file system (cont’d):
– Use TCT to generate my root file system,
convert to ext2 format and compress it.
– Download to the target and run
<Redboot> load –r –v –b 0xnnnnnnnn <ramdisk>
<Redboot> load –r –v –b 0xuuuuuuuu <kernel>
<Redboot> go 0xuuuuuuuu
33
File Systems
• Use ramdisk as root file system (cont’d):
#
#
#
#
#
#
#
#
#
#
#
rm -rf /tmp/tmpmnt
mkdir /tmp/tmpmnt
rm -rf /tmp/ramrootfs
dd if=/dev/zero of=/tmp/ramrootfs bs=1k count=10240
mke2fs -F -m 0 -i 2000 /tmp/ramrootfs
mount -o loop -t ext2 /tmp/ramrootfs /tmp/tmpmnt
cd /tmp/tmpmnt
cp -av /my_workdir/my_filesystem/pxa250/fs1/* .
cd /tmp
umount /tmp/tmpmnt
cat /tmp/ramrootfs | gzip -9 > /tftpboot/pxa250.ram
34
File Systems
• Use JFFS/JFFS2 as root file system
– You have to use
/opt/hardhat/devkit/arm/xscale_be/target/sbin/mkfs
.jffs2 to make your jffs2 file system.
– The mkfs.jffs2 needs /usr/lib/libz.so.1 ;
/lib/libc.so.6 ; /lib/ld-linux.so.2
– Bootup your target with root=nfs or /dev/ram which
contains the above binaries and your target file
system directory.
– Run /usr/sbin/mkfs.jffs2 -d <target dir> -o my.jffs2
35
File Systems
• Use JFFS/JFFS2 as root file system (cont’d)
– Rebuild the kernel with
"root=/dev/mtdblock? rw ip=off"
– Use Redboot commands to download the
my.jffs2 and the new kernel
– Reboot the system with the new kernel and
jffs2 file system.
36
Kernel Modules
• An object file (e.g., myfile.o) that is
dynamically loaded and added to the kernel
at run-time
• Often used to add/remove optional items
to/from the system such as device drivers
• Useful when kernel footprint or alternative
drivers is an issue
• May also be used with proprietary code to
avoid licensing issues in GPL
37
Kernel Modules
• Often have a custom /proc interface built-in
to the module
– Written by the kernel module programmer
– Can be written to provide both a read and a
write interface
– Typically used initially to assist in kernel module
debugging
– But the long-term use is typically to help the
system administrator either by providing
information about system configuration and
operation, and allowing parameters in the kernel
module to be modified as may be needed by the
administrator
38
Kernel Modules
• Loading and Unloading Modules
–
–
–
–
–
insmod - Install (load) a module
rmmod - Remove (unload) a module
lsmod - List installed modules
depmod - Show dependencies of a module
modprobe - Loads a module and its
dependencies
– modinfo - Displays information about a module
• Start-Up
– insmod may be used in /etc/init.d/* and
/etc/rc*.d/*
39
Kernel Modules
• A Simple Kernel Module
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
static int __init my_init_module(void){
printk("<1> Yup, I’m here!\n"); /* Logged to
/dev/console */
return 0;
}
static void __exit my_cleanup_module(void)
{
printk("<1> And now I’m leaving.\n"); /* Logged to
/dev/console */
}
module_init(my_init_module);
module_exit(my_cleanup_module);
40
Kernel Modules
• Kernel Module Compiling
– Kernel modules need to be built using the kernel
headers rather than the user-space headers
– <architecture-prefix>-gcc -D__KERNEL__ -Wall O2 -I <path-to-kernel>/include -I <path-tokernel>/arch/<architecture> -DMODULE -c
mymod.c
– When more than one '-I' option is used, the
directories are scanned in left-to-right order.
These directories are searched before the
standard system directories.
41
Kernel Modules
• Compiling with version information is only necessary
when compiling a module for a kernel that has
"CONFIG_MODVERSIONS" enabled.
• Version mismatch:
# insmod mymod.o
mod1.o: kernel-module version mismatch
mod1.o was compiled for kernel version 2.4.17_mvl21
while this kernel is version 2.4.17_mvl21-cllf.
• Solutions:
– Insmod –f
– recompile the module with "version information" in the kernel
42
Kernel Modules
• How do I compile a module with "version
information" in the kernel?
– <architecture-prefix>-gcc -D__KERNEL__ Wall -O2 -I<path-to-kernel>/include -I
<path-to-kernel>/arch/<architecture> DMODULE -DMODVERSIONS -include
<path-to-kernel>/include/linux/version.h -c
mymod.c
43
Kernel Modules
• depmod - Module Dependencies Database
– Creates a database of module dependencies
– Scans modules in /lib/modules
– Generates /lib/modules/*/modules.dep
• * will be replaced by the kernel version and build number
– Update when adding new modules to the system
that should be automatically inserted
– Modules that will be loaded manually do not need
to be in the database
44
Kernel Modules
• depmod Example
# insmod lp
./lp.o: unresolved symbol
parport_register_device_R9b846d61
./lp.o: unresolved symbol
parport_release_R93e35225
./lp.o: unresolved symbol
parport_claim_or_block_Rca62ba8c
./lp.o: unresolved symbol
parport_unregister_device_Re6842bfb
./lp.o: unresolved symbol
parport_enumerate_R6a5c148b
# depmod -a
/lib/modules/2.2.12-20b/modules.dep
45
Kernel Modules
• modprobe - Load Module and its
Dependencies
–
–
–
–
–
May be used instead of insmod
Check dependency database
Loads dependent modules in the correct order
Checks /etc/conf.modules for parameters
Can pass additional parameters
46
Kernel Modules
• Passing Values to the Module
– modprobe parport_pc.o demo=1
– This works with insmod also
– In the module’s source
/* parport_pc.c */
#ifdef MODULE
static int demo = 0;
MODULE_PARM(demo, "i");
MODULE_PARM_DESC(demo, "Demo variable,
defaults to 0");
#endif
47
Kernel Modules
• Add Module via Linux Configuration Process
– Used when a kernel module must be built
at the same time as the kernel; Not
required for simple testing of the kernel
module
– Steps
• First: Add a selection to the kernel configuration
• Second: Add the object module to kernel
Makefile
• Third: Configure and Build the Linux kernel
48
Kernel Modules
• Add Module via Linux Configuration Process
– Step #1: Add a selection to the configuration
• Locate the appropriate [Cc]onfig.in file
• Add the appropriate lines for your module
– To allow "y", "m" or "n" selection:
– tristate ’User-readable description goes here’
CONFIG_YOURSYMBOL
• Refer to Documentation/Configure.help
and Documentation/kbuild/configlanguage.txt
49
Kernel Modules
• Add Module via Linux Configuration Process
– Step #2: Add the object module to Makefile
• Determine appropriate <path-to-kernel>/
drivers/*/Makefile
• Add command to include your module
• obj-$(CONFIG_YOURSYMBOL) +=
yourfilename.o
• Copy source files to same directory
• If necessary, add compile options, etc. to
Makefile
50
Kernel Modules
• Add Module via Linux Configuration Process
– Step #3: Build the linux kernel
• make config OR make menuconfig OR make xconfig
OR make oldconfig
• make dep OR make depend
• make bzImage OR make zImage
• make modules
• make
INSTALL_MOD_PATH=/opt/hardhat/devkit/mips/fp_le/
target/lib/modules install_modules
• the modules should end up in the target’s
/lib/modules directory.
51
Kernel Modules
• Kernel Modules Source Level Debugging
– Instructs insmod to generate a load map for the
module when it gets loaded into memory.
• [target linux] insmod –m module.o > module.map
• [target linux] grep “.text” module.map
• [gdb] add-symbol-file module.o XXXXXXXX
XXXXXXXX = address of ‘.text’ section from grep
command.
– precludes the ability to debug the module’s
‘init’method.
52
MontaVista Realtime
• MontaVista provides following improvements for
real-time performance of the Linux kernel :
– MontaVista Real-Time Scheduler
• To meet real-time performance requirements while preserving
the standard Linux programming model and APIs.
• All that necessary is to use the standard Linux real-time
priority options provided within its POSIX function calls.
– Preemptible Kernel
• Reduces the latency of the kernel when reacting to real-time or
interactive events by allowing a low-priority process to be
preempted, even if it is in kernel mode executing a system call.
• This feature allows applications that need real-time response –
such as audio and other multimedia applications – to run more
reliably, even when the system is under an increased load due
to other lower-priority processes.
53
MontaVista Realtime
– In the following instances, preemption should
not occur, and the Preemptible Kernel does not
allow it:
•
•
•
•
•
while handling interrupts
while doing “bottom half” processing
while holding a spinlock, writelock, or readlock
while the kernel is executing the scheduler itself
At all other times, the MontaVista algorithm allows
preemption. Also, whenever the system exits from
one of the above states, it tests to see if preemption
is called for. If so, the current task is preempted.
54
MontaVista Realtime
•
Enabling the MontaVista Real-Time
Scheduler
–
–
–
–
Start make menuconfig or make xconfig,
enable Real Time Scheduler.
Enter a value for the Maximum Priority
option.
Save your changes.
Rebuild the kernel
55
MontaVista Realtime
• To enable the MontaVista Preemptible
Kernel, complete the following steps:
1.Start make menuconfig or make xconfig
2.Select “General setup”
3.Enable “Preemptible kernel support”
4.Enable “Break selected locks”
5.Rebuild the kernel
56
MontaVista Realtime
• Pthread Programming
– The ‘P’ is for POSIX, Portable Operating
System Interface
– IEEE Standard
– Section 1003.1c defines Pthreads
57
MontaVista Realtime
• Threads, An Alternative View
– Some engineers prefer to view things differently in
Linux. Even though Linux is a process-based
operating system, they choose to view a process
as a container.
– In this view, the process does not execute code. It
simply provides the space and other properties in
which threads may execute.
– When a process is created (via fork) in this view,
one thread of execution is automatically started.
58
MontaVista Realtime
• Threads, An Alternative View (cont’d)
– That initial thread begins at the place we call main.
It could then create additional threads within the
same process.
– When any thread wishes to terminate, it calls
pthread_exit. That one thread is then
terminated.
– If any one thread wishes to terminate the entire
process (and all threads within it), that thread may
call exit.
– Finally, if all threads, one by one, call
pthread_exit, when the last thread is gone,
Linux will remove the process.
59
MontaVista Realtime
• POSIX Thread Execution Priorities
– The greater the numerical priority value, the more
important the thread.
– POSIX recommends at least 99 priorities above
zero (MontaVista supports range: 99~2047)
– root priviledge is required to use the elevated
priority numbers (1-99).
– SCHED_FIFO or SCHED_RR must be used at
elevated priority numbers.
– SCHED_OTHER ("fairness") is not permitted at
elevated priorities.
60
MontaVista Realtime
• POSIX Policies
– SCHED_FIFO
•
•
•
•
Processes (threads) run “First In First Out”
use the elevated priority numbers
Most commonly used "real-time" scheme
Used when process(es) are known to use
relatively brief "bursts" of CPU time
• Permits the highest priority process (thread) to
run "at will"
• Starvation of lower priorities can occur
61
MontaVista Realtime
• POSIX Policies
– SCHED_RR (Round Robin)
• SCHED_RR is SCHED_FIFO with "quanta"
• A "Quanta" is a period of time after which the process
(thread) is moved behind others of the same priority
• May be used when the process(es) are known to have
long periods of intensive execution and more than one
process uses this priority
• Also use the elevated priority numbers
• Processes run until they say they want to wait, or until
their quanta is exhausted
62
MontaVista Realtime
• POSIX Policies
– SCHED_OTHER
• In Linux, it is implemented as the normal
scheduling policy (let’s be fair and let everyone
run)
• Only available at POSIX priority zero
• Lower priority than SCHED_FIFO and
SCHED_RR
63
MontaVista Realtime
• Choosing Priorities for SCHED_FIFO,
SCHED_RR & SCHED_OTHER
– High priorities (99--)
•
•
•
•
I/O intensive (reactive)
Critical (time-sensitive) operations
High repetition rate
NOTE: Processes MUST wait -- busy spins are
bad
64
MontaVista Realtime
• Choosing Priorities for SCHED_FIFO, SCHED_RR &
SCHED_OTHER
– Low priorities (1++)
• Less vital (less catastrophic if not done) activities
• CPU intensive operations
• Consider SCHED_RR
– Priority zero
•
•
•
•
•
Must use SCHED_OTHER
Non-realtime activities
Batch operations (compiling, etc...)
Time-consuming computations
Human interface
65
MontaVista Realtime
• Pthread Coding Requirements
– Include files
• unistd.h
• pthread.h
• semaphore.h
– Compiler flags: -D_REENTRANT
• Required for some architectures
• Ignored when unnecessary
66
MontaVista Realtime
• Pthread Functions Briefly
– pthread_create - Create a new thread
– pthread_exit - "Me" exit
– pthread_join - Wait for a given thread
to pthread_exit
– pthread_cancel - Attempt to terminate
a thread
– pthread_self - Who am I?
– pthread_detach - Save no resources if
I pthread_exit later (can’t be joined)
67
MontaVista Realtime
• Pthread Attribute Preparation
int
pthread_attr_init(pthread_attr_t
*attr);
– Setup pthread attribute object
– Usually defaulted at pthread_create
– Can be changed as thread runs
• sched_setscheduler()
• sched_setparam()
68
MontaVista Realtime
• Making Yourself Realtime
#include <sched.h>
struct sched_param sched_params;
/* Change our priority to as high as
possible and use SCHED_FIFO */
sched_params.sched_priority =
sched_get_priority_max(SCHED_FIFO);
if (0 != sched_setscheduler(getpid(),
SCHED_FIFO, &sched_params)) {
printf("sched_setscheduler failed (YOU
MUST BE ROOT TO USE THIS)\n");
exit(1);
}
69
MontaVista Realtime
• Study more:
– Posix.4: Programming for the RealWorld, Bill O.
Gallmeister, O’Reilly & Associates, 1-56592-074-0.
– Pthreads Programming, Bradford Nichols, Dick
Buttlar, and Jacqueline Proulx Farrell, O’Reilly &
Associates, Inc., 1-56592-115-1.
70
Notes
•
•
•
•
•
•
•
•
•
/opt/hardhat/devkit/arm/xscale_le/target
/etc/bootptab, /etc/xinetd.d/bootps
/etc/exports
/etc/xinetd.d/tftp
/etc/dhcpd.conf
/etc/init.d/nfs restart
/etc/redhat-release
/mnt/cdrom/bin/hhl-host-install
Redboot> fis create ; fis delete ; fis list
71