File system and CompactFlash question on MCF5485EVB board

Claus, Ric claus at slac.stanford.edu
Fri Nov 2 05:44:12 UTC 2012


I ran into the same kind of issue but with and SD card.  The problem is that the files you're interested in are in the first partition, not in the MBR area of the disk.  Thus you need to dereference the first partition descriptor found in the MBR to find the Volume ID (see http://www.pjrc.com/tech/8051/ide/fat32.html), and use that to access your files.  The following snippet of $RTEM_ROOT/src/cpukit/libmisc/fsmount/fsmount.h helped me to figure out what is going on:

 * The following example code tries to mount a FAT file system within a SD
 * Card.  Some cards do not have a partition table so at first it tries to find
 * a file system inside the hole disk.  If this is successful the mount process
 * will be aborted because the @ref RTEMS_FSTAB_OK condition is true.  If this
 * did not work it tries to mount the file system inside the first partition.
 * If this fails the mount process will not be aborted (this is already the
 * last entry), but the last error status will be returned.
 *
 * @code
 * #include <stdio.h>
 * #include <string.h>
 * #include <errno.h>
 *
 * #include <rtems.h>
 * #include <rtems/bdpart.h>
 * #include <rtems/error.h>
 * #include <rtems/fsmount.h>
 *
 * static const rtems_fstab_entry fstab [] = {
 *   {
 *     .source = "/dev/sd-card-a",
 *     .target = "/mnt",
 *     .type = "dosfs",
 *     .options = RTEMS_FILESYSTEM_READ_WRITE,
 *     .report_reasons = RTEMS_FSTAB_ANY,
 *     .abort_reasons = RTEMS_FSTAB_OK
 *   }, {
 *     .source = "/dev/sd-card-a1",
 *     .target = "/mnt",
 *     .type = "dosfs",
 *     .options = RTEMS_FILESYSTEM_READ_WRITE,
 *     .report_reasons = RTEMS_FSTAB_ANY,
 *     .abort_reasons = RTEMS_FSTAB_NONE
 *   }
 * };
 *
 * static void my_mount(void)
 * {
 *   rtems_status_code sc = RTEMS_SUCCESSFUL;
 *   int rv = 0;
 *   size_t abort_index = 0;
 *
 *   sc = rtems_bdpart_register_from_disk("/dev/sd-card-a");
 *   if (sc != RTEMS_SUCCESSFUL) {
 *     printf("read partition table failed: %s\n", rtems_status_text(sc));
 *   }
 *
 *   rv = rtems_fsmount(fstab, sizeof(fstab) / sizeof(fstab [0]), &abort_index);
 *   if (rv != 0) {
 *     printf("mount failed: %s\n", strerror(errno));
 *   }
 *   printf("mount aborted at %zu\n", abort_index);
 * }
 * @endcode


Cheers,
            Ric


________________________________________
From: rtems-users-bounces at rtems.org [rtems-users-bounces at rtems.org] On Behalf Of Chris Xenophontos [cxenophontos at hammers.com]
Sent: Thursday, November 01, 2012 8:02 PM
To: rtems-users at rtems.org
Subject: File system and CompactFlash question on MCF5485EVB board

We are currently running RTEMS 4.10.2 on a Coldfire MCF5485EVB board, with a Transcend 4GB Compact Flash Card installed in respective slot.  The required manufacturer's firmware has been downloaded onto CPLD in order to access Compact Flash, etc.

The Compact Flash socket is wired on the board to use 16-bit accesses, (both enables tied together), and memory mapped mode only.

We want to use the Compact Flash card for file storage for our application, not for bootup.

I've modified an existing ATA/IDE driver to access Compact Flash card, as directed in RTEMS File System documentation.

The ATA driver initializes and reads Compact Flash card status correctly, and, when Identify Drive command is sent to card, the correct expected data is returned.  First word is 0x848A, and driver correctly interprets cylinder/head/sector and LBA info - since these values translate into the card's capacity of 4GB.  Logical Block Addressing is used.

The problem we have is, during register and mount process, the file system attempts to read an MBR from the Compact Flash card - however, all zeroes are returned, and the process fails.

