Getting Started with Linux on iPAQ

In this section, I will give an overview of how to get started running Linux on the iPAQ, including what devices and peripherals are needed. I will describe options on several ways to run Linux on the iPAQ, including dual booting with PocketPC.

After describing the different configurations for running Linux on the iPAQ, I will describe some of the prerequisites for installing Linux, and then I will describe several ways to install Linux, depending on the peripherals and communication paths available for your iPAQ.

If, as in the PC world, we could depend on every iPAQ having a CD-ROM drive, this would be much simpler.

Linux Configurations on the iPAQ

There are several ways you can run Linux on the iPAQ.

Native Install

You can replace PocketPC in flash ROM with a Linux installation. This method also requires installing the Compaq bootldr, which is firmware that can boot PocketPC or Linux from flash ROM. Actually, it can also boot QNX, Savaje's J2SE, Plan 9 and NetBSD.

Here are the basic steps for a native Linux installation on the iPAQ:

  • Use ActiveSync or network to copy bootldr and BootBlaster to the iPAQ under PocketPC

  • Use BootBlaster install bootldr

  • Install task-bootstrap via serial port or from CF card

  • Boot linux

  • Use network to install rest of packages.

Linux on CF

Using the Compaq bootldr, it is also possible to boot Linux from a CF card such as an IBM microdrive while having PocketPC or another copy of Linux installed in the internal flash.

It is also possible to boot directly from PocketPC using CyaCE, although I will not discuss it further at this time because of my complete lack of experience with this method.

Here are the basic steps for booting Linux from CF Card:

  • Use ActiveSync or network to copy bootldr linux.zip to the ipaq's CF card.

  • Unzip linux.zip

  • Run BootBlaster from CF to install bootldr.

  • Push reset button, holding center of joypad.

  • As directed by the bootldr splash screen, push the Q button (the second button from right) to boot Linux from vfat.

Dual Booting with PocketPC

Dual booting PocketPC is still a bit troublesome, because PocketPC keeps most user files in DRAM. When Linux is booted, it uses all of DRAM, overwriting any user data that PocketPC had there. We have a scheme in mind where DRAM could automatically be copied to disk before booting Linux and restored from disk before rebooting PocketPC, but it is currently unimplemented. It might also be possible to partition DRAM so that Linux did not touch PocketPC user data, but we do not know enough about how PocketPC uses DRAM to know whether or not this is feasible.

Memory and Filesystems

It's probably time for a little discussion of the types of memory and filesystems that can be used on your iPAQ and attached devices.

The iPAQ and other handhelds come with two types of built-in memory: DRAM and Flash. DRAM is volatile memory in that the contents of DRAM fade away if power fails. Flash is nonvolatile storage with constrained updates.

Nor Flash, Nand Flash

There are two kinds of Flash chips available: Nand and Nor. Nand Flash memory cells are physically smaller than Nor Flash cells, but they cannot be organized with a large fast read interface, hence they tend not to be used for system memory. Nor cells, on the contrary, can be organized as a suitable replacement for mask ROM.

Nand and Nor flash share a number of characteristics. In Flash memory, a word must be erased before it can be programmed. In both types of Flash, the storage array is organized into erase blocks. All words of an erase block must be erased simultaneously. Sectors tend to be fairly large: 256KB on the iPAQ. Each erase block can only be erased about 100000 times before the sector fails.

These characteristics of FLash mean that Flash is not a direct replacement for DRAM. Trying to use it like DRAM would result in very low performance and early failure of the Flash memory. Flash is quite useful, however, for file repositories. It has similar performance characteristics to disk, on average. With suitable wear leveling, the lifetime of the Flash sectors is likely to match the lifetime of the device.

A standard filesystem such as VFAT or the Linux Ext2/Ext3 filesystem can be used over Flash if a block remapping layer is used. For the root filesystem on the iPAQ, we have been using a filesystem designed expressly with the characteristics of Flash in mind: Journaling Flash Filesystem Version Two (JFFS2). JFFS2 is a log-structured filesystem. That is, all the data and meta data is written sequentially to a journal in Flash. The complete filesystem directory structure is maintained in DRAM. It is reconstituted from the journal when the filesystem is mounted.

CompactFlash

CompactFlash (CF) is a bit of a misnomer -- it is just a compact form of the PCMCIA PC Card standard. Many CF cards do contain NAND flash chips, all of these cards present an IDE interface rather than a bare Flash memory interface.

The controller in a CF card implements an algorithm that maps logical disk block numbers to physical flash blocks. This mapping process also compensates for bad blocks in the Flash chips. This controller also performs wear leveling; it will try to spread the erase and write operations evenly across all sectors of flash in the card.

