Page 1 of 1

Reading core dump from flash

Posted: Tue Apr 16, 2019 10:55 am
by Ian777
Hey everyone,

I wrote the following portion of code to read the coredump from flash:

Code: Select all

oid coreD(void){
 
    const esp_partition_t *pt = NULL;
    size_t bytestoread = 256;
    size_t bytesread = 0;
    char str_dst[256];
 
    pt = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_COREDUMP, "coredump");
 
    if (pt != NULL)
    {
        size = pt->size;
        printf("POINTER IS NOT NULL \n");
 
        while(bytestoread > 0)
        {
            printf("STARTING PARTION READ \n");
            printf("Remaining partition size : %zu \n",size);
 
            esp_err_t er = esp_partition_read(pt, bytesread ,str_dst, bytestoread);
 
            printf("PARTITION READ \n");
            printf("%s",str_dst);
 
            if (er != ESP_OK)
            {
                printf("READ IS NOT OK!\n");
                ESP_LOGE(TAG,"Partition read error : %s", esp_err_to_name(er));
                return ;
            }
 
            else if (er == ESP_OK)
            {
                printf("\n READ IS OK!\n");
                bytesread = bytesread +256;
                size = size - 256;
 
                if(size <= 256)
                {
                    bytestoread = size;
                }
            }
        }
    }
}
This seems to be perfectly fine in my opinion although it returns the following:

Code: Select all

TARTING PARTION READ
PARTITION READ
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒@READ IS OK!
STARTING PARTION READ
PARTITION READ
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒@READ IS OK!
STARTING PARTION READ
PARTITION READ
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒@READ IS OK!
Anyone know what could be causing this?

I'm executing it like this:

Code: Select all

void app_main()
{
    
    extern struct tm timeinfo;
    extern char strftime_buf[64];
    
    
    char buf[30];
    //define variables for determining wakeup time
    int TfutH = 17+15;
    int TfutM = 60;
    int TfutS = 60;
    uint64_t TdiffH;
    uint64_t TdiffM;
    uint64_t TdiffS;
    uint64_t Tdiff;
    //allocate memory to the heap
    char* datep = (char*)malloc(sizeof(char)*(sizeof(buf)+1));
    if(datep == NULL){
        abort();
    }
    void* work = NULL;
    work = ff_memalloc(FF_MAX_SS);
    if(work == NULL){
        abort();
    }
    char* test = malloc((74)*sizeof(char));
    if(test == NULL){
        abort();
    }
    char* location = malloc(50*sizeof(char));
    if(location == NULL){
        abort();
    }
    char* errorcond = (char*)malloc(sizeof(char) * 40);
    if(errorcond == NULL){
        abort();
    }
    size_t ersize = sizeof(errorcond);
    
    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK(ret);
    //initialize wifi and wait for it to be connected
    app_wifi_initialise();
    app_wifi_wait_connected();
    coreD();
    abort();
    ...
    ...
    ...
    }
    
The abort call after coreD generates the coredump for testing purposes.
I've also tried running coreD prior to initializing the flash with the same result.

Any help will really be appreciated

Re: Reading core dump from flash

Posted: Tue Apr 16, 2019 11:42 am
by WiFive
Core dump is binary data it won't print as a readable string. Core dump for uart base64 encodes the data before printing.

Re: Reading core dump from flash

Posted: Tue Apr 16, 2019 9:20 pm
by Ian777
Hi WiFive,

Thank you, I got it going. Seemed to be more of how I was interpreting it on the server than what the esp was doing.

I have another question, Once I finished reading the core dump, I'd like to erase it.

so I find my core dump partition using the following:

Code: Select all

  pt = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_COREDUMP, "coredump");
To erase the flash I've tried the following:

Code: Select all

er = esp_partition_erase_range(pt,pt->address,pt->size);
Which is how I understood the function should be used from the docs,although it returns an error, namely : ESP_ERR_INVALID_ARG

So I went through the forum and saw people were using it as :

Code: Select all

er = esp_partition_erase_range(pt,0,pt->size);
This returns ESP_OK but sadly the core dump isn't erased. If i reset the ship or enter and exit deepsleep the coredump is found and reread. Is there something I'm doing wrong with this function?

Thank you in advance for any help

Re: Reading core dump from flash

Posted: Wed Sep 29, 2021 2:32 pm
by master_mac
Hi, were you able to solve it?

Re: Reading core dump from flash

Posted: Sat May 04, 2024 4:28 pm
by WildPointer
Hello Ian777,
Could you please share how you interpreted the data?
I am having the same issues. I would like to print the core dump as readable characters from flash.

Thanks