mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-10 13:13:27 +00:00
Fix CI errors and CPPcheck warnings
This commit is contained in:
parent
486c56e651
commit
30fffbdc01
@ -23,7 +23,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "STM32_LittleFS.h"
|
#include "STM32_LittleFS.h"
|
||||||
#include "littlefs/lfs.h"
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#define rtos_malloc malloc
|
#define rtos_malloc malloc
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
#ifndef STM32_LITTLEFS_FILE_H_
|
#ifndef STM32_LITTLEFS_FILE_H_
|
||||||
#define STM32_LITTLEFS_FILE_H_
|
#define STM32_LITTLEFS_FILE_H_
|
||||||
|
|
||||||
|
#include "littlefs/lfs.h"
|
||||||
|
|
||||||
// Forward declaration
|
// Forward declaration
|
||||||
class STM32_LittleFS;
|
class STM32_LittleFS;
|
||||||
|
|
||||||
|
@ -502,93 +502,92 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_dir_t *dir, const struct lfs_region *r
|
|||||||
bool relocated = false;
|
bool relocated = false;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (true) {
|
|
||||||
int err = lfs_bd_erase(lfs, dir->pair[0]);
|
|
||||||
if (err) {
|
|
||||||
if (err == LFS_ERR_CORRUPT) {
|
|
||||||
goto relocate;
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t crc = 0xffffffff;
|
int err = lfs_bd_erase(lfs, dir->pair[0]);
|
||||||
lfs_dir_tole32(&dir->d);
|
if (err) {
|
||||||
lfs_crc(&crc, &dir->d, sizeof(dir->d));
|
if (err == LFS_ERR_CORRUPT) {
|
||||||
err = lfs_bd_prog(lfs, dir->pair[0], 0, &dir->d, sizeof(dir->d));
|
|
||||||
lfs_dir_fromle32(&dir->d);
|
|
||||||
if (err) {
|
|
||||||
if (err == LFS_ERR_CORRUPT) {
|
|
||||||
goto relocate;
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
lfs_off_t oldoff = sizeof(dir->d);
|
|
||||||
lfs_off_t newoff = sizeof(dir->d);
|
|
||||||
while (newoff < (0x7fffffff & dir->d.size) - 4) {
|
|
||||||
if (i < count && regions[i].oldoff == oldoff) {
|
|
||||||
lfs_crc(&crc, regions[i].newdata, regions[i].newlen);
|
|
||||||
err = lfs_bd_prog(lfs, dir->pair[0], newoff, regions[i].newdata, regions[i].newlen);
|
|
||||||
if (err) {
|
|
||||||
if (err == LFS_ERR_CORRUPT) {
|
|
||||||
goto relocate;
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
oldoff += regions[i].oldlen;
|
|
||||||
newoff += regions[i].newlen;
|
|
||||||
i += 1;
|
|
||||||
} else {
|
|
||||||
uint8_t data;
|
|
||||||
err = lfs_bd_read(lfs, oldpair[1], oldoff, &data, 1);
|
|
||||||
if (err) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
lfs_crc(&crc, &data, 1);
|
|
||||||
err = lfs_bd_prog(lfs, dir->pair[0], newoff, &data, 1);
|
|
||||||
if (err) {
|
|
||||||
if (err == LFS_ERR_CORRUPT) {
|
|
||||||
goto relocate;
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
oldoff += 1;
|
|
||||||
newoff += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
crc = lfs_tole32(crc);
|
|
||||||
err = lfs_bd_prog(lfs, dir->pair[0], newoff, &crc, 4);
|
|
||||||
crc = lfs_fromle32(crc);
|
|
||||||
if (err) {
|
|
||||||
if (err == LFS_ERR_CORRUPT) {
|
|
||||||
goto relocate;
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = lfs_bd_sync(lfs);
|
|
||||||
if (err) {
|
|
||||||
if (err == LFS_ERR_CORRUPT) {
|
|
||||||
goto relocate;
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
// successful commit, check checksum to make sure
|
|
||||||
uint32_t ncrc = 0xffffffff;
|
|
||||||
err = lfs_bd_crc(lfs, dir->pair[0], 0, (0x7fffffff & dir->d.size) - 4, &ncrc);
|
|
||||||
if (err) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ncrc != crc) {
|
|
||||||
goto relocate;
|
goto relocate;
|
||||||
}
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t crc = 0xffffffff;
|
||||||
|
lfs_dir_tole32(&dir->d);
|
||||||
|
lfs_crc(&crc, &dir->d, sizeof(dir->d));
|
||||||
|
err = lfs_bd_prog(lfs, dir->pair[0], 0, &dir->d, sizeof(dir->d));
|
||||||
|
lfs_dir_fromle32(&dir->d);
|
||||||
|
if (err) {
|
||||||
|
if (err == LFS_ERR_CORRUPT) {
|
||||||
|
goto relocate;
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
lfs_off_t oldoff = sizeof(dir->d);
|
||||||
|
lfs_off_t newoff = sizeof(dir->d);
|
||||||
|
while (newoff < (0x7fffffff & dir->d.size) - 4) {
|
||||||
|
if (i < count && regions[i].oldoff == oldoff) {
|
||||||
|
lfs_crc(&crc, regions[i].newdata, regions[i].newlen);
|
||||||
|
err = lfs_bd_prog(lfs, dir->pair[0], newoff, regions[i].newdata, regions[i].newlen);
|
||||||
|
if (err) {
|
||||||
|
if (err == LFS_ERR_CORRUPT) {
|
||||||
|
goto relocate;
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
oldoff += regions[i].oldlen;
|
||||||
|
newoff += regions[i].newlen;
|
||||||
|
i += 1;
|
||||||
|
} else {
|
||||||
|
uint8_t data;
|
||||||
|
err = lfs_bd_read(lfs, oldpair[1], oldoff, &data, 1);
|
||||||
|
if (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
lfs_crc(&crc, &data, 1);
|
||||||
|
err = lfs_bd_prog(lfs, dir->pair[0], newoff, &data, 1);
|
||||||
|
if (err) {
|
||||||
|
if (err == LFS_ERR_CORRUPT) {
|
||||||
|
goto relocate;
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
oldoff += 1;
|
||||||
|
newoff += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
crc = lfs_tole32(crc);
|
||||||
|
err = lfs_bd_prog(lfs, dir->pair[0], newoff, &crc, 4);
|
||||||
|
crc = lfs_fromle32(crc);
|
||||||
|
if (err) {
|
||||||
|
if (err == LFS_ERR_CORRUPT) {
|
||||||
|
goto relocate;
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = lfs_bd_sync(lfs);
|
||||||
|
if (err) {
|
||||||
|
if (err == LFS_ERR_CORRUPT) {
|
||||||
|
goto relocate;
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
// successful commit, check checksum to make sure
|
||||||
|
uint32_t ncrc = 0xffffffff;
|
||||||
|
err = lfs_bd_crc(lfs, dir->pair[0], 0, (0x7fffffff & dir->d.size) - 4, &ncrc);
|
||||||
|
if (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ncrc != crc) {
|
||||||
|
goto relocate;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -607,7 +606,7 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_dir_t *dir, const struct lfs_region *r
|
|||||||
}
|
}
|
||||||
|
|
||||||
// relocate half of pair
|
// relocate half of pair
|
||||||
int err = lfs_alloc(lfs, &dir->pair[0]);
|
err = lfs_alloc(lfs, &dir->pair[0]);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user