More Working with LibFlash

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
aleonard
Member
Posts: 15
Joined: Thu Sep 16, 2010 8:19 pm

More Working with LibFlash

Post by aleonard »

For my project, I'd like to store a number of parameters in Flash memory. I'm currently using the XC-2 development board, but am planning to port the project to a custom system in the near future.

First a question about how libflash works:
I queried fl_getFactoryImage() and found that the "factory" image size corresponds to the current code image that I wrote to the device.
From this forum http://www.xcore.com/forum/viewtopic.ph ... t=libflash, the start location of the data partition is stored in the beginning of the flash by xflash.
How is the start location of the Data Partition computed by xflash? One might assume that it would start after the last image partition ( in this case just the factory image). If this is true, what happens if the code expands and we write a larger factory image? How would one then keep a constant reference for the Data Partition to retrieve stored parameters?

Second, I am having trouble getting the libflash functions to work as expected. I can successfully run the following functions:
fl_connect()
fl_getFlashType()
fl_getFlashSize()
fl_getFactoryImage()
These all return successfully with valid data.

But the following other functions fail:
fl_getDataPartitionSize()
fl_getNumDataSectors()
fl_getWriteScratchSize()
fl_writeData()

Here is the code I am using to test:

Code: Select all

int DatSize, Success[4], i;
	unsigned sizes[4];
	unsigned char DatBuffer[RAW_ARRAY_MAX], dummy[4096];
	fl_BootImageInfo finfo;

	Success[0] = fl_connect(spiPorts);//ToDevice(spiPorts, devs, 2);
	Success[1] = fl_getFlashType();
	Success[2] = fl_getFactoryImage(finfo);

	sizes[0] = fl_getFlashSize();

	sizes[1] = fl_getDataPartitionSize();
	sizes[2] = fl_getNumDataSectors();
	sizes[3] = fl_getWriteScratchSize(0, 8192);
	
	/////Code initializing DatBuffer and DatSize here////
	Success[3] = fl_writeData(0, DatSize, DatBuffer, dummy);


Is there some kind of setup I need to do to activate the Data Partition? Or something else I'm missing? (clearly)

Thanks for any insight.


bearcat
Respected Member
Posts: 283
Joined: Fri Mar 19, 2010 4:49 am

Post by bearcat »

Have a look at Chapter 14 in the tools user guide for the options of the xflash command line utility.

I believe you need to specify the boot partition size so there is room for a data partition. It appears to default to the full size of the flash device, therefore leaving no room for a data partition.
User avatar
aleonard
Member
Posts: 15
Joined: Thu Sep 16, 2010 8:19 pm

Post by aleonard »

Thanks for the reply. It took me a couple days to notice it for some reason...

I did read through the tools user guide quite a few times before posting in the forum. Going off your suggestion, I tried to use fl_startImageReplace(), hoping this might allow me to set the size of the boot partition. Unfortunately, this function just stalls indefinitely.

Also tried fl_startImageAdd(), but this fails immediately.

There must be a way to set the sizes of the boot and data partitions. I'm sure I'm missing something key. I submitted a support ticket with the issue and I'll post here with any successful results.
bearcat
Respected Member
Posts: 283
Joined: Fri Mar 19, 2010 4:49 am

Post by bearcat »

I was thinking that you would use XFLASH to initally set the partition sizes and write a first image. Then use the libflash library in firmware to write the data partition or firmware updates.

You would have to program the flash initially somehow with either XFLASH thru JTAG, or an external programmer.
User avatar
aleonard
Member
Posts: 15
Joined: Thu Sep 16, 2010 8:19 pm

Post by aleonard »

Ah yes. This is the answer. You set the boot partition size through XFLASH.

You can set the boot partition size through the XDEV flash programmer interface. Or you can run eg:

xflash app.xe --boot-partition-size 0x18000


this is the obvious/key thing I was missing.

Thanks!