Because CF cards provide a block remapping layer that hides the raw Flash interface, it is OK to use these cards with a filesystem such as VFAT or Ext2, but it is still not recommended. Some degree of journaling is preferred so that dead batteries or card removal do not cause the filesystem to be left in an inconsistent state due to incomplete or out of order writes. We recommend the Linux Ext3 or Reiser hybrid journaling filesystems.

JFFS2 is not a good fit for CF cards because it uses a raw flash interface, not the logical block interface provided by CF.

Execute in Place

We do not use execute-in-place techniques with Linux on the iPAQ. WinCE/PocketPC does for applications but not its kernel. We find that Flash is a more precious resource than DRAM, so it is better to use compression to boost Flash capacity. The use of compression precludes the use of execute-in-place.

IPKG, Feeds, Releases, and Bootstraps

The handhelds.org community, and in particular Carl Worth, has developed a package format and package management program called ipkg, for Itsy Package. IPKG is similar to RPM and nearly identical in format to the Debian package format. I will describe ipkg files and how to create and manage them in . The main difference between ipkg and the others is the granularity of packaging and the integration of the ipkg command line interface.

Ipkg files are collected into feeds or releases. A feed is just a collection of ipkgs that is accessible via HTTP, FTP, or the local filesystem along with a Packages file that contains the description of the latest version of each ipkg in the feed.

Ipkgs are installed with the ipkg install. Like RPM and Debian packages, ipkg files specify what other packages they depend on. The ipkg install command will install the requested packages and all the packages on which they depend.

	bash# ipkg install python
...
      

Many feeds are mutable and are updated with new versions of individual packages. The ipkg update command fetches the updated Packages file from the feed, and ipkg upgrade will install the latest version of packages that have been installed from the feed.

A release is just an immutable feed, so that installation behavior is repeatable.

Packages may be removed using the ipkg remove command.

Notes and Cautions

That being said, I urge you not to worry too much before trying Linux on the iPAQ. However, do not try this on someone else's iPAQ without first getting their permission.

Configuring the Serial Port and Terminal Emulator

At some point while using or installing Linux on the iPAQ, you will need to use a terminal emulator to either the bootldr's command line interface or to the Linux serial console.

Serial Port Baudrate and Flow Control

Both the bootldr and the handhelds.org Linux distributions are set up to use the serial port at 115200 baud.

Hyperterminal

Hyperterminal is the terminal emulator that ships with Windows. It is a somewhat flaky program, but it is usable. I use it from my desktop machine, which runs Windows NT.

Minicom

Minicom is the terminal emulator that is standard in the Linux world. It is not without its quirks, but it is generally better behaved than Hyperterminal.

Using XModem, YModem, and ZModem

XModem, YModem, and ZModem are three members of a family of protocols for transferring data via serial port. They are often useful when sending from a host PC to the iPAQ or vice versa.

Zmodem is the most efficient and easy to use of the three, but it has not been implemented in the bootldr. The bootldr supports xmodem and ymodem and now uses ymodem by default.

Starting a transfer to the iPAQ with xmodem

First, on the iPAQ, enter a command that expects to receive data via xmodem, such as the bootldr command load bootldr or load root. For example:

	  boot> load bootldr
	  partition bootldr is a bootldr partition:
	    requireing a bootldr or parrot image.
	    After receving file, will automatically uncompress .gz images
	  loading flash region bootldr
	  using xmodem
	  ready for xmodem download..
	  ....
	

At this point, the bootldr is printing characters that show up as dots or upside down T's while it waits for data from the host PC.

Next, from the terminal emulator, initiate an xmodem send of the desired file.

Sending via XModem from Hyperterminal

With Hyperterminal on Windows, use the command: Transfer->Send File to activate the Send File dialog. With this dialog, select the name of the file to send, choose the Xmodem protocol, and then Send.

Sending via XModem from Minicom

With minicom, use the key sequence: ctrl-A-z-s Then select xmodem and the name of the file to send. Transfer->Send File to activate the Send File dialog. With this dialog, select the name of the file to send, choose the Xmodem protocol, and then Send.

If the bootldr continues to print dots, then make sure that the lrzsz package is installed on your Linux PC. The minicom application is often installed without the lrzsz package that implements xmodem, ymodem, and zmodem in Linux.

Starting a transfer to the iPAQ with ymodem

In practice, you will only use ymodem if you have a Linux host and you are sending data to the bootldr. Ymodem is 50% to 100% faster than xmodem because it uses a bigger block size. Ymodem is also more resilient to errors because it uses a CRC instead of a simple checksum.

If your bootldr is version 2.19.67 or earlier, you need to set the ymodem parameter to 1 to tell it to use the ymodem for data transfers. With later versions, ymodem is the default.

	  boot> set ymodem 1
	