When a file is written to CompactFlash card using a PC, it can be listed, etc, so the card appears to be OK.  And because the Identify Device command causes the card to return expected data, the HW interface from our Coldfire board appears to be OK as well.

Relevant parts from rtems.c are included below - any help is greatly appreciated!!

thanks
Chris Xenophontos

#include <stdlib.h>
#include <rtems.h>
#include <bsp.h>
#include <unistd.h>

#include <rtems/rtems_bsdnet.h>
#include <rtems/libio.h>
#include <rtems/shellconfig.h>     // added for shell/filesystem support
#include <rtems/ide_part_table.h>
#include "networkconfig.h"
#include <libchip/ide_ctrl_cfg.h>
#include <libchip/ide_ctrl_io.h>
#include  <libchip/ata.h>
#include <rtems/bdpart.h>
#include <rtems/dosfs.h>
#include <rtems/fsmount.h>

rtems_task Init( rtems_task_argument ignored );
extern int xmain( void );


fstab_t fs_table[] =
{
  {
    "/dev/hda","/mnt/cf", "dosfs",
    RTEMS_FILESYSTEM_READ_WRITE,
    FSMOUNT_MNT_OK | FSMOUNT_MNTPNT_CRTERR | FSMOUNT_MNT_FAILED,
    0
  }
};



rtems_task Init( rtems_task_argument ignored )
{
    rtems_status_code sc;
    int rv;
    size_t abort_index;

   /*     * * * *   /

    abort_index = 0;

    sc = rtems_bdpart_register_from_disk( "/dev/hda" );

    rv = rtems_fsmount( fs_table, sizeof(fs_table)/sizeof(fs_table[0]), NULL);

    printf( "\n\nrtems_bdpart_register_from_disk status: %d\n", sc );    // returns 27 = IO_ERROR
    printf(   "\nrtems_fsmount status status:            %d\n", rv );          // return 0

   /*     * * * *   /

    sc = rtems_shell_init ( "fstst", 60 * 1024, 150, "/dev/console", 0, 1, 0 );

   /*     * * * *   /

    printf( "\nEntering xmain....\n" );

    xmain();
};

   /*     * * * *   /

#define TASK_INTLEVEL 0
#define CONFIGURE_INIT
#define CONFIGURE_INIT_TASK_ATTRIBUTES ( RTEMS_FLOATING_POINT | RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_ASR | RTEMS_INTERRUPT_LEVEL(TASK_INTLEVEL))

#define CONFIGURE_MAXIMUM_TASKS               20
/*( SYS_MAX_TASKS + 7 ) */
#define CONFIGURE_MAXIMUM_TIMERS               3


#define CONFIGURE_MAXIMUM_SEMAPHORES          20 //12   // 16
#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES      24   //SB_MAX_PIPES=23    //32
/* #define CONFIGURE_INIT_TASK_STACK_SIZE      2048 */

#define CONFIGURE_INIT_TASK_STACK_SIZE (10*1024)
#define CONFIGURE_INIT_TASK_PRIORITY   120
#define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \
                                           RTEMS_NO_TIMESLICE | \
                                           RTEMS_NO_ASR | \
                                           RTEMS_INTERRUPT_LEVEL(0))

#define ADA_TASKS  0

#define CONFIGURE_RTEMS_INIT_TASKS_TABLE

#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER

#define CONFIGURE_MAXIMUM_DRIVERS                   10
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS    30
#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
#define CONFIGURE_FILESYSTEM_DOSFS

#define CONFIGURE_APPLICATION_NEEDS_IDE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_ATA_DRIVER
#define CONFIGURE_ATA_DRIVER_TASK_PRIORITY           9
#define CONFIGURE_BDBUF_MAX_WRITE_BLOCKS             512
#define CONFIGURE_MICROSECONDS_PER_TICK           10000
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS    30

#define CONFIGURE_SHELL_COMMANDS_INIT         // added for shell/filesystem support
#define CONFIGURE_SHELL_COMMANDS_ALL     // added for shell/filesystem support

////////////////////////////////////////////////////////////////
#include <rtems/confdefs.h>






More information about the users mailing list