world leader in high performance signal processing
Trace: » hddtest

ADSP-BF548 EZ-KIT Quick Start: Peripheral Demos: hddtest

www.analog.com_static_imported-files_images_product_descriptions_680755565image1a.jpg

What is hddtest

The hdd demo is found in the folder Home > Blackfin > demos > hdd

This demo program will check if the sda1 partition is mounted to /mnt and then will create a test file on the hard drive. You will need to prepare the hard drive for this demo by following the preparation text file.

This is only a simple demo, just to show you that files can be written to the hard drive and basic debugging can be performed.

Download hddtest

The demo comes with the customised Ubuntu ISO and can be found in the folder /home/Blackfin/demos. Alternatively it is already installed on the demo uClinux image (demo-uclinux.img) that you can get on ADSP-BF548 EZ-KIT Quick Start: Booting uClinux.

If you just want to download the demos on their own and get their source code you can download the compressed archive (demos-R1.tar.gz) here bf548-quick-start .

How to run the hddtest program

  • Change directory to /demos/hdd

    root:/> cd /demos/hdd
  • If you haven't before, partition and format the hard drive

    root:/> fdisk /dev/sda
    
    The number of cylinders for this disk is set to 4864.
    There is nothing wrong with that, but this is larger than 1024,
    and could in certain setups cause problems with:
    1) software that runs at boot time (e.g., old versions of LILO)
    2) booting and partitioning software from other OSs
    (e.g., DOS FDISK, OS/2 FDISK)
    
    Command (m for help): p
    
    Disk /dev/sda: 40.0 GB, 40007761920 bytes
    255 heads, 63 sectors/track, 4864 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
       Device Boot      Start         End      Blocks Id System
    /dev/sda1               1        4864    39070048+  b Win95 FAT32
    Command (m for help): q
    
    root:/> mkfs.ext2 /dev/sda1
    mke2fs 1.41.12 (17-May-2010)
    ext2fs_check_if_mount: Can't check if filesystem is mounted due to missing mtab file while determining whether /dev/sda1 is mounted.
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    2444624 inodes, 9767512 blocks
    488375 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=0
    299 block groups
    32768 blocks per group, 32768 fragments per group
    8176 inodes per group
    Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624
    
    Writing inode tables: done 
    Writing superblocks and filesystem accounting information: done
    
    This filesystem will be automatically checked every 30 mounts or
    180 days, whichever comes first. Use tune2fs -c or -i to override.

    Note: If your partition table doesn't look like this when you ran the p command

       Device Boot      Start         End      Blocks Id System
    /dev/sda1               1        4864    39070048+  b Win95 FAT32

    Then you may have to delete some partitions etc. Research the fdisk command here http://tldp.org/HOWTO/Partition/fdisk_partitioning.html to learn how to do this.

  • If you haven't already, mount the hard drive partition

    root:/> mount /dev/sda1 /mnt
  • Run hddtest

    root:/> ./hddtest
  • View the created file

    root:/> ls /mnt
    lost+found     test_file.txt
    root:/> cat /mnt/test_file.txt
    This is a test file that should be saved on to the hard drive!
  • (Optional) Unmount the hard drive

    root:/> umount /dev/sda1


How the hddtest demo works

  • Required header files
    This program makes use of the string.h and stdio.h header files, the string library is for looking through and checking if the file system is loaded while the stdio library is for reading/writing to the hdd.
  • File system check
    This segment of code will open the /proc/mounts syscall and look through all the mounted file systems to see if /dev/sda1 is mounted. If you are looking for another file system other than /dev/sda1 than you can modify the 'device' string variable to point elsewhere.
  • Writing out a file
    If the file system is found, the program performs a normal file write procedure. It opens the file test_file.txt and will write a simple demo string to it. This is akin to your standard C program, and you can write out to the mounted partition in different ways just like your normal development machine.

For other alternatives and ways to utilise the hdd (once it is mounted) look up File I/O programming. Anything available in standard C will most likely be available to perform on the Blackfin.

Compiling hddtest

Make sure your vendor staging install is complete (ADSP-BF548 EZ-KIT Quick Start: Compiling uClinux).

root:/> make vendor_staging_install

Run the following compile command in the same directory as the source code:

root:/> bfin-linux-uclibc-gcc -O2 hddtest.c -o hddtest

What this compile command is doing is it is calling the uclibc cross compiler that is set up from the Blackfin toolchains to compile our application.

The final parameters match up to standard gcc compiling, “hddtest.c” is the source file and ”-o hddtest” indicates the output file is “hddtest”.

A standard make file is accompanies this demo and you can run that by simply calling

root:/> make hddtest

Further Reading

The ATAPI controller is discussed on the Blackfin On-Chip ATAPI Controller page.

You can look up file operations for programming with C to see examples such as binary file io.