ソースを参照

Add data size validation

Scott Lahteine 7年前
コミット
760c912ab9
2個のファイルの変更37行の追加14行の削除
  1. 34
    14
      Marlin/src/module/configuration_store.cpp
  2. 3
    0
      Marlin/src/module/configuration_store.h

+ 34
- 14
Marlin/src/module/configuration_store.cpp ファイルの表示

@@ -249,6 +249,8 @@ typedef struct SettingsDataStruct {
249 249
 
250 250
 MarlinSettings settings;
251 251
 
252
+uint16_t MarlinSettings::datasize() { return sizeof(SettingsData); }
253
+
252 254
 /**
253 255
  * Post-process after Retrieve or Reset
254 256
  */
@@ -331,6 +333,15 @@ void MarlinSettings::postprocess() {
331 333
     int16_t MarlinSettings::meshes_begin;
332 334
   #endif
333 335
 
336
+  bool MarlinSettings::size_error(const uint16_t size) {
337
+    if (size != datasize()) {
338
+      SERIAL_ERROR_START();
339
+      SERIAL_ERRORLNPGM("EEPROM datasize error.");
340
+      return true;
341
+    }
342
+    return false;
343
+  }
344
+
334 345
   /**
335 346
    * M500 - Store Configuration
336 347
    */
@@ -750,7 +761,7 @@ void MarlinSettings::postprocess() {
750 761
     #endif
751 762
 
752 763
     //
753
-    // Validate CRC
764
+    // Validate CRC and Data Size
754 765
     //
755 766
     if (!eeprom_error) {
756 767
       const uint16_t eeprom_size = eeprom_index - (EEPROM_OFFSET),
@@ -769,6 +780,8 @@ void MarlinSettings::postprocess() {
769 780
         SERIAL_ECHOPAIR(" bytes; crc ", (uint32_t)final_crc);
770 781
         SERIAL_ECHOLNPGM(")");
771 782
       #endif
783
+
784
+      eeprom_error |= size_error(eeprom_size);
772 785
     }
773 786
     EEPROM_FINISH();
774 787
 
@@ -1260,19 +1273,14 @@ void MarlinSettings::postprocess() {
1260 1273
         for (uint8_t q = MAX_EXTRUDERS * 2; q--;) EEPROM_READ(dummy);
1261 1274
       #endif
1262 1275
 
1263
-      if (working_crc == stored_crc) {
1264
-        if (!validating) {
1265
-          postprocess();
1266
-          #if ENABLED(EEPROM_CHITCHAT)
1267
-            SERIAL_ECHO_START();
1268
-            SERIAL_ECHO(version);
1269
-            SERIAL_ECHOPAIR(" stored settings retrieved (", eeprom_index - (EEPROM_OFFSET));
1270
-            SERIAL_ECHOPAIR(" bytes; crc ", (uint32_t)working_crc);
1271
-            SERIAL_ECHOLNPGM(")");
1272
-          #endif
1273
-        }
1276
+      eeprom_error = size_error(eeprom_index - (EEPROM_OFFSET));
1277
+      if (eeprom_error) {
1278
+        SERIAL_ECHO_START();
1279
+        SERIAL_ECHOPAIR("Index: ", int(eeprom_index - (EEPROM_OFFSET)));
1280
+        SERIAL_ECHOLNPAIR(" Size: ", datasize());
1274 1281
       }
1275
-      else {
1282
+      else if (working_crc != stored_crc) {
1283
+        eeprom_error = true;
1276 1284
         #if ENABLED(EEPROM_CHITCHAT)
1277 1285
           SERIAL_ERROR_START();
1278 1286
           SERIAL_ERRORPGM("EEPROM CRC mismatch - (stored) ");
@@ -1281,7 +1289,19 @@ void MarlinSettings::postprocess() {
1281 1289
           SERIAL_ERROR(working_crc);
1282 1290
           SERIAL_ERRORLNPGM(" (calculated)!");
1283 1291
         #endif
1284
-        reset();
1292
+      }
1293
+      else if (!validating) {
1294
+        #if ENABLED(EEPROM_CHITCHAT)
1295
+          SERIAL_ECHO_START();
1296
+          SERIAL_ECHO(version);
1297
+          SERIAL_ECHOPAIR(" stored settings retrieved (", eeprom_index - (EEPROM_OFFSET));
1298
+          SERIAL_ECHOPAIR(" bytes; crc ", (uint32_t)working_crc);
1299
+          SERIAL_ECHOLNPGM(")");
1300
+        #endif
1301
+      }
1302
+
1303
+      if (!validating) {
1304
+        if (eeprom_error) reset(); else postprocess();
1285 1305
       }
1286 1306
 
1287 1307
       #if ENABLED(AUTO_BED_LEVELING_UBL)

+ 3
- 0
Marlin/src/module/configuration_store.h ファイルの表示

@@ -29,6 +29,8 @@ class MarlinSettings {
29 29
   public:
30 30
     MarlinSettings() { }
31 31
 
32
+    static uint16_t datasize();
33
+
32 34
     static void reset();
33 35
     static bool save();   // Return 'true' if data was saved
34 36
 
@@ -90,6 +92,7 @@ class MarlinSettings {
90 92
       #endif
91 93
 
92 94
       static bool _load();
95
+      static bool size_error(const uint16_t size);
93 96
     #endif
94 97
 };
95 98
 

読み込み中…
キャンセル
保存