FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [August 2017 Threads] +FAT how to create two partitions on SD cardPosted by spikeroot on August 4, 2017 I'm having a hard time figuring out how to do this. Here is my code, could you tell me what is wrong with it? ffconfigMAXPARTITIONS is set to 2, and the 2nd call to FFFormat is only finding 1 partition when it calls FF_PartitionSearch.
~~~
static FFDiskt Disks[ffconfigMAX_PARTITIONS];
static FFIOManagert * CreateIoManager(FFDiskt * pdisk)
{
FFCreationParameterst xParameters;
memset( &xParameters, '0', sizeof( xParameters ) );
xParameters.pxDisk = pdisk;
xParameters.pucCacheMemory = NULL;
xParameters.ulMemorySize = 1024;
xParameters.ulSectorSize = 512;
xParameters.fnWriteBlocks = prvFFWrite;
xParameters.fnReadBlocks = prvFFRead;
xParameters.xBlockDeviceIsReentrant = pdFALSE;
if (!xPlusFATMutex) xPlusFATMutex = xSemaphoreCreateRecursiveMutex();
ASSERTANDRETURN(xPlusFATMutex, NULL);
xParameters.pvSemaphore = ( void * ) xPlusFATMutex;
FF_Error_t err;
FF_IOManager_t * p_ioman = FF_CreateIOManger( &xParameters, &err );
ASSERT_AND_RETURN(p_ioman, NULL);
if (err != 0)
{
ffconfigFREE(p_ioman);
return NULL;
}
return p_ioman;
}
int FFSDDiskTwoPartitionFormat(void)
{
for (sizet i = 0; i < ffconfigMAXPARTITIONS; i++)
{
memset(&Disks[i], 0, sizeof(Disks[i]));
Disks[i].ulNumberOfSectors = RTEStorageGetBlockCount(RTESTORAGE_CARD);
Disks[i].pxIOManager = CreateIoManager(&Disks[i]);
if (!Disks[i].pxIOManager) return -1;
Disks[i].xStatus.bIsInitialised = pdTRUE;
Disks[i].xStatus.bPartitionNumber = i;
}
FF_PartitionParameters_t partitions;
memset( &partitions, 0x00, sizeof( partitions ) );
partitions.ulSectorCount = RTE_Storage_GetBlockCount(RTE_STORAGE_CARD);
partitions.ulHiddenSectors = 0;
partitions.ulInterSpace = 0;
partitions.xPrimaryCount = 2; // ????
partitions.eSizeType = eSizeIsPercent;
partitions.xSizes[0] = partitions.xSizes[1] = 50;
FF_Error_t partition_err = FF_Partition(&Disks[0], &partitions);
if (partition_err != FF_ERR_NONE) return -1;
for (size_t i = 0; i < ffconfigMAX_PARTITIONS; i++)
{
FF_Error_t format_err = FF_Format(&Disks[i], i, pdFALSE, pdFALSE);
if (format_err != FF_ERR_NONE) return -1;
}
return 0;
}
~~~
+FAT how to create two partitions on SD cardPosted by rtel on August 7, 2017 Is this a different topic to this thread: https://sourceforge.net/p/freertos/discussion/382005/thread/4874bbe8/ ?
+FAT how to create two partitions on SD cardPosted by heinbali01 on August 7, 2017 The topics are indeed quite similar.
Before answering, I will try-out the above code on an SD-card
+FAT how to create two partitions on SD cardPosted by heinbali01 on August 7, 2017 PS. please check all return codes from the library calls and it may also useful to define FF_PRINTF , in order to see the internal logging of FreeRTOS+FAT.
I'm still playing with it and I'll report later.
+FAT how to create two partitions on SD cardPosted by spikeroot on August 7, 2017 My code is checking all return values. The second call to FF_Format is returning 0x86000010.
I also have FF_PRINTF defined, and here is the output:
FFFormat: Secs 124868608 Rsvd 32 Hidden 0 Root 0 Data 124868576
FFFormat: SecCluster 64 DatSec 124838016 DataClus 1950594 ulClusterBeginLBA 30592
FFFormat: Clearing entire FAT (2 x 15240 sectors):
FFFormat: Clearing done
FFFormat: Clearing root directory at 00007780: 64 sectors
FFPart: no partitions, try as PBR
FFPart: no partitions, try as PBR
FFPart: no partitions, try as PBR
prvDetermineFatType: firstWord 0000FFF8
+FAT how to create two partitions on SD cardPosted by heinbali01 on August 7, 2017 I'm working on it, about one hour to go :-)
+FAT how to create two partitions on SD cardPosted by spikeroot on August 7, 2017 Thanks! Appreciate your responsive support on this forum.
+FAT how to create two partitions on SD cardPosted by heinbali01 on August 7, 2017 Hi Michael, the biggest problem with your code was this line:
~~~
partitions.ulHiddenSectors = 0;
~~~
As a consequence, the boot sector 0 got overwritten while formatting partition 0.
The meaning of partitions.ulHiddenSectors is: the offset where the BPR ( Partition Boot Record ) shall be stored.
I will add a configASSERT() , to flag this off in future releases.
There were some other issues, like not settings the signature:
~~~
pxDisks[ i ]->ulSignature = sdSIGNATURE;
~~~
As multiple partitions are rarely used, the documentation about this feature is maybe not optimal. We're sorry about this.
Here below you find an attachment called format_partitions.c that I used for testing.
Please tell us how it goes. Thanks, Hein
+FAT how to create two partitions on SD cardPosted by heinbali01 on August 7, 2017 Another thing that I changed was:
~~~
- xParameters.ulMemorySize = 1024;
+ xParameters.ulMemorySize = 3072; // 1024;
~~~
This is the amount of cache memory per I/O handler. Recently there was a question about the "optimal" size of this cache memory. I found that at most 9 sector buffers were being used simultaneously in a busy application:
https://sourceforge.net/p/freertos/discussion/382005/thread/ea301981/?limit=250#3a53
So this would be safer:
~~~
xParameters.ulMemorySize = 9 * 512;
~~~
If you have a single task that makes use of FreeRTOS+FAT, the size of the caching memory may be less.
+FAT how to create two partitions on SD cardPosted by spikeroot on August 9, 2017 I've incorporated your suggestions and am now successfully partitioning my SD card. But now my problem is that Windows won't read the second partition. I can see it through the disk management console, but I can't actually access it. Apparently (and I wish I'd known this before) Windows just doesn't recognize multiple partitions on a removable drive. I found a couple workarounds that involved installing a hacked-together driver to make windows see it as a non-removable drive, but only ended up causing Windows to run its "Repair Windows" utility upon restarting and re-install the old driver.
Do you have any other suggestions for accessing the second partition?
Link to my original question about being able to access all partitions: https://sourceforge.net/p/freertos/discussion/382005/thread/4874bbe8/
+FAT how to create two partitions on SD cardPosted by heinbali01 on August 9, 2017
Do you have any other suggestions for accessing the second partition?
Yes I do, use Linux :-)
I just checked my SD-card under ubuntu. It shows the two partitions created by FreeRTOS+FAT. I see their contents and I can write to them.
Also running the file check program showed success:
~~~
root@myubuntu:~# fsck.vfat /dev/sdb1
fsck.fat 3.0.28 (2015-05-16)
/dev/sdb1: 6 files, 6/123381 clusters
root@myubuntu:~# fsck.vfat /dev/sdb2
fsck.fat 3.0.28 (2015-05-16)
/dev/sdb2: 3 files, 3/123381 clusters
~~~
My W10 only sees a single partition.
+FAT how to create two partitions on SD cardPosted by heinbali01 on August 9, 2017
My W10 only sees a single partition.
With W10, of course I mean Windows-10.
Also when I try to (re-)format the SD-card it will only see the first partition, i.e. it only sees 50% of the actual disk size.
+FAT how to create two partitions on SD cardPosted by spikeroot on August 9, 2017 Linux might be an option if I were the user of my product. Unfortunately, I need to make it work for Windows users.
My original question was whether I'd be able to access all partitions from Windows. Apparently the answer should have been "no." I understand now that this limitation is inherent in Windows.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|