159
159
#include " ../lcd/extui/dgus/DGUSDisplayDef.h"
160
160
#endif
161
161
162
- #ifdef EEPROM_CHECK_BUILD_COUNT
163
- #include " ../../Build_Count.h"
164
- #endif
165
-
166
162
#pragma pack(push, 1) // No padding between variables
167
163
168
164
#if HAS_ETHERNET
@@ -195,8 +191,8 @@ static const feedRate_t _DMF[] PROGMEM = DEFAULT_MAX_FEEDRATE;
195
191
*/
196
192
typedef struct SettingsDataStruct {
197
193
char version[4 ]; // Vnn\0
198
- #if ENABLED(EEPROM_CHECK_BUILD_COUNT )
199
- uint8_t build_count ;
194
+ #if ENABLED(EEPROM_INIT_NOW )
195
+ uint32_t build_hash ;
200
196
#endif
201
197
uint16_t crc; // Data Checksum
202
198
@@ -638,8 +634,12 @@ void MarlinSettings::postprocess() {
638
634
#endif
639
635
640
636
const char version[4 ] = EEPROM_VERSION;
641
- #if ENABLED(EEPROM_CHECK_BUILD_COUNT)
642
- const uint8_t build_count = BUILD_COUNT;
637
+
638
+ #if ENABLED(EEPROM_INIT_NOW)
639
+ constexpr uint32_t strhash32 (const char *s, char c=' \0 ' , uint32_t h=0 ) {
640
+ return *s ? strhash32 (s + 1 , *s, (((h << 1 ) | (h >> 31 )) ^ c)) : h;
641
+ }
642
+ constexpr uint32_t build_hash = strhash32(__DATE__ __TIME__);
643
643
#endif
644
644
645
645
bool MarlinSettings::eeprom_error, MarlinSettings::validating;
@@ -648,7 +648,11 @@ void MarlinSettings::postprocess() {
648
648
649
649
bool MarlinSettings::size_error (const uint16_t size) {
650
650
if (size != datasize ()) {
651
- DEBUG_ERROR_MSG (" EEPROM datasize error. Size " ,size," datasize " ,datasize ());
651
+ DEBUG_ERROR_MSG (" EEPROM datasize error."
652
+ #if ENABLED(MARLIN_DEV_MODE)
653
+ " (Actual:" , size, " Expected:" , datasize (), " )"
654
+ #endif
655
+ );
652
656
return true ;
653
657
}
654
658
return false ;
@@ -660,20 +664,19 @@ void MarlinSettings::postprocess() {
660
664
bool MarlinSettings::save () {
661
665
float dummyf = 0 ;
662
666
char ver[4 ] = " ERR" ;
663
- #if ENABLED(EEPROM_CHECK_BUILD_COUNT)
664
- uint8_t build_count;
665
- #endif
667
+
666
668
if (!EEPROM_START (EEPROM_OFFSET)) return false ;
667
669
668
670
eeprom_error = false ;
669
671
670
672
// Write or Skip version. (Flash doesn't allow rewrite without erase.)
671
673
TERN (FLASH_EEPROM_EMULATION, EEPROM_SKIP, EEPROM_WRITE)(ver);
672
674
673
- #if ENABLED(EEPROM_CHECK_BUILD_COUNT )
674
- EEPROM_SKIP (build_count ); // Skip the build_count slot
675
+ #if ENABLED(EEPROM_INIT_NOW )
676
+ EEPROM_SKIP (build_hash ); // Skip the hash slot
675
677
#endif
676
- EEPROM_SKIP (working_crc); // Skip the checksum slot
678
+
679
+ EEPROM_SKIP (working_crc); // Skip the checksum slot
677
680
678
681
working_crc = 0 ; // clear before first "real data"
679
682
@@ -1476,8 +1479,8 @@ void MarlinSettings::postprocess() {
1476
1479
eeprom_index = EEPROM_OFFSET;
1477
1480
1478
1481
EEPROM_WRITE (version);
1479
- #if ENABLED(EEPROM_CHECK_BUILD_COUNT )
1480
- EEPROM_WRITE (BUILD_COUNT );
1482
+ #if ENABLED(EEPROM_INIT_NOW )
1483
+ EEPROM_WRITE (build_hash );
1481
1484
#endif
1482
1485
EEPROM_WRITE (final_crc);
1483
1486
@@ -1511,33 +1514,31 @@ void MarlinSettings::postprocess() {
1511
1514
1512
1515
char stored_ver[4 ];
1513
1516
EEPROM_READ_ALWAYS (stored_ver);
1514
- #if ENABLED(EEPROM_CHECK_BUILD_COUNT)
1515
- uint8_t stored_build_count;
1516
- EEPROM_READ_ALWAYS (stored_build_count);
1517
- #endif
1518
-
1519
-
1520
- uint16_t stored_crc;
1521
- EEPROM_READ_ALWAYS (stored_crc);
1522
1517
1523
1518
// Version has to match or defaults are used
1524
- if (( strncmp (version, stored_ver, 3 ) != 0 ) || TERN0 (EEPROM_CHECK_BUILD_COUNT,(stored_build_count != BUILD_COUNT)) ) {
1519
+ if (strncmp (version, stored_ver, 3 ) != 0 ) {
1525
1520
if (stored_ver[3 ] != ' \0 ' ) {
1526
1521
stored_ver[0 ] = ' ?' ;
1527
1522
stored_ver[1 ] = ' \0 ' ;
1528
1523
}
1529
-
1530
- #if ENABLED(EEPROM_CHECK_BUILD_COUNT)
1531
- DEBUG_ECHO_MSG (" EEPROM version mismatch (EEPROM=" , stored_ver, " ." ,stored_build_count , " Marlin=" EEPROM_VERSION " ." , BUILD_COUNT," )" );
1532
- #else
1533
- DEBUG_ECHO_MSG (" EEPROM version mismatch (EEPROM=" , stored_ver, " Marlin=" EEPROM_VERSION " )" );
1534
- #endif
1524
+ DEBUG_ECHO_MSG (" EEPROM version mismatch (EEPROM=" , stored_ver, " Marlin=" EEPROM_VERSION, " )" );
1535
1525
TERN_ (DWIN_CREALITY_LCD_ENHANCED, LCD_MESSAGE (MSG_ERR_EEPROM_VERSION));
1536
1526
1537
1527
IF_DISABLED (EEPROM_AUTO_INIT, ui.eeprom_alert_version ());
1538
1528
eeprom_error = true ;
1539
1529
}
1540
1530
else {
1531
+
1532
+ // Optionally reset on the first boot after flashing
1533
+ #if ENABLED(EEPROM_INIT_NOW)
1534
+ uint32_t stored_hash;
1535
+ EEPROM_READ_ALWAYS (stored_hash);
1536
+ if (stored_hash != build_hash) { EEPROM_FINISH (); return true ; }
1537
+ #endif
1538
+
1539
+ uint16_t stored_crc;
1540
+ EEPROM_READ_ALWAYS (stored_crc);
1541
+
1541
1542
float dummyf = 0 ;
1542
1543
working_crc = 0 ; // Init to 0. Accumulated by EEPROM_READ
1543
1544
@@ -2480,7 +2481,7 @@ void MarlinSettings::postprocess() {
2480
2481
return success;
2481
2482
}
2482
2483
reset ();
2483
- #if ENABLED (EEPROM_AUTO_INIT)
2484
+ #if EITHER (EEPROM_AUTO_INIT, EEPROM_INIT_NOW )
2484
2485
(void )save ();
2485
2486
SERIAL_ECHO_MSG (" EEPROM Initialized" );
2486
2487
#endif
0 commit comments