AnsweredAssumed Answered

MFS files not writing to memory.

Question asked by Sean MacKay on Apr 8, 2014
Latest reply on May 12, 2014 by Sean MacKay

MFS is still NOT doing anything after formatting, and I can not figure out why.

 

---

 

I am having trouble reading and writing any files onto internal flash with MFS. I can write and read with FlashX, I can detect that an MFS install is not formatted, and then format it, but I can not write and/or read a file after doing so. I'm not sure which part breaks down, but I've attempted to manually read the first 500 memory locations on the flash using FlashX and can't see anything other than a basic MFS string likely related to the formatting process.

 

My (stripped down to remove excess comments and error checking which passes) code is, including some commented toggles I've enabled and disabled while testing:

 

Code

    #define         FLASH_NAME "flashx:storage" //custom bank from 0x0006000 to 0x0007FFFF

  #define BUFFER_SIZE (80)

  static char_ptr buffer, buffer2;

  MQX_FILE_PTR   flash_file, pm_file, mfs_file, working_file;

  uint_32 error, len;

  buffer = (char_ptr)_mem_alloc_zero(BUFFER_SIZE);

  buffer2= (char_ptr)_mem_alloc_zero(BUFFER_SIZE);

  buffer = "\nThis is a test string";

 

  _int_install_unexpected_isr();

 

  /* Open the flash device */

  flash_file = fopen(FLASH_NAME, NULL);

  /* Get the size of the flash file */

  fseek(flash_file, 0, IO_SEEK_SET);

  printf("\nSize of the flash file: 0x%x Bytes", ftell(flash_file)); //Doesn't actually work for some reason, but also broken with flashx:bank1

  /* Disable sector cache */

  //ioctl(flash_file, FLASH_IOCTL_ENABLE_SECTOR_CACHE, NULL);

//Determine base memory address

// uint_32 memlocation = 0;

// ioctl(flash_file, FLASH_IOCTL_GET_SECTOR_BASE, &memlocation);

// printf("\nThe base memory location is 0x%08x", memlocation); //confirms starts at 0x60000

  /* Unprotecting the the FLASH might be required */

  //uint_32 ioctl_param = 0;

  //ioctl(flash_file, FLASH_IOCTL_WRITE_PROTECT, &ioctl_param);

 

 

  /*

  * Attempt to install MFS Partition manager.

  */

  fseek(flash_file, 0, IO_SEEK_SET);

  error = _io_part_mgr_install(flash_file, "PM:", 0);

  pm_file = fopen("PM:", 0);

 

 

  /*

  * Attempt to install MFS

  */

  error = _io_mfs_install(pm_file, "MFS:", 0);

  /*

  * Open MFS

  */

  mfs_file = fopen("MFS:", NULL);

  error = ferror(mfs_file);

  printf("\nOpening the file system. The error recieved is %d", error);

  if ((error != MFS_NO_ERROR) && (error != MFS_NOT_A_DOS_DISK))

          _task_block();

  // Check for format

  if (error == MFS_NOT_A_DOS_DISK)

  {

  printf("\nMFS not formatted, formatting to continue.");

         ioctl(mfs_file, IO_IOCTL_DEFAULT_FORMAT, NULL);

  }

  else

  printf("\nMFS is formatted.");

  fclose(mfs_file);

     

  //ioctl( mfs_file, IO_IOCTL_FAT_CACHE_OFF, NULL);    // without CACHE

 

 

  /*

  * Test the MFS

  */

  buffer = "Testing the MFS filesystem write";

 

  working_file = fopen("MFS:myfile.txt", "n");

  if (working_file == NULL ) printf("Error creating file.");

  //write(working_file, buffer, strlen(buffer));

  fprintf(working_file, buffer);

  /* Close the file: */

  //ioctl( working_file, IO_IOCTL_FLUSH_FAT, NULL);

  //fflush(working_file);

  error = fclose(working_file);

  printf("\nThe contents bring written to file are: %s\n and the error code of closing is: %d", buffer, error);

 

  working_file = fopen("MFS:myfile.txt", "r");

  read(working_file, buffer2, strlen(buffer));

  /* Close the file: */

  error = fclose(working_file);

 

  printf("\nThe contents of the written file are: %s\n and the error code of closing is: %d", buffer2, error);

  return 0;

 

 

No errors are thrown from any of the function calls to error (aside from a NOT_A_DOS_DISK when the flashX is not formatted. Also no task errors are thrown.

Outcomes