Hi,
I want to make my bootloader reading a flash data from address 0x40000
and due to its value load corresponding version. So, I have the following code of custom loader:
extern void* readFlashDataPage(unsigned int addr);
unsigned int dpVersion;
unsigned int imgAddr;
void init(void)
{
unsigned int* page = (unsigned int*)readFlashDataPage(0x40000);
dpVersion = (page[0] == 0x00000002) ? 1 : 2;
}
int checkCandidateImageVersion( int version )
{
return dpVersion == version;
}
void recordCandidateImage( int version, unsigned int address )
{
imgAddr = address;
}
unsigned int reportSelectedImage(void)
{
return imgAddr;
}
But it seems doesn't work, there is version 1 is always loaded.
I can guess that I put incorrect address for readFlashDataPage() function,
but I tried to use 0x40000 and 1024 (block number), all the same.
Any ideas?
P.S.> I put 0x00000002 value with offset 0x40000 to the flash, and I also tried to revert
bits in comparision condition:
dpVersion = (page[0] == 0x40000000) ? 1 : 2;
Version 1 is loaded without any problems if I use next expression:
dpVersion = 1;
What is the right value for readFlashDataPage(x) function? I
-
- Junior Member
- Posts: 6
- Joined: Wed Sep 04, 2013 1:45 pm
-
Verified
- XCore Legend
- Posts: 1163
- Joined: Thu Dec 10, 2009 9:20 pm
- Location: Bristol, UK
My understanding from the source code is page number (see below). Note the addition of the dataPartitionBase though!
int fl_readDataPage(unsigned n, unsigned char dst[])
{
unsigned address;
if( n >= fl_getNumDataPages() ) { return( 1 ); }
address = fl_getDataPartitionBase() + n * fl_getPageSize();
return fl_readPage(address, dst);
}
int fl_readDataPage(unsigned n, unsigned char dst[])
{
unsigned address;
if( n >= fl_getNumDataPages() ) { return( 1 ); }
address = fl_getDataPartitionBase() + n * fl_getPageSize();
return fl_readPage(address, dst);
}
Technical Director @ XMOS. Opinions expressed are my own