cancel
Showing results for 
Search instead for 
Did you mean: 

Wi-Fi Combo

Anonymous
Not applicable

sflash_write error fix, SDKs -all.

Simple 2 lines error correction to resolve page write error at free address . This error I reported her: Possible OTA bug?

int sflash_write( const sflash_handle_t* const handle, unsigned long device_address, /*@observer@*/ const void* const data_addr, unsigned int size )

{

    int status;

    unsigned int write_size;

    unsigned int max_write_size = (unsigned int) 1;

    int enable_before_every_write = 1;

    const unsigned char* data_addr_ptr = (const unsigned char*) data_addr;

    unsigned char curr_device_address[3];

    uint8_t result;

    if ( handle->write_allowed != SFLASH_WRITE_ALLOWED )

    {

        return -1;

    }

    /* Some manufacturers support programming an entire page in one command. */

#ifdef SFLASH_SUPPORT_MACRONIX_PARTS

    if ( SFLASH_MANUFACTURER( handle->device_id ) == SFLASH_MANUFACTURER_MACRONIX )

    {

        max_write_size = (unsigned int) 128;  /* TODO: this should be 256, but that causes write errors */

        enable_before_every_write = 1;

    }

#endif /* ifdef SFLASH_SUPPORT_MACRONIX_PARTS */

#ifdef SFLASH_SUPPORT_SST_PARTS

    if ( SFLASH_MANUFACTURER( handle->device_id ) == SFLASH_MANUFACTURER_SST )

    {

        max_write_size = (unsigned int) 1;

        enable_before_every_write = 1;

    }

#endif /* ifdef SFLASH_SUPPORT_SST_PARTS */

#ifdef SFLASH_SUPPORT_EON_PARTS

    if ( SFLASH_MANUFACTURER( handle->device_id ) == SFLASH_MANUFACTURER_EON )

    {

        max_write_size = (unsigned int) 1;

        enable_before_every_write = 1;

    }

#endif /* ifdef SFLASH_SUPPORT_EON_PARTS */

#ifdef SFLASH_SUPPORT_MICRON_PARTS

    if ( SFLASH_MANUFACTURER( handle->device_id ) == SFLASH_MANUFACTURER_MICRON )

    {

        max_write_size = (unsigned int) 128;

        enable_before_every_write = 1;

    }

#endif /* ifdef SFLASH_SUPPORT_MICRON_PARTS */

    if ( enable_before_every_write == 0 )

    {

        status = sflash_write_enable( handle );

        if ( status != 0 )

        {

            return status;

        }

    }

    /* Generic x-bytes-at-a-time write */

    while ( size > 0 )

    {

        write_size = ( size > max_write_size )? max_write_size : size;

#if 1//darius, correcting write_size to properly write page block

        if( ( (device_address & 0xFF)+write_size-1) >= 0x100)

            write_size =  (unsigned long)0x100 -(device_address & 0xFF);

#endif

        curr_device_address[0] = (unsigned char) ( ( device_address & 0x00FF0000 ) >> 16 );

        curr_device_address[1] = (unsigned char) ( ( device_address & 0x0000FF00 ) >>  8 );

        curr_device_address[2] = (unsigned char) ( ( device_address & 0x000000FF ) >>  0 );

12 Replies
MichaelF_56
Moderator
Moderator

Thanks darius1

0 Likes
AxLi_1746341
Honored Contributor

mwf_mmfae wrote:

Thanks darius1

Do you review the code and confirm the change is correct?

I do appreciate darius1​'s work, but I hope someone from cypress can review the code and confirm if this change is correct or not.

user_2170816
New Contributor II

Is there any review update about that issue? I have tried 100+ trials with and without these 2 lines, but results were the same.

0 Likes
Anonymous
Not applicable

Hi.

This issue are critical if you using  spi flash chip with page write function - exmp.:  MACRONIX_PARTS  or MANUFACTURER_MICRON. I use MACRONIX. So, for me was big problem.

If you use  SFLASH_MANUFACTURER_SST or SFLASH_MANUFACTURER_EON  you can leave this fix or not.

What your spi flash chip?

0 Likes
user_2170816
New Contributor II

Hi,

Thank you for quick reply,

I am using WINBOND 25080 bla bla something.

0 Likes
Anonymous
Not applicable

WINBOND 25Q80 chip have page write function. So , I think, for you are critical.

AxLi_1746341
Honored Contributor

mwf_mmfae

The point is no one from cypress to review the patch post on the forum.

I don't know what's your meaning by marking this as helpful.

Is that a confirm this is a good fix? AFAICT, you deliver a confusing message.

0 Likes
MichaelF_56
Moderator
Moderator

Darius response was helpful.  I'm entitled to an opinion.

0 Likes
user_2170816
New Contributor II

darius1

What could be the reason to not make any difference between my tests with and without your fix? I tested over 100 times and all OTAs was successfull in two case.

0 Likes
Anonymous
Not applicable

Hi

Read this

Possible OTA bug?

After 7 update with new firmware file (each file bigger 4096 byte) your system will crash.

At 7 step new header address became xx 0xFE . Write to this address succses only 2 bytes other 32 bytes are writed into start of page... so your header became fail. After reboot bootloader load new corrupted data into your main application place  and crash...

Sdk not supported winbond.. so you must write support for this chip. What is max_write_size in your function sflash_write?

Note. After 9 step your system will crash anyway..

Other situation, which was for me - firmware update chunk size. I used chunk size 130 and writing into sflash was failed. If chunk size is 2^n then old fuction writing ok.

0 Likes
AxLi_1746341
Honored Contributor

Hi darius1​,

Thanks for point out this issue and provide the fix.

I think the issue is *valid*.

You change means a write cannot cross 2 pages, I think the fix is correct.

Thought I don't like the hardcoded 0x100 and 0xFF values, but it looks correct to me if the page size is 256.

Thanks,

Axel

0 Likes
Anonymous
Not applicable

Thank you for your review.

#if 1//

#define PAGE_SIZE 256

        if( ( (device_address %PAGE_SIZE )+write_size-1) >= PAGE_SIZE)

            write_size =  (unsigned long)PAGE_SIZE-(device_address %PAGE_SIZE);

#endif