The question about MFS and SD card in the MQX

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

The question about MFS and SD card in the MQX

1,390 Views
小勇邹
Contributor II

The SD card is partitioned to two part in the widows OS.

How to access the file in the part 2 of the SD card by MQX OS with MFS?

For example, I wan to access the file in address \Freescale\boot.bin in the part 2 by using MFS.

Is it possible to get the start sector and end sector of the file by using MFS?

Is it possible to get the start sector of part 2 by using MFS?

Is it possible to write and read something to the sectors of part2 by using the fwrite and fread function without using MFS ?

0 Kudos
8 Replies

755 Views
RadekS
NXP Employee
NXP Employee

Hi Robin,

I suppose that by “part 2 of the SD” you mean partition 2. Correct?

Please look at sdcard example code at:

c:\Freescale\Freescale_MQX_4_2\mfs\examples\sdcard\demo.c

If you want select second partition, please edit line with partition_name definition into

char partition_name[] = "pm:2";

Note: supported are four partitions (1..4).

You can use fopen() function for access into this file and use simply write() or read() function for access to content of this file.

As inspiration you can use shell functions (at c:\Freescale\Freescale_MQX_4_2\shell\source\mfs\) or for example some customer example code. For example like here:

https://community.freescale.com/thread/356993

In case of MFS, you don’t need to take care about start or end sectors…. They are handled inside MFS code.

You could simply work with directory structure and just read or write files….

I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

755 Views
小勇邹
Contributor II

Dear RadekS,

Yes.Thank you for your help.

There are two parts in my application- the bootloader part(without MQX OS and MFS) + the user application part(with MQX OS and MFS).

I want to find out which sector of SD card the firmware file is stored by using the user application part.

Then the bootloader part can get the firmware file according to the sector information without using MFS.

Is it possible?

I think the “LOCATION” in the data struct “struct mqx_file” is the start sector information of the file and “SIZE” is the file size. Is it correct?

Best regards.

Robin Zou.

Robin-XiaoYong Zou

ABB Xiamen Low Voltage Equipment Company Limited

BU LPLS E&D China

No. 12-20,3rd Chuang Xin Road Xiamen SEZ,Fujian 361006 P.R.China

CN

Phone: +86 592 5767877

Telefax: +86 592 6038110

Mobile: +86 181-5089-3720

email: robin-xiaoyong.zou@cn.abb.com<mailto:robin-xiaoyong.zou@cn.abb.com>

0 Kudos

755 Views
RadekS
NXP Employee
NXP Employee

Hi Robin,

Thank you for clarification.

So, If I understood correctly, you don’t want use whole MFS inside bootloader. That is clear requirement due to code size.

Unfortunately described solution will work only under special condition – when file will be not fragmented. However we don’t have any tool on FAT file system that could manage that.

I could imagine that you could implement some “lite” version of MFS which will run under special restrictions (like only short name, file must be in root,…). In that case you have to know at least start of FAT table, type of FAT (FAT12/16/32), start of file, cluster size and you can read file from SD card safely.

Unfortunately we don’t have such version of MFS. If you want it, but you don’t have resource for that, you could try paid support for that:

http://www.freescale.com/webapp/sps/site/prod_summary.jsp?code=MQX_SUPPORT

Other possible solution:

You can create your own partition on SD card and write image file directly into this partition – without formatting for file system. In that case you don’t need to take care about fragmentation and you can simply read this partition like any other file…

I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

755 Views
小勇邹
Contributor II

Dear RadekS,

Thank you for your help.

Yes,the boot loader should be small in my application.

I write a new solution according to your advice.

1. The SD card is partitioned to two parts in the widows 7.The firmware files is stored in the part 1 and the part 2 is empty.

2. The user application opens the files from the part 1 and decides which firmware to be updated.Then the user application use the simple SDHC driver without MFS to write the firmware to the specific sector in the part 2.

3. Get the data from specific sector in the boot loader without MQX and MFS.

Is there any problem for the solution?

Best regards.

Robin Zou.

Robin-XiaoYong Zou

ABB Xiamen Low Voltage Equipment Company Limited

BU LPLS E&D China

No. 12-20,3rd Chuang Xin Road Xiamen SEZ,Fujian 361006 P.R.China

CN

Phone: +86 592 5767877

Telefax: +86 592 6038110

Mobile: +86 181-5089-3720

email: robin-xiaoyong.zou@cn.abb.com<mailto:robin-xiaoyong.zou@cn.abb.com>

0 Kudos

755 Views
RadekS
NXP Employee
NXP Employee

