readFlashDataPage in bootloader with tools 13.2

Technical questions regarding the xTIMEcomposer, xSOFTip Explorer and Programming with XMOS.
User avatar
Redrat
Member++
Posts: 20
Joined: Wed Feb 04, 2015 10:14 am

readFlashDataPage in bootloader with tools 13.2

Postby Redrat » Mon Mar 27, 2017 9:56 am

Hello,

I'm having trouble using readFlashDataPage in the flashloader with tools 13.2.

In init() it doesn't seem to work at all and always returns null; viewtopic.php?f=26&t=5053 suggested using the bootsize as the offset but that didn't work either.

viewtopic.php?p=20090&sid=aeda5cc69c4ff8105f14f115ea753b6e#p20090 says it doesn't work in init() and that it should instead be called in checkCandidateImageVersion(), however if i do this the loader hangs and no image is loaded at all.

So what is the correct way to use it, or is it not properly supported in 13.2?

Thanks,
Red.

Edit:
For reference I'm using a XS1-U12A <--> XS1-L6A
I see the same behaviour with tools 14.2 too.
User avatar
Sebastian
Member++
Posts: 26
Joined: Wed Jul 20, 2016 9:15 am

Postby Sebastian » Tue Mar 28, 2017 9:26 am

Hello red,

one important thing is, that
readFlashDataPage
reads with an absolute address.

Here is my code wich works on an XEF232 and 14.2.4
Maybe it will help you

Code: Select all

#include <xs1.h>
#include <platform.h>

/**************************************************************
if checkCandidateImageVersion reported no image of INTERREST,
the bootloader will load the factory image.
***************************************************************/

// we use 1.5Mb for images and rest for data + 1 Page of Data
#define BOOT_PARTITON_SIZE 0x181000

/*we could read the data partition of our flash drive*/
extern void * unsafe readFlashDataPage(unsigned addr);

/* Store the version of the image in memory that will potentially be booted */
int candidateImageVersion = -1;
unsigned candidateImageAddress;
int pin = 0;

/*Button for reading factory default */
//in port p_switch = on tile[0]: XS1_PORT_1P;
on tile[0]: in port p_switch = XS1_PORT_1P;

/* init is the first function called by the bootloader */
void init(void)
{

   /*
   data[0] = 0x12;
   data[1] = 0x11;
   data[2] = 0x11;
   data[3] = 0x11;

   fl_writeData(0, 4, data, preserve_data_buffer);

   image = *(int*)readFlashDataPage(BOOT_PARTITON_SIZE); //1.5MByte Image storage

   !!!!!   image contains now 0x11111121;  !!!!
  */
  unsafe{
    p_switch :> pin;
    if(pin)
      candidateImageVersion = 0; // load factory version;
    else
      candidateImageVersion = *(int * unsafe)readFlashDataPage(BOOT_PARTITON_SIZE); //1.5MByte Image storage
  }
}

int checkCandidateImageVersion(int imageVersion)


  if(candidateImageVersion > -1 && candidateImageVersion == imageVersion)
     return 1;
  else
     return 0;
}

void recordCandidateImage(int imageVersion, unsigned imageAddress)
{
    candidateImageVersion = imageVersion;
    candidateImageAddress = imageAddress;
}

unsigned reportSelectedImage(void){
 return candidateImageAddress;
}



Sebastian
User avatar
Redrat
Member++
Posts: 20
Joined: Wed Feb 04, 2015 10:14 am

Postby Redrat » Wed Mar 29, 2017 10:51 am

Hi Sebastian,

Thanks for the help but I was trying with the absolute address.

Here's the loader I'm currently trying to get to work;

Code: Select all

#include <xs1.h>
#include <platform.h>
#include <stdio.h>

extern void * unsafe readFlashDataPage ( unsigned addr );

int keptVersion;
unsigned int keptAddress;
unsigned int bootFactory;
#define BOOT_PARTITON_SIZE 0x80000

void init( void ){
    unsafe{
        bootFactory =  *(unsigned int * unsafe)readFlashDataPage (BOOT_PARTITON_SIZE);
    }
    keptAddress=0;
}

int checkCandidateImageVersion( int v ){
  // this is a good version if we don't yet have an address
  // or if we are not booting from factory and the version is
  // greater than or equal to the kept version.

  return ( keptAddress == 0 ) || ( !bootFactory && v >= keptVersion );
}

void recordCandidateImage( int v, unsigned int address ){
  // we don't record the version if the kept address is still 0
  // as this is assumed to be the factory image version
  // and is therefore independent of the "upgrade" versions.
  if ( keptAddress != 0 ) {
    keptVersion = v;
  }

  // record the candidate address.
  keptAddress = address;
}


unsigned int reportSelectedImage( void ){
  // return what we found, should be at least one as the factory image
  // will be recorded.
  return keptAddress;
}


and flashing the device with this command line:

Code: Select all

xflash --loader src/loader.xc --spi-spec src/sst26vf064b.h --boot-partition-size 0x80000 --factory bin/Release/RRX_Factory.xe --upgrade 24 RRX_Main.024.xe --data src/data.dat

Who is online

Users browsing this forum: No registered users and 1 guest