View detail for AVR32115: 32-bit AVR AP7 Linux ATA driver

View detail for AVR32115: 32-bit AVR AP7 Linux ATA driver
AVR32115: AVR32 AP7 Linux ATA driver
Features
• Conformant with ATA 6 standard.
• Supports of parallel ATA devices as:
Hard disks
CDROM and DVDROM
Other ATA compliant devices
• Supports up to two devices.
• PIO mode 0 to 4 supported.
32-bit
Microcontrollers
Application Note
1 Introduction
This application note describes how to connect parallel ATA devices to the AVR®32
using the built-in CompactFlash® controller, the External Bus Interface (EBI) and a
simple EBI to ATA adaptor. This application note describes an example adaptor
card for the STK®1000 development board.
A low-level device driver for the Linux® ATA library is provided. On top of this driver
Linux provides higher-level drivers for a number of devices and applications.
A parallel ATA device can be a hard disk, CDROM, DVDROM or any other device
compliant with the ATA standard (found at http://www.t13.org/). The use of hard
disks opens the possibility for vast and reliable storage space, root file system on
disks and even extended memory by the use of swap files.
DMA transfers to external devices are not supported on the current AP7000 series.
Knowledge of configuration and use of the Linux system and the Linux Board
Support Package for AVR32 AP7000 series is required for this application note.
Neither the knowledge of Linux kernel development nor C-programming experience
is required.
Rev. 32068C-AVR-08/08
2 Hardware Interface
2.1 ATA Signal Summary
The ATA standard specifies the signals in Table 1 for communication between the
host and the device:
Table 1: ATA Signals
Name
Description
Logic level
CSEL
Cable Select
High
CS0-
Chip Select 0
Low
Out
CS1-
Chip Select 1
Low
Out
DD [15:0]
Data [15:0]
High
In / Out
DASP-
Device active
Low
DA [2:0]
Address [2:0]
High
Out
DMACK-
DMA acknowledge
Low
Out
DMARQ-
DMA request
Low
In
INTRQ
Interrupt request
High
In
DIOR-
I/O read
Low
Out
DIOW-
I/O write
Low
Out
IORDY
I/O ready
High
In
PDIAG-
Passed diagnostics
Low
RESET-
Reset
Low
Direction
Out
For a full description of these signals please refer to Chapter 6 of the ATA 6 standard.
The standard can be purchased from ANSI and a working draft of the standard is also
available online at http://www.t10.org/t13/project/d1410r3a-ATA-ATAPI-6.pdf.
2.2 External Bus Interface and CompactFlash Controller
The AVR32 has a built-in CompactFlash controller with the ability to operate in True
IDE and Alternate True IDE mode. This enables communication with ATA devices
through MMIO (Memory Mapped IO). The controller handles all control signals.
ATA devices are accessed by using the specified address offsets within the
CompactFlash controller address space as specified in Table 2.
2
Table 2: CompactFlash IDE modes
Name
Address offset
CS0-
CS1-
True IDE
0x00c00000 - 0x00dfffff
Asserted
Negated
Alternate True IDE
0x00e00000 – 0x00ffffff
Negated
Asserted
AVR32115
32068C-AVR-08/08
AVR32115
For more information on the CompactFlash controller please refer to Chapter 16 of
the AP7000 datasheet.
The signals of the EBI and the CompactFlash controller map to ATA signals as
specified in Table 3.
Table 3: EBI / CompactFlash to ATA signals
EBI name
CompactFlash name
ATA name
N/A
CFCE1
CS0-
N/A
CFCE2
CS1-
D [15:0]
N/A
DD [15:0]
A [3:1]
N/A
DA [2:0]
NWR1
CFIOR
DIOR-
NWR3
CFIOW
DIOW-
NWAIT
N/A
IORDY
N/A
CFRNW
N/A
2
NCS4
CFCS0
N/A
3
NCS5
CFCS1
N/A
3
Note
1
Notes:
1. The use of EBI address lines 3 to 1 instead of 2 to 0 is due to a work-around
described in Chapter 3.
2. CFRNW is inverted and used as DIR signal by adaptor circuit.
3. NCS4/CFCS0 or NCS5/CFCS1 (depending on which CompactFlash memory
space is accessed) are used as OE- by adaptor circuit.
2.3 Example of EBI to ATA Adaptor Circuit
Schematics for an adaptor circuit for the STK1000 development card using the PCI
style connector is found at URL.
The adaptor consists of logic voltage converters used to convert between the
voltages and isolating the ATA bus from the EBI. The adaptor also has a LED for
showing ATA activity (DASP-).
In order for INTRQ- to function properly capacitor C63 has to be removed from the
STK1000. The capacitor is located on the other side of the “Int B” button.
2.3.1 ATA bus voltage level
The ATA standard states that voltages above 2.4 Volts are to be considered logical
high and voltages below 0.5 Volts are to be considered logical low.
The majority of new DMA capable devices are using 3.3 Volts as logical high, still the
example adaptor features a jumper that lets the user choose between 3.3 and 5.0
Volts. Please make sure that the correct voltage is used, as using the wrong voltage
may result in reduced signal integrity.
Simpler circuits may replace the voltage converters if it is known that the device uses
3.3 Volts.
3
32068C-AVR-08/08
3 Software Interface
3.1 Linux Device Driver and libATA
The device driver is included with Linux from version 2.6.23. The file can be found in
the Linux file tree at:
drivers/ata/pata_at32.c
The purpose of the low-level device driver is to:
1. Setup memory space to be used by libATA.
2. Setup SMC 1 signal timings of this memory space according to ATA standard.
3. Attach the libATA interrupt handler to the IRQ given by the wire-up code in
order to handler interrupts from the ATA device.
The rest of the device handling is done by libATA through MMIO. The device is
identified and presented to the user through the SCSI emulation layer.
Reservation of pins and initial setup of the EBI and the CompactFlash controller is
done by the wire-up code where the device is also registered to the kernel. See
Section 3.4 for an example of this.
For more information on Linux device drivers in general please refer to kernel
documentation or the book Linux Device Drivers found at http://lwn.net/Kernel/LDD3/.
3.2 Memory Space Setup
The first step of the driver initialization is to setup the memory space for
communicating with the ATA device. The CompactFlash controller memory space to
be used is given by the platform data record set up by the architecture wire up code.
The driver reserves two memory spaces within the main memory space, and then
maps them to virtual memory addresses.
The driver also sets up non-timing aspects of the SMC as follows:
•
•
•
•
•
•
16-bit bus width.
Sample data on rising edge of NRD.
Drive data on falling edge of NCS.
Use NWAIT with READY mode.
Byte select access type.
TDF optimization off.
Please refer to AP7000 datasheet for more details on these settings.
As mentioned earlier address bits 3 to 1 of the address bus is used instead of 2 to 0.
The ATA standard specifies that all register transfers to the ATA device (8-bit) are to
take place on the lower byte of the data bus (7 to 0). Since the SMC is configured for
16-bit data transfer, the odd addressed bytes would go on the higher byte due to the
endianness of the AVR32.
By using address lines 3 to 1 instead, all addresses can be even, thus all 8-bit
transfers will go on the lower byte as the ATA standard demands. This removes the
need to swap between bus widths of 8- and 16-bit.
1
4
Static Memory Controller
AVR32115
32068C-AVR-08/08
AVR32115
The device addresses given to libATA has to be altered according to this, in effect the
offsets have to be shifted on step up by the low level driver.
3.3 Signal Timings
The driver has to setup the SMC timings according to the current PIO mode used by
libATA. These timings are computed by a libATA utility function and can be found in
Chapter 10 of the ATA 6 standard.
Table 4: ATA data transfer timings summary
PIO mode
Max MB / sec
Cycle time
0
3.3
600 ns
1
5.2
383 ns
2
8.3
240 ns
3
11.1
180 ns
4
16.7
120 ns
The timings are different for register and data transfer (8- and 16-bit respectively) in
PIO modes 0 to 2. The driver currently uses the register transfer timings for both
transfer types, giving slightly slower data transfers in PIO modes 0 to 2. This is not
considered to be a big issue, as most users probably want to use the faster modes 3
and 4.
3.4 Wire-up Code
In essence the wire-up code needs to do the following:
1. Enable a CompactFlash controller memory space with the EBI.
2. Select the multiplexed pins needed by the EBI and CompactFlash controller
to their peripheral function:
•
CFCE_1 and CFCE_2
•
NCS4/CFCS0 or NCS5/CFCS1.
•
CFRNW
•
NWAIT
3. Enable an external interrupt pin and compute the corresponding IRQ.
4. Register the device with the kernel.
For an example of how this is done, please refer to the code in:
arch/avr32/mach-at32ap/at32ap7000.c
5
32068C-AVR-08/08
4 Testing and Performance
4.1 Test setup
The driver was tested with the example adaptor card on the STK1000 development
kit, standard hard disks, Ext 2 and Ext 3 file systems and the Bonnie® benchmark
utility found at http://www.textuality.com/bonnie/.
The AP7000 was clocked at 140 MHz.
4.2 Test results
The following results where achieved in PIO mode 4:
Table 5: Bonnie results in PIO mode 4
Sequential input
Per Char
Block
Rewrite
FS
K/sec CPU K/sec CPU K/sec CPU
Ext 2 1,640 95 6,324 76 2,960 76
Ext 3 1,524 89 5,115 66 2,781 60
Sequential output
Random
seek
Per Char
Block
K/sec CPU K/sec CPU K/sec CPU
1,411 96 5,324 85
78
7
1,413 96 5,328 80
84
7
The results show that the max achievable transfer rate of 16.7 MB/s is far from being
achieved. This indicates that the performance is bound by CPU speed.
4.3 Automated testing
A Shell script for automated testing and a Perl script that parse the test reports for
easy import to a spreadsheet program has been developed to ease the testing
process. These two scripts can be found together with this application note.
The automated test runs through a list of volumes specified at the top of the script.
Please edit the script in order to specify the correct volumes to be tested. The number
of times each test is run can also be specified. Documentation for how the script is
altered is embedded as comments within the script.
For each volume the script runs a three-stage test consisting of:
1. Run Bonnie the specified number of times.
2. Make the specified number of copies of the generated random data file.
3. Check the MD5 sum of the random file copies to check for file corruption.
Test results is stored in a directory named autotest. The kernel log output is also
stored for later analysis. If there was signal corruption during the test there will be
messages like this in the kernel log:
ata1.00: exception Emask 0x0 SAct 0x0 SErr 0x0 action 0x2 frozen
If these messages occur please check the ATA signals and the adaptor.
To generate a report for easy import to a spreadsheet program simply run the Perl
script with the path to the report directory as an argument. The script will then parse
the report files and output the report.
6
AVR32115
32068C-AVR-08/08
AVR32115
5 Example use in Linux
5.1 Kernel with ATA support
5.1.1 Configuring and building the kernel
To compile the kernel with support for parallel ATA on the AVR32, the following
libraries and drivers have to be selected, either as built-in or modules:
System Type and features --->
Atmel AVR32 AP options --->
AT32AP7000 static memory bus width (16 bit)
Device Drivers --->
SCSI device support --->
<> SCSI device support
<> SCSI disk support
<> SCSI CDROM support
<> Serial ATA and PATA drivers --->
<> Atmel AVR32 PATA support
File systems --->
<> Second extended fs support
<> Ext 3 journalling file system support
CD-ROM/DVD Filesystems --->
<> ISO 9660 CDROM file system support
Here <> indicates that you have to select either built-in <*> or module <M>. After
selecting these, the kernel image and modules has to be rebuilt and installed.
5.1.2 Booting the kernel and loading modules
Boot the compiled kernel. If one or more of the drivers were compiled as modules
they need to be loaded:
modprobe sd_mod
modprobe sr_mod
modprobe pata_at32
When these modules are loaded and there is one or two ATA devices connected to
the adaptor, there should be a message in the kernel log informing about the
successful discovery of these devices. The devices should also appear in the /dev
directory.
7
32068C-AVR-08/08
This is an example of kernel log messages when a hard disk with four partitions and a
CDROM is connected:
sda: sda1 sda2 sda3 sda4
sd 0:0:0:0: [sda] Attached SCSI disk
…
sr 0:0:1:0: Attached scsi CD-ROM sr0
Please note that even if the devices are detected they may not function in a reliable
manner. Extensive testing, for instance by using the earlier mentioned test script,
should always be performed in order to validate the hardware. Examine kernel log for
libATA error messages.
5.1.3 Troubleshooting
If detection of the ATA devices failed, examine libATA output to the kernel log. Most
likely there is a communication problem with the devices due to hardware failure or
poor signal integrity.
Check the following:
•
•
•
•
•
Are all ATA signal lines properly connected? Try enabling the DEBUG_BUS flag
in the low-level driver and look at the signals on the bus when the module is
reloaded.
Is DMACK- high at all times?
Is capacitor C63 removed from the STK1000?
Is the correct voltage level used on the ATA bus?
Is the ATA device working? Try another device.
The debug flag in include/linux/libata.h may be enabled in order to get more
debugging output from libATA. Also consider changing PIO_MASK in the low-level
driver to enforce the use of lower PIO modes.
5.2 Creation, use and maintenance of file systems
5.2.1 Install needed file system tools
The following tools are needed in order to create, use and maintain file systems:
•
•
•
•
fdisk (partition hard disks)
mkfs (with support for Ext 2 and / or Ext 3)
fsck (with support for Ext 2 and / or Ext 3)
mount
All these tools can be built using Buildroot. Please refer to application note AVR32003
or online documentation for more information on Buildroot.
5.2.2 Partition hard disk and create file systems
Before a hard disk can be used it needs to be partitioned. This can be done by the
use of fdisk, an interactive disk partitioner. Please refer manual pages for more
information of it usage. File systems are created using the mkfs command.
8
AVR32115
32068C-AVR-08/08
AVR32115
Example:
$ fdisk /dev/sda
… Create four partitions …
$ mkfs.ext2 /dev/sda2
$ mkfs.ext3 /dev/sda3
Four partitions are created; they will all be used in later examples.
5.2.3 Mounting file systems
A file system on a disk may be mounted in the root file system using the mount
command. The directory /mnt is a common place to mount auxiliary file systems.
Example:
$ mkdir /mnt
$ mkdir /mnt/sda2
$ mkdir /mnt/sda3
$ mount –t ext2 /dev/sda2 /mnt/sda2
$ mount –t ext3 /dev/sda3 /mnt/sda3
To remove mounted file systems use the umount command.
Example:
$ umount /mnt/sda2
In order to avoid corruption always umount file systems prior to power down.
To automate the process of mounting file systems they can be added to /etc/fstab.
Please refer to manual pages on fstab for more information.
5.2.4 Maintaining file systems
In file systems are corrupted they need to be checked using the fsck utility. Please
refer to manual pages for more information.
5.2.5 Swap partitions
By the use of virtual memory Linux may move processes not currently running from
primary memory and onto the swap partition. This enables the systems to have more
loaded processes than there is actually room for in the primary memory.
A swap partition has to be created and enabled using the mkswap and swapon
commands.
Example:
$ mkswap /dev/sda1
$ swapon /dev/sda1
Please note that it may take considerable time to reload a swapped process back into
primary memory. Do not use swapping for real-time applications.
9
32068C-AVR-08/08
5.3 Root file system on hard disk
This Application note concludes by showing how a root file system on a hard disk can
be created and used.
5.3.1 Create a root file system on hard disk
The easiest way to create a root file system is to create a file system on a sufficiently
large partition, mount it and extract the tar-ball created by Buildroot in the directory.
This example creates an Ext 3 root file system on volume sda4:
$ mkfs.ext3 /dev/sda4
$ mkdir /mnt/sda4
$ mount –t ext3 /dev/sda4 /mnt/sda4
$ cd /mnt/sda4
$ tar xf /path/to/rootfs.tar
The path to the root file system archive needs to be replaced by its real path.
5.3.2 Boot with root file system on hard disk
As of yet the kernel loader uBoot is not able to use ATA devices on the AVR32.
Therefore the kernel has to be loaded by other means such as non-volatile memory
or TFTP.
In order for the kernel to use the root file system at boot time, the drivers have to be
built into the kernel (not compiled as modules).
The name of the device containing the root file system has to be given as an
argument to the kernel at boot time. This is done by the use of uBoot.
Example:
UBoot> set bootargs 'root=/dev/sda4 console=ttyS0'
UBoot> saveenv
UBoot> boot
10
AVR32115
32068C-AVR-08/08
Disclaimer
Headquarters
International
Atmel Corporation
2325 Orchard Parkway
San Jose, CA 95131
USA
Tel: 1(408) 441-0311
Fax: 1(408) 487-2600
Atmel Asia
Room 1219
Chinachem Golden Plaza
77 Mody Road Tsimshatsui
East Kowloon
Hong Kong
Tel: (852) 2721-9778
Fax: (852) 2722-1369
Atmel Europe
Le Krebs
8, Rue Jean-Pierre Timbaud
BP 309
78054 Saint-Quentin-enYvelines Cedex
France
Tel: (33) 1-30-60-70-00
Fax: (33) 1-30-60-71-11
Atmel Japan
9F, Tonetsu Shinkawa Bldg.
1-24-8 Shinkawa
Chuo-ku, Tokyo 104-0033
Japan
Tel: (81) 3-3523-3551
Fax: (81) 3-3523-7581
Technical Support
[email protected]
Sales Contact
www.atmel.com/contacts
Product Contact
Web Site
www.atmel.com
Literature Request
www.atmel.com/literature
Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any
intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMEL’S TERMS AND
CONDITIONS OF SALE LOCATED ON ATMEL’S WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED
OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS,
BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS
BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the
contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice. Atmel does not make any
commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in,
automotive applications. Atmel’s products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life.
© 2008 Atmel Corporation. All rights reserved. Atmel®, logo and combinations thereof, AVR®, STK® and others, are the registered
trademarks or trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others.
32068C-AVR-08/08
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement