Flash loader readFlashDataPage(x)

New to XMOS and XCore? Get started here.
y0lo
Member
Posts: 12
Joined: Tue Sep 08, 2015 8:47 am

Flash loader readFlashDataPage(x)

Post by y0lo »

Hi,
I have a couple question about the function readFlashDataPage().
When we use this function maybe is it necessary to specify an additional parameter for "xcc"?
Does this function take an address or page number?

I try build the flash loader as it shown within xTIMEComposer User Guide:

loader.c:

Code: Select all

extern void* readFlashDataPage(unsigned int addr);

int dpVersion;
unsigned imgAdr;

void init(void) 
{
	dpVersion = *(unsigned int *)readFlashDataPage(0);
	imgAdr = 0;
}

int checkCandidateImageVersion(int v) 
{
	return  (v  == dpVersion);
}

void recordCandidateImage(int v, unsigned adr) 
{
	imgAdr = adr; 
}

unsigned reportSelectedImage(void) 
{
  return imgAdr;
}
make object file for loader:

Code: Select all

xcc -c loader.c -o loader.o 
I have two application: red blink - for factory and blue blink for second image.

Code: Select all

xflash --boot-partition-size 0x20000 --factory red_blink.xe --loader loader.o --upgrade 1 blue_blink.xe


then I read the flash, change the value at 0x20000 for "01 00 00 00" (I have tried as LSB and MSB) and write back this image to flash.

I expect that the second image (blue blink) should booting. But it didn't happen.
Any ideas?

PS
I use xTIMEComposer 14.1.0


y0lo
Member
Posts: 12
Joined: Tue Sep 08, 2015 8:47 am

Post by y0lo »

I found out:
-it works only for xTIMEcomposer 13.0.1
-readFlashDataPage(addr) - gets an absolute address from spi-flash with shift in 5 (!!!) bytes.
For exampe:
to read data from address 0x0F000 - readFlashDataPage(0x0F000 - 5)

WTF?!!
User avatar
larry
Respected Member
Posts: 275
Joined: Fri Mar 12, 2010 6:03 pm

Post by larry »

xTIMEcomposer user guide is wrong in that the flash is not ready in init(), so readFlashDataPage fails. In my testing, if I move my readFlashDataPage call to checkCandidateImageVersion, I can read the data partition ok. Address argument to readFlashDataPage is a word address, so data partition starts at 0x10000, argument is 0x4000. Data is written bit reversed and returned raw little-endian, so 01 00 00 00 is returned as 0x00000080.

I've attached my test code for your reference.
You do not have the required permissions to view the files attached to this post.