Hi Robin,

You improved my first idea (copy file in MQX application). I thought that biggest issue will be loading firmware into empty partition on PC. On Linux it should be easy, on windows it could be challenge. On MQX it should be without any problem - by copy firmware file in MQX application we could avoid that possible issue.

Your proposal looks like simplest solution.

BTW: MQX contains bootloader application for Vybrid. You can use it as inspiration (for example in case of MD5 checksum, …).

I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

755 Views
小勇邹
Contributor II

Dear RadekS,

Thank you for your help.

I do not know how to use the simple SDHC driver without MFS to write the firmware to the empty part 2 in the MQX.

If using the simple SDHC driver without MFS, I have to find the start sector of empty part 2 first.

Do you have any example or suggestion?

“MQX contains bootloader application for Vybrid.” Can you tell me where I can find it?

Best regards.

Robin Zou.

Robin-XiaoYong Zou

ABB Xiamen Low Voltage Equipment Company Limited

BU LPLS E&D China

No. 12-20,3rd Chuang Xin Road Xiamen SEZ,Fujian 361006 P.R.China

CN

Phone: +86 592 5767877

Telefax: +86 592 6038110

Mobile: +86 181-5089-3720

email: robin-xiaoyong.zou@cn.abb.com<mailto:robin-xiaoyong.zou@cn.abb.com>

0 Kudos

755 Views
pavel_chromy
NXP Employee
NXP Employee

Dear Robin,

just open file "pm:2" (substitute partition manager device name for pm) to directly access second primary partition. You may write to it using ordinary write function (block devices in MQX are files, just like on UNIX systems). You may also use IOCTL command of the partition manager to get information about the partition (to obtain number of first sector). Please have a look at the MFS IO user's guide, partition manager IOCTL commands for details.

You may also sector 0 of the SDCARD and decode the partition table in the bootloader - I think this shall be pretty easy (much easier than decoding FAT). Please havae a look at the following link Master boot record - Wikipedia, the free encyclopedia.

0 Kudos

755 Views
RadekS
NXP Employee
NXP Employee

Hi Robin and Pavel,

I tested write into partition on MQX 4.2 – It works.

Unfortunately we cannot simply use read()/write() functions directly. It is necessary handle additional code due to BLOCK_MODE.

In this case we have to work with blocks of data (block size = device sector size). In my case (SD card) it was 512 bytes.

You can use part_mgr.c functions as inspiration…

Here is my test code:

char partition_name2[] = "pm:2";            

char               c;

uint32_t           count=512;

int32_t            offset=0;

int32_t            seek_mode=0;

_mqx_int           bi;

int32_t            writesize = 512;

char               *buf = NULL;

char               *buf2 = NULL;

_mqx_int           result;

                                  

                                /* Open partition */

partition_handle2 = fopen(partition_name2, NULL);

                                if (partition_handle != NULL)

                                {

printf("Opening partition 2...\n");

                                   

                                    /* Validate partition */

                                    error_code = _io_ioctl(partition_handle2, IO_IOCTL_VAL_PART, NULL);

                                    if (error_code != MFS_NO_ERROR)

                                    {

printf("Error validating partition: %s\n", MFS_Error_text((uint32_t)error_code));

continue;

                                    }

                  

                                  buf = _mem_alloc(writesize);

                                  buf2 = _mem_alloc(writesize);

                                 

                                                                                  /* generate data to buf */

                                                                                  c = '0';

                                          for (bi = 0; (bi < count) && (bi < writesize); bi++) {

                                              buf[bi] = c;

                                              c = (c == 'z') ? '0' : c+1;

                                          }

                                                 printf("Writing:\n");

                                                 printf("%s\n",buf);

//result = write(partition_handle2, buf, bi);

                                         result = write(partition_handle2, buf, 1); //please check BLOCK_MODE, DEV_SECTOR_SIZE,... in part_mgr.c

                                         if (result != 1) {

                                             /* incomplete write */

                                             printf("Error writing file.\n");

                                         }

printf("\nDone.\n");

                                           

                                     printf("Reading:\n");

fseek(partition_handle2, offset, IO_SEEK_SET);

                                     //result = read(partition_handle2, buf2, bi);

                                     result = read(partition_handle2, buf2, 1); //please check BLOCK_MODE, DEV_SECTOR_SIZE,... in part_mgr.c

                                     if (result != 1) {

                                                /* incomplete read */

                                                printf("Error writing file.\n");

                                     }

printf("%s\n",buf2);

  printf("\nDone.\n");

I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos