Unstable partition API flashing functions

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: Unstable partition API flashing functions

Postby ESP_igrr » Fri Mar 24, 2017 2:21 am

Thanks for the stack dump, this confirms what we thought is the cause of this.

Could you please try adding this line into components/esp32/ld/esp32.common.ld, near line 88 (next to *libesp32.a:core_dump.o):

Code: Select all

*libesp32.a:heap_alloc_caps.o(.literal .text .literal.* .text.*)

imtiaz
Posts: 106
Joined: Wed Oct 26, 2016 1:34 am

Re: Unstable partition API flashing functions

Postby imtiaz » Fri Mar 24, 2017 2:41 am

Wow - its definitely fixed the crash ! However after my file download , it now seems to just freeze - I''ll dig further.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Unstable partition API flashing functions

Postby ESP_Angus » Fri Mar 24, 2017 2:44 am

Small update to Ivan's post, I was just able to reproduce the crash with Bluetooth+spi_flash and confirmed the same fix described above. I've updated the bugfix/spi_flash_lock_period branch on github.

Hopefully your OTA mechanism is almost at the working stage now!

Angus

imtiaz
Posts: 106
Joined: Wed Oct 26, 2016 1:34 am

Re: Unstable partition API flashing functions

Postby imtiaz » Fri Mar 24, 2017 3:06 am

Thats awesome , thanks for the great support and magik linker code :)

I had a function that verifies the downloaded file from the spi flash using MD5 which has always worked - and it just stopped working with the update - it just freezes now when you call it and after a while I get a WDT reset - do you guys have any idea what could be happening.

Code: Select all

/************************************************************
@Func:
@Inputs:
@Outputs:
*************************************************************/
static BOOL VerifyBinFileFromFlash(const esp_partition_t* p , size_t FileLen , unsigned char * FileHash)
{
	struct MD5Context MyMD5;
	unsigned char MyDigest[16];
	MD5Init(&MyMD5);
	uint32_t  FlashBuf[4];
	esp_err_t SpiErr = 0;
	//read 4 bytes at a time
	TRACE_D("Verifying  File MD5 Hash\n");
	if( FileLen % 4 != 0)
	{
		TRACE_D("Bad File Length \n");
		return False;
	}
	for(uint32_t i = 0 ; i!= FileLen ; i+=4)
	{
		 if( (SpiErr = esp_partition_read(p, i,FlashBuf, 4)) ==  ESP_OK)
		 {
			MD5Update(&MyMD5 , (unsigned char const*)FlashBuf , 4);
		 }
		 else
		 {
			 TRACE_D("FATAL : Error reading SPI flash \n");
			 return False;
		 }
	}
	MD5Final(MyDigest , &MyMD5);
	for(uint8_t i=0;i<16;i++)
	{
		printf("MD5 %d = Calc : %x , Rec : %x \n",i,MyDigest[i],FileHash[i]);
	}
	if(memcmp(MyDigest , FileHash , 16) == 0)
	{
		printf("File Hash Match \n");
		return True;
	}
	else
	{
		printf("File Hash MisMatch !!!!!!!!!!!! \n");
		return False;
	}
}

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Unstable partition API flashing functions

Postby ESP_Angus » Fri Mar 24, 2017 5:02 am

imtiaz wrote: I had a function that verifies the downloaded file from the spi flash using MD5 which has always worked - and it just stopped working with the update - it just freezes now when you call it and after a while I get a WDT reset - do you guys have any idea what could be happening.
Can you please post the exact output you get when it resets?

I wasn't able to reproduce a WDT running this code by itself, however this code is very slow (14 seconds to verify 1MB) so if it's running at high-ish priority then it may be starving out some other task and this is causing it to crash, or causing task watchdog to throw errors.

A faster way to accomplish the same goal is to use mmap:

Code: Select all

   spi_flash_mmap_handle_t handle;
   const void *image_data;
   esp_partition_mmap(p, 0, FileLen, SPI_FLASH_MMAP_DATA, &image_data, &handle);
   assert(image_data != NULL);
   MD5Update(&MyMD5 , image_data, FileLen);
   spi_flash_munmap(handle);

  MD5Final(MyDigest , &MyMD5);
This version takes approx 200ms for 1MB and produces the same result.

That said, I would still be very keen to investigate the crash you see with the other approach.

Angus

imtiaz
Posts: 106
Joined: Wed Oct 26, 2016 1:34 am

Re: Unstable partition API flashing functions

Postby imtiaz » Fri Mar 24, 2017 8:58 am

Thanks Angus - I'll send the exact wdt output tomorrow. Priority however of the task is 5 - so not high.

But yeah will swap to using memory map way - much faster.

imtiaz
Posts: 106
Joined: Wed Oct 26, 2016 1:34 am

Re: Unstable partition API flashing functions

Postby imtiaz » Fri Mar 24, 2017 9:44 am

Hi Angus,