Now start a transfer just as you would with xmodem, but choose the ymodem protocol.

Starting a transfer to the iPAQ with zmodem

Zmodem is supported by Linux on the iPAQ, but not the bootldr.

On the iPAQ, you can enable it to receive a file or set of files by issuing the rz command. By default, rz will not overwrite files. To direct it to do si, use rz -y. Generally, one does not need to type in the rz, it will be invoked automatically when the zmodem send is initiated from the host PC.

Installing the bootldr via BootBlaster

The first step in running Linux on the iPAQ in Native or Dualboot configuration is to upgrade the firmware to one that can boot Linux. We use firmware that we wrote at Compaq Research and that has been extended by members of the handhelds.org community, called bootldr.

Installing BootBlaster via ActiveSync

This step is needed if you do not have a network card that you can use to copy files to the iPAQ/PocketPC. If you have a network card, proceed to the Section called Installing BootBlaster via Pocket Internet Explorer.

  1. Connect your iPAQ via the USB or serial cradle or cable.

  2. 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 Default.

    • click OK (top right of the screen).

  3. 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. Start->Program->ActiveSync

  4. 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.

  5. 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.

Installing BootBlaster via Pocket Internet Explorer

If your PocketPC iPAQ is already connected to a network, then you can transfer the files such as BootBlaster.exe directly to the iPAQ without using ActiveSync.

Starting BootBlaster

  • On your iPaq H3600, use the File Navigator to find BootBlaster_1.18.exe wherever you put it, and then invoke it by tapping it with the stylus.

  • Backing Up PocketPC

    1. 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").

    2. Copy the "saved_bootldr.bin" off of your iPAQ and put it in a safe place in case you wish to restore it later.

    3. From the "Flash menu, select Save Windows gz This will copy and compress all the flash ROM on your ipaq into a .gz file along with a file containing the asset information from your iPAQ. This will take a while. After it is complete, copy these files to your PC to save them. Under normal circumstances, installing Linux will not touch the asset partition in flash, but it is safer to have a backup copy.

      Wait very patiently This will take many minutes, but a progress bar is displayed.

    Installing the Bootldr

    1. 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.

    2. First, BootBlaster protects all the flash blocks containing PocketPC so that there is no way that an interruption in the programming process can cause the OS to be corrupted.

      Sometimes BootBlaster freezes during this process. 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. It is perfectly safe to reset the iPAQ if it freezes while protecting flash.

      After protecting flash, BootBlaster erases the boot sector and then it programs the new boot loader into the boot sector.

    Getting to the Bootldr Command Line (boot> prompt)

    Updating from a Previous Version of Bootldr

    If your iPAQ has an older version of the bootldr on it, then we recommend that you update it.

    Use the load bootldr command to load the new version of the bootldr via xmodem over the serial cable or serial cradle.

    Installing Task-Bootstrap via Serial Port

    At the boot> prompt, type the load root and then send task-bootstrap.jffs2 via XMODEM.

    	boot> load root
    ...
          

    Installing Task-Bootstrap via CF Flash or Harddrive

    If you have a CF sleeve, or single or dual PCMCIA sleeve and a flash card or drive that you can plug into the sleeve, then you can install an root filesystem image directly from the card.

    As we discussed earlier, these cards are preformatted with a VFAT filesystem. Fortunately, the bootldr can read and write files on a VFAT filesystem. [Although, currently it has a bug where it cannot read from the toplevel directory on a VFAT filesystem.]

    1. Plug the card into a machine with network access. The iPAQ itself can fill that role if it has a dual PCMCIA sleeve, a network card, and is running PocketPC or Linux.

    2. Make a directory (folder) named /images on the filesystem on the card.

    3. Copy task-bootstrap.jffs2 to the directory /images on the card.

    4. Now plug the card into the iPAQ, if it was not already there, push reset, and get to the boot> prompt.

    5. Use the bootldr copy to copy /images/task-bootstrap.jffs2 from the card to the root partition of flash.

      	    boot> copy hda1:/images/task-bootstrap.jffs2 root
      	  

      The first argument to the copy is the source from which to copy date. The hda1: prefix indicates that it should copy from the first disk (hda) partition 1.

      The second argument to the copy is the destination to which to copy data. If the name of a flash partition is used as a destination, such as root, then the partition is erased, and the data is copied to it. If the partition is defined to contain a JFFS2 filesystem, then the unused erase blocks of the partition will be formatted for JFFS2.

      A backup of a Linux installation can be made by turning around that last command:
      	    boot> copy root hda1:/images/backup.jffs2
      	  

      One can restore this backup on the same iPAQ or to another iPAQ, as long as the size of the root partition is the same.

    Installing a Task Complete