简单介绍我在学校的项目的技术 (based on arm7)
时间:2009-05-01 来源:anabelle
Implement Embedded Linux on PDA
1. Introduction
Familiar Linux is presently available for the Compaq iPaq. Since the architecture of iPaq is quite different to the normal desktop computer, we have to develop new application program for this Linux embedded system.
2. Overview
During the development of embedded Linux on PDA, the source code is written and modified in the Linux on desktop. And the source code is compiled by the cross compiler for Arm Linux. It is a compiler used to compile a source code for arm target platform.
The Familiar Project is composed of a group of loosely knit developers all contributing to creating the next generation of PDA OS. Currently, most of our development time is being put towards producing a stable, and full featured Linux distribution for the Compaq iPAQ h3600-series of handheld computers, as well as apps to run on top of the distribution. The hardware and software requirements are listed as following:
2.1. Hardware Requirement:
1. Compaq H3600 iPAQ
2. Serial cable
3. Serial cradle
2.2. OS/Software Requirement:
1. Red Hat Linux 7.3
2. Cross compiler for ARM used in Redhat Linux
3. GCC
4. Root Image – Familiar v.0.5.2 task-bootstrp.jffs2)
5. A terminal emulator capable of performing xmodem uploads – Hyperterminal
6. ActiveSync Software (on host pc)
7. Bootloader – ARM Bootldr 2.18.01
8. Some applications for PDA – qpe application
As we use Compaq iPAQ h3600 as the hardwire, and it is in the series of Compaq iPAQ of handheld computers, so Familiar Linux is surely an ideal OS platform that we place our target on.
Currently Familiar's Linux distribution supports some of the following key features:
- Entirely based on XFree86's/keithp's Tiny-X server.
- OpenSSH's ssh.
- JFFS2 supported, which enables the read/write access to the Flash.
- Binary and Library distribution compatible the ARM target.
- a good wealth of peripherals and GUI applications .
- Full package support based on ipkg.
The current software release versions are:
- Familiar Project Linux v0.5.1 for the IPAQ H3600.
For free download, please visit: http://familiar.handhelds.org/
3. Implementation Details
3.1. Setup target environment
The primary work is to install Familiar Linux v.0.5.2 on iPAQ H3600 [1, 2]. The main tasks in this procedure are backup wince, install boot-loader and install root image. Finally we can boot PDA with embed Linux successfully. In the part, the only dangerous step is to fresh the boot loader. So you should be care of this. The detailed steps are as follows:
Backup WinCE
- Connect your iPAQ via the USB or serial cradle or cable.
- If using a serial cradle or cable, then configure your iPAQ to use the serial port for ActiveSync.
· Select settings from the Start Menu (the Microsoft flag icon)
· Click the Connections tab, and then double-click the PC icon.
· Ensure the automatically synchronize when serial cable is connected using is checked.
· Change USB to 115200 baud defaultly.
· Click OK (top right of the screen).
- Use the ActiveSync application to connect to your iPaq 3600 from your PC. If there is not an ActiveSync icon in the tool tray, then use the Start->Program->ActiveSync menu item to start it.
- Copy BootBlaster_1.18.exe to the default folder on your iPaq from your Windows machine using drag and drop or cut and paste. You may safely ignore any messages that say it "may need to convert" file formats.
- Copy bootldr-2.18.01.bin to the default folder on your iPaq from your Windows machine. Again, You may safely ignore any messages that say it "may need to convert" file formats.
- On your iPaq H3600, find BootBlaster_1.18.exe wherever you put it, and then execute BootBlaster_1.18.
7. Root Image – Familiar v.0.5.2 task-bootstrp.jffs2)
- From the "Flash" menu, select "Save". This will save a copy of your current bootloader to DRAM on the iPAQ (under the name "saved_bootldr.bin").
- Copy the "saved_bootldr.bin" off of your iPAQ and put it in a safe place in case you wish to restore it later.
- From the "Flash menu, select Save Windows gz This will copy and compress all the flash on your ipaq into a .gz file. This will take a while. After it is complete, copy this file to your PC to save it.
Note: Please be patient! This will take several minutes.
- From the "Flash" menu on BootBlaster, select "Program". A file dialog will open allowing you to select the bootloader to use. Select the bootloader from step #5.
- Wait patiently. On my iPAQ, it takes about 15 seconds to program the bootloader. During this time, the iPAQ just sits there.If it sits for more than 15 seconds with no activity, then reboot the iPAQ by pushing the recessed reset button at the bottom right and repeat this step.
Check the Install
- After “flash”, it will auto-verified. If not, do it manually. From the "Flash" menu on BootBlaster, select "Verify". If it does not say that you have a valid bootloader, do NOT reset your iPAQ, try programming the flash again. If that doesn't work, program your flash with your saved bootloader. (Be careful! This is the only risk!)
- When the iPAQ is reset, by default, it will boot Windows CE.
- Reboot your iPaq H3600 by pushing the recessed reset button at the lower right of the unit while holding the center of the joypad.
- Set up Hyperterminal first
· 115200 baud
· no flow control
then put the iPAQ back in the cradle. At this point, either type a space in the terminal emulator or push the calendar button on the iPAQ to get the bootldr's prompt "boot>".
Before proceeding to Linux installation, unlock flash with this command: pflash 0x40000 0xffff 0 by typing it at the boot prompt.
The bootldr will automatically protect itself upon boot if the bootldr sector is not locked, however you may do so manually with the command: pflash 0x0 0x3ffff1.
Performing Boot-loader Configuration [5]
- setup flash partitions.
· At the "boot>" prompt, enter: partition reset
Here's an example of prompt display:
boot> partition reset
argv[1]=reset
defining partiton: bootldr
defining partiton: root
boot>
|
Flashing the Filesystem
- At the "boot>" prompt, issue the following command: load root
- Proceed to send the proper fileimage-bootstrape[here] via xmodem, using Hyperterminal. Then bootloader successfully erased, wrote, and verified the filesystem image.
Boot the Installlation for the First Time
- At the "boot>" prompt, type: boot
- Familiar Linux start, and you need login in as root using rootme as the password.
3.2. Setup Host Environment
This section contains information on setting up a GNU toolchain For ARM targets. It details in both some pre-compiled toolchain which you can install, and how to compile your own toolchain.
3.2.1. Install pre-built toolchain
3.2.1.1. Download tool-chain
The toolchain actually consists of a number of components. The necessary crosscompiler tools (arm targets) for a development environment are:
· arm-linux-gcc-*.rpm (The compiler itself gcc)
· arm-linux-binutils-*.rpm (A set of tools for manipulating binaries)
· arm-linux-glibc-*.rpm (C-library glibc)
· arm-linux-kernel-*.rpm (Kernel source code of ARM Linux)
The most convenient approach to install cross-compiler tool-chain is to use rpm. The download URL is ftp://ftp.netwinder.org/users/c/chagas/arm-linux-cross/RPMS/ . The packages are suitable for Linux version 2.4.
If this link is not available, please try this: http://www.arm.linux.org.uk (CVS supported)
3.2.1.2. Install the tool-chain
If there is rpm package, please use the four commands to install:
rpm -ivh arm*-binutils*.rpm
rpm –ivh arm*-gcc*.rpm
rpm -ivharm*-glibc*.rpm
rpm –ivh arm*-kernel*.rpm
Install it once with:
rpm -ivh arm*-binutils*.rpm arm*-gcc*.rpm arm*-glibc*.rpm arm*-kernel*.rpm
But sometime version conflicts happened. Thus to install it one by one could be safer. The installation path of arm-linux toolchain is /usr/local/arm-linux.
3.2.1.3. Setup environment variables
In order to make the toolchain work, please set a couple of variables:
PATH=/usr/local/arm-linux/bin:$PATH
LD_LIBRARY_PATH=/usr/local/arm-linux/lib:$LD_LIBRARY_PATH
CC=arm-linux-gcc
CXX=arm-linux-g++
PREPROCESSCMD="$CC -E"
LD=arm-linux-ld
PS1="[arm-linux] $PS1"
3.2.2. Cross compile C-program
This sub-section shows how to build C program for ipaq using the cross compiler.
1. For a sample hello.c , we'll make a new directory “hello” and do the following.
mkdir ~/hello
cp hello.c ~/hello
cd ~/hello-world
To build, call the compiler, with the right options, with the command
arm-linux-gcc -Wall -g -o hello hello.c
2. For a complete set of source code, In the Makefile, add some lines:
CC=arm-linux-gcc; LD=arm-linux-ld
An alternative approach is to issue a command like:
Make CC=arm-linux-gcc LD=arm-linux-ld all
This subsection introduces how to compile your toolchain. This is useful when the pre-built package isn’t available.
Build binutils ...
Download the binutils-2.10.tar.gz
# tar zxvf binutils-2.10.tar.gz
# cd binutils-2.10
# mkdir build
# cd build
# ../configure --target=arm-elf --prefix=/usr/local/gnu
# make
# make install [Note: write access to /usr/local/gnu is required]
Build gcc ...
Download the gcc-2.95.3.tar.gz
# tar zxvf gcc-2.95.3.tar.gz
Apply patch from Philip Blundell to change the Position Independent Code generation for ARM:
# gzip -cd gcc-2.95.3-arm-pic.patch.gz | patch -p0
# cd gcc-2.95.3
# mkdir build
# cd build
# ../configure --target=arm-elf --prefix=/usr/local/gnu --disable-threads
# make LANGUAGES="c" [Note: be sure /usr/local/gnu/bin is in the PATH list]
Continue installing the C compiler:
# cd gcc
# make install
Build libc ...
Download the newlib.tar.gz
# tar zxvf newlib.tar.gz
# cd newlib-1.8.1
# mkdir build
# cd build
# ../configure --target=arm-elf --prefix=/usr/local/gnu
--enable-target-optspace
# make
# make install
Build other languages supports in gcc ...
# cd gcc-2.95.3/build
# ../configure --target=arm-elf --prefix=/usr/local/gnu
# make LANGUAGES="c c++"
# make install
3.3. Compiling the ARM kernel on your desktop
If a development on the extension & modification of ARM-Linux kernel will be taken care of later, the experiment of compiling ARM-Linux kernel should be done now. This section describes how to do that.
3.3.1. Requirements
Grab the kernel-sources from handhelds.org. You find them e.g. under ftp://lorien.handhelds.org/pub/linux/feeds/demo/.
Copy the tarball into /usr/kernel and extract it using tar xvfz somekernel.tar.gz.
Set a link /usr/local/linux-arm-kernel to the kernel using "ln -s /usr/kernel/somekernel.x.y.z/kernel /usr/local/linux-arm-kernel".
3.3.2. Using the CVS repository of handhelds.org
To get the newest (or an older) version of the kernel sources, you may use the anonymous CVS access. This sub-section describes how to get the sources for kernel 2.4.16-rmk1-hh15 (familiar 0.5.2).
- Create a directory, where the kernel sources should be stored. You will need approx 150 MByte of disk space.
- Enter this dir and export the CVSROOT variable typing
export CVSROOT=:pserver:[email protected]:/cvs - login the server typing
cvs login. Enter the required password anoncvs. You should be looged in. - If you have already the kernel repository available (did already a download) before, use the next step to go on.
cvs co linux/kernel will prepare your linux/kernel repository. - Now you can checkout your kernelversion.
cvs co -r K2-4-16-rmk1-hh15 linux/kernel grab the sources from the kernel repository.
3.3.3. Compilation and installation of the kernel
Become superuser, enter the subdir linux/kernel and type
#cp arch/arm/def-configs/h3600 .config
#make oldconfig
to get the config done for the h3600 ipaq.
Type qtarm to get all necessary environment variables set. Qtarm script file must includes such information:
#!/bin/bash
# qtarm
# script file to set up Cross-compiler (arm-linux-cc)
# -------------
# Compiler-Path is where your Cross-compiler is located
COMPILER_PATH=/usr/local/arm-linux
# Kernel-Path where your ARM-Kernel is located
KERNEL_PATH=/usr/local/linux-arm-kernel
# LD_LIBRARY_PATH has to be added by COMPILER_PATH lib dirs.
LD_LIBRARY_PATH=$QTDIR/lib:$COMPILER_PATH/lib:$LD_LIBRARY_PATH
# Installation PATHs .....
# Install-PATHs are used to define the installation PATH
# for self created libs (used for qt/emb/arm)
LIB_INST_PATH=/usr/local/lib
INC_INST_PATH=/usr/local/include
export LIB_INST_PATH INC_INST_PATH
# -------------------------------------------------
# Programs .....
# some Makefiles use the follwing Environment variables
# to find the right compiler / linker
CC=arm-linux-gcc
CXX=arm-linux-g++
CCX=arm-linux-gcc
CXXX=arm-linux-g++
COMPILER=arm-linux-gcc
LINKER=arm-linux-g++
# the strip-program (strips down the size of the binary
# deleting all debug-information)
STRIP_PROG=$COMPILER_PATH/bin/arm-linux-strip
# some Makefiles use the follwing Environment variable
# to define a preprocessor
PREPROCESSCMD="$COMPILER -E"
export STRIP_PROG COMPILER LINKER PREPROCESSCMD CC CXX CCX CXXX
Type #make dep clean bzImage modules and drink some coffee (it may take half an hour).
Enter make modules_install (they are standardwise are installed into /lib/modules/kernelversion). If you dont want that, you can set $INSTALL_MOD_PATH as a prefix.
After the kernel is ready, and the link is remade, the kernel can be found in /usr/local/linux-arm-kernel/arch/arm/boot. The file bzImage is a new kernel binary.
3.4. Build Your Image
3.4.1. Creating jffs2 Image
Refer to The Familiar Project for procedures on installing linux onto your IPAQ. The best approach to create a jffs2 image is to download an old version filesystem and modify it to what you want. Below is a jffs2 image of the filesystem, as well as a tarball of the fs tree. (* refers to the version).
kernel image (zImage-*)
root image (task-boostrap-*.jffs2)
root tarball (task-boostrap-*.tar.gz)
After you prepare a full set of filesystem, make the image by:
#mkfs.jffs2 -r root -o root.jffs2 -e erasesize -p
root: the directory containing the files to go in the image.
root.jffs2: the name of the filesystem image.
erasesize: the sectorsize of flash on the target machine.
erasesize is 0x40000 for H3600
Erase the whole block to contain the filesystem, then load the constructed .jffs2 image in the beginning of the block device. As of bootldr 2.14.5, it automatically erases the whole partition if 16 (bit 4) is one of the flags set in the partition definition.
You can obtain mkfs.jffs2 from ftp://ftp.uk.linux.org/pub/people/dwmw2/iPAQ/mkfs.jffs2
3.4.2. Build ipkg of C-program for Compaq IPAQ
IPAQ is a good tool to build the C-program for IPAQ. The steps of compile are shown next.
1) Copy the ‘ipaq-build’ into /usr/loacal/sbin
2) Create the directory “hello”, which should have two sub-directories-“CONTROL” & “destination directory” . a subdirectory “destination directory” is the destination directory on IPAQ.
/hello/CONTROL
/hello/usr/bin (*only for reference, modify it to your own directory)
3) In “CONTROL”, a file named "control" is created. The sample file (attached in the zip file) is:
###Begin: CONTROL/control for ipaqrs
Package: ipaqrs
Priority: optional
Version: 1.0
Date: July, 12th, 2002
Architecture: arm
Maintainer: Familiar User
Depends:
Description: serial-comm program
###End: CONTROL/control for ipaqrs
4) Copy the binary files into “/hello/usr/bin”.
5) Issue the command : ipkg-build directory [destination directory]
3.5. Install Application
3.5.1. Usage of ipkg
Given the assumption that IPAQ is installed with Linux. The application can be transferred from desktop PC to IPAQ via xmodem, using Hyperterminal on windows (minicom on Linux). More details is in appendix A.
1) Send hello_*.ipk to /tmp (on ipaq)via zmodom, using hyperterminal.
2) Install the ipk by entering “ipkg install /tmp/hello_*.ipk”.
3) The file is installed under the directory /usr/bin
Usage of ipkg:
install <file.ipk>: Install package <file.ipk>
remove <pkg>: Remove package <pkg>
list List available packages and descriptions
files <pkg> List all files belonging to <pkg>
search <file> Search for a packaging providing <file>
info [<pkg>] [<field>] Display all/some info fields for <pkg> or all
status [pkg] [<field>] Display all/some status fields for <pkg> or all
depends <pkg> Print uninstalled package dependencies for <pkg>
3.5.2. Installing ipkg on IPAQ
Install application [here] via xmodem
- Send Qtopia_*.ipk to /tmp (on ipaq)via zmodom, using hyperterminal.
- Install the ipk by entering “ipkg install /tmp/Qtopia_*.ipk”.
Continue installing the following ipkg:
- h3600-utils, apm
- qt-embedded, qpe-taskbar, qpe-base, qpe-sounds, qpe-pics
At the "boot>" prompt, type: reboot
After the system reboot with the newly install package, a qpe GUI interface is built. Install other Qtopia packages:
Qpe-filebrowser, qpe-handwriting, qpe-keyboard, qpe-qipkg, ape-embeddedkonsole, qpe-systemtime, qpe-textedit, ipaqrs_2.0_arm.ipk……
3.5.3. Install applications without iPKG
1. Connect IPAQ to desktop with serial cable
2. Send executable file to IPAQ (/tmp) via zmodom, using hyperterminal/minicom.
· Open hyperterminal, choose zmodom transfer, choose target file from the browser.
· Waiting, this is very fast.
3. Copy .o file to /usr/bin.
4. Online Resources:
1. Compaq iPaq Project: http://www.handhelds.org/
2. ARM Linux Project: http://www.arm.uk.linux.org/~rmk/
3. Download toolchain: http://handhelds.org/download/toolchain/
References
[1]. Tools-Chain How-to, http://www.aleph1.co.uk/armlinux/docs/toolchain/toolchHOWTO.pdf
[2]. How to build ipkg package, http://www.handhelds.org/z/wiki/BuildingIpkgs
[3] How to create a custom jffs2 image for the iPAQ, http://internet2.motlabs.com/ipaq/howto/custom_jffs2_ipaq.htm
[4] How to install bootldr, http://www.handhelds.org/feeds/bootldr/install.html
[5] How to install familiar Linux, http://familiar.handhelds.org/familiar/releases/latest/install/H3600/install.html