Your code to calc the hash works awesomely well. However , here is the output when my md5 has code fails. I thought it was a WDT reset - but not sure now - anyway here you go
  • File Size : 970864
    Verifying File MD5 Hash
    Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception
    was unhandled.
    Register dump:
    PC : 0x40123c9a PS : 0x00060933 A0 : 0x8004b4fe A1 : 0x3f
    fc0b10
    0x40123c9a: r_platform_reset at ??:?
    A2 : 0x00000000 A3 : 0x40123c98 A4 : 0x00000000 A5 : 0x00
    000014
    0x40123c98: r_platform_reset at ??:?
    A6 : 0x3ffb93cc A7 : 0x3ffb8360 A8 : 0x80019fb8 A9 : 0x00
    0064bc
    A10 : 0x0000a55a A11 : 0x0000a55a A12 : 0x00000000 A13 : 0x00
    000020
    A14 : 0x000022e4 A15 : 0x3ffb8360 SAR : 0x00000000 EXCCAUSE: 0x00
    000000
    EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00
    000000

    Backtrace: 0x40123c9a:0x3ffc0b10 0x4004b4fe:0x3ffc0b40 0x40048569:0x3ffc0b70 0x4
    0048675:0x3ffc0b90 0x40054ed9:0x3ffc0bb0 0x40082bd6:0x3ffc0bd0 0x40081431:0x3ffc
    0c00
    0x40123c9a: r_platform_reset at ??:?
    0x40082bd6: r_rwbtdm_isr_wrapper at intc.c:?
    0x40081431: _xt_lowint1 at xtensa_vectors.o:?

    Entering gdb stub now.
    Guru Meditation Error of type IllegalInstruction occurred on core 0. Exception
    was unhandled.
    Register dump:
    PC : 0x400d3d06 PS : 0x00060033 A0 : 0x80085be0 A1 : 0x3f
    fc09b0
    0x400d3d06: esp_gdbstub_panic_handler at C:/esp32/esp-idf/components/esp32/gdbst
    ub.c:348
    A2 : 0x3ffc0a50 A3 : 0x00000017 A4 : 0x3ffc0ab0 A5 : 0x00
    000018
    A6 : 0x00000003 A7 : 0x00060523 A8 : 0x80085a5c A9 : 0x3f
    fc0990
    A10 : 0x00000018 A11 : 0x00000018 A12 : 0x3ffc0c00 A13 : 0x3f
    fc0a10
    A14 : 0x3ffc21c0 A15 : 0x3ffc21cc SAR : 0x0000001f EXCCAUSE: 0x00
    000000
    EXCVADDR: 0x00000000 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0x00
    000000

    Backtrace: 0x400d3d06:0x3ffc09b0 0x40085be0:0x3ffc0a30 0x400811cd:0x3ffc0a50 0x4
    0123c9a:0x3ffc0b10 0x40123c9a:0x3ffc0b40 0x40048569:0x3ffc0b70 0x40048675:0x3ffc
    0b90 0x40054ed9:0x3ffc0bb0 0x40082bd6:0x3ffc0bd0 0x40081431:0x3ffc0c00
    0x400d3d06: esp_gdbstub_panic_handler at C:/esp32/esp-idf/components/esp32/gdbst
    ub.c:348
    0x40085be0: xt_unhandled_exception at C:/esp32/esp-idf/components/esp32/panic.c:
    444
    0x400811cd: _xt_user_exc at xtensa_vectors.o:?
    0x40123c9a: r_platform_reset at ??:?
    0x40123c9a: r_platform_reset at ??:?
    0x40082bd6: r_rwbtdm_isr_wrapper at intc.c:?
    0x40081431: _xt_lowint1 at xtensa_vectors.o:?

    imtiaz
    Posts: 106
    Joined: Wed Oct 26, 2016 1:34 am

    Re: Unstable partition API flashing functions

    Postby imtiaz » Sun Mar 26, 2017 10:21 pm

    Hi @ESP_Angus , @ESP_igrr,

    With the last updates on the branch "spi_flash_lock_period"- everything is more stable. I am still finding that every once in a a while - maybe 1/10 times - The esp32 access point just drops off. Sometimes it comes back other times it doesn't.

    I think its something to do with the BL co - existence but thats purely guesswork.

    Also when the access point drops off there is no notification from the underlying software and if you call esp_wifi_get_mode() it still says WIFI_MODE_AP. However I can see using my PC and with android phone running "wifi network analyszer"that the AP is no longer there.

    Thanks
    Imtiaz

    ESP_Angus
    Posts: 2344
    Joined: Sun May 08, 2016 4:11 am

    Re: Unstable partition API flashing functions

    Postby ESP_Angus » Mon Mar 27, 2017 6:11 am

    Thanks Imtiaz.

    Regarding the Illegal Instruction exception crash, thanks for the crash dump it's extremely helpful. We're looking into that now.

    The bugfix/spiflash_lock_period branch is in the process of being merged and should appear in Github master branch very soon.

    Regarding the AP disappearing, I'll try to reproduce this. As a workaround (and additional diagnostic information), can you please try increasing the "FreeRTOS Timer Task Priority" (under Components -> FreeRTOS in menuconfig) from 1 to 6, so timers run at a higher priority than your OTA task?


    Angus

    imtiaz
    Posts: 106
    Joined: Wed Oct 26, 2016 1:34 am

    Re: Unstable partition API flashing functions

    Postby imtiaz » Tue Mar 28, 2017 12:07 am

    Hi Angus,

    I am not sure how to increase the free rtos timer priority . In menuconfig all I can do is change from timer 0 (level 1) to timer 1 (level 3) .. or are you talking about changing code directly?

    Who is online

    Users browsing this forum: Baidu [Spider] and 123 guests