comparison Discovery/Src/externLogbookFlash.c @ 538:b1eee27cd02b

BugFix firmware downgrade to version with less settings: If a downgrade to a firmware version using less setting parameter were done then the settings had been reset to the default values. Root cause was that only increased number of settings was accepted by the read function. Because the layout of the setting structure is fixed (only bytes attached, no change in the order of data values) a downgrade just discarding the no longer used settings is possible => Updated read function to handle reduction of setting parameters.
author Ideenmodellierer
date Sat, 10 Oct 2020 13:51:44 +0200
parents 538eb1c976e9
children 2702bfa7b177
comparison
equal deleted inserted replaced
537:0ad0b26ec56b 538:b1eee27cd02b
566 * and loaded before calling this function 566 * and loaded before calling this function
567 */ 567 */
568 uint8_t ext_flash_read_settings(void) 568 uint8_t ext_flash_read_settings(void)
569 { 569 {
570 uint8_t returnValue = HAL_BUSY; 570 uint8_t returnValue = HAL_BUSY;
571 uint8_t exit = 0;
571 uint8_t *pData; 572 uint8_t *pData;
572 const uint16_t lengthStandardNow = sizeof(SSettings); 573 const uint16_t lengthStandardNow = sizeof(SSettings);
573 uint8_t length_lo, length_hi; 574 uint8_t length_lo, length_hi;
574 uint16_t lengthOnEEPROM; 575 uint16_t lengthOnEEPROM;
575 uint32_t header; 576 uint32_t header;
579 580
580 ext_flash_read_block_start(); 581 ext_flash_read_block_start();
581 ext_flash_read_block(&length_lo, EF_SETTINGS); 582 ext_flash_read_block(&length_lo, EF_SETTINGS);
582 ext_flash_read_block(&length_hi, EF_SETTINGS); 583 ext_flash_read_block(&length_hi, EF_SETTINGS);
583 584
584 while ((length_lo != 0xFF) && (length_hi != 0xFF)) /* get the latest stored setting block */ 585 while ((length_lo != 0xFF) && (length_hi != 0xFF) && (exit == 0)) /* get the latest stored setting block */
585 { 586 {
586 lengthOnEEPROM = length_hi * 256; 587 lengthOnEEPROM = length_hi * 256;
587 lengthOnEEPROM += length_lo; 588 lengthOnEEPROM += length_lo;
588 if(lengthOnEEPROM <= lengthStandardNow) 589 if(lengthOnEEPROM <= lengthStandardNow) /* EEPROM Header size equal or smaller => settings constant or upgraded */
589 { 590 {
590 ext_flash_read_block_multi(&header, 4, EF_SETTINGS); 591 ext_flash_read_block_multi(&header, 4, EF_SETTINGS);
591 if((header <= pSettings->header) && (header >= pSettings->updateSettingsAllowedFromHeader)) 592 if((header <= pSettings->header) && (header >= pSettings->updateSettingsAllowedFromHeader)) /* check to allow update of header */
592 { 593 {
593 returnValue = HAL_OK; 594 returnValue = HAL_OK;
594 pSettings->header = header; 595 pSettings->header = header;
595 pData = (uint8_t *)pSettings + 4; /* header */ 596 pData = (uint8_t *)pSettings + 4; /* header */
596 for(uint16_t i = 0; i < (lengthOnEEPROM-4); i++) 597 for(uint16_t i = 0; i < (lengthOnEEPROM-4); i++)
597 ext_flash_read_block(&pData[i], EF_SETTINGS); 598 ext_flash_read_block(&pData[i], EF_SETTINGS);
599 if(header != pSettings->header) /* setting layout changed => no additional setting sets expected */
600 {
601 exit = 1;
602 }
603 }
604 else
605 {
606 returnValue = HAL_ERROR;
607 exit = 1;
608 }
609 }
610 else /* size of settings decreased => possible downgrade of firmware */
611 {
612 ext_flash_read_block_multi(&header, 4, EF_SETTINGS);
613
614 if(header > 0xFFFF0014) /* verify that new (old) header should be compatible (only less bytes, no change in layout) */
615 {
616 returnValue = HAL_OK;
617 pSettings->header = header;
618 pData = (uint8_t *)pSettings + 4; /* header */
619 for(uint16_t i = 0; i < (lengthStandardNow-4); i++) /* only read the data fitting into the structure */
620 ext_flash_read_block(&pData[i], EF_SETTINGS);
598 } 621 }
599 else 622 else
600 { 623 {
601 returnValue = HAL_ERROR; 624 returnValue = HAL_ERROR;
602 } 625 }
626 exit = 1;
603 } 627 }
604 ext_flash_read_block(&length_lo, EF_SETTINGS); 628 ext_flash_read_block(&length_lo, EF_SETTINGS);
605 ext_flash_read_block(&length_hi, EF_SETTINGS); 629 ext_flash_read_block(&length_hi, EF_SETTINGS);
606 } 630 }
607 ext_flash_decf_address_ring(EF_SETTINGS); /* set pointer back to empty address */ 631 ext_flash_decf_address_ring(EF_SETTINGS); /* set pointer back to empty address */