Skip to content

Commit ea2f88a

Browse files
committed
flashfs fix unfinished log
1 parent d18cfc9 commit ea2f88a

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

lib/Espfc/src/Blackbox/BlackboxFlashfs.cpp

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ const FlashfsRuntime * flashfsGetRuntime()
2020
return &flashfs;
2121
}
2222

23-
static uint32_t IRAM_ATTR flashfsJournalAddress(size_t index)
23+
static uint32_t IRAM_ATTR flashfsJournalAddress(size_t index, bool getEnd = false)
2424
{
25-
uint32_t base = reinterpret_cast<const esp_partition_t*>(flashfs.partition)->size - FLASHFS_JOURNAL_SIZE;
26-
return base + (index * sizeof(FlashfsJournalItem));
25+
uint32_t journalBase = reinterpret_cast<const esp_partition_t*>(flashfs.partition)->size - FLASHFS_JOURNAL_SIZE;
26+
return journalBase + (index * sizeof(FlashfsJournalItem)) + (getEnd * sizeof(uint32_t));
2727
}
2828

2929
void flashfsJournalLoad(FlashfsJournalItem * data, size_t start, size_t num)
@@ -32,22 +32,6 @@ void flashfsJournalLoad(FlashfsJournalItem * data, size_t start, size_t num)
3232
flashfsReadAbs(flashfsJournalAddress(start), (uint8_t*)data, size);
3333
}
3434

35-
static uint32_t flashfsLogLoad()
36-
{
37-
if(!flashfs.partition) return 0;
38-
39-
uint32_t address = 0;
40-
flashfsJournalLoad(flashfs.journal, 0, FLASHFS_JOURNAL_ITEMS);
41-
for(size_t i = 0; i < FLASHFS_JOURNAL_ITEMS; i++)
42-
{
43-
const auto& it = flashfs.journal[i];
44-
if(it.logEnd == FLASHFS_ERASED_VAL) break;
45-
address = it.logEnd;
46-
flashfs.journalIdx++;
47-
}
48-
return address;
49-
}
50-
5135
static void IRAM_ATTR flashfsLogBegin()
5236
{
5337
uint32_t beginAddr = flashfs.address;
@@ -78,19 +62,55 @@ static void IRAM_ATTR flashfsLogEnd()
7862

7963
if(!flashfs.partition) return;
8064

81-
size_t address = flashfsJournalAddress(idx) + sizeof(uint32_t);
65+
size_t address = flashfsJournalAddress(idx, true);
8266

8367
flashfsWriteAbs(address, (uint8_t*)&endAddr, sizeof(uint32_t));
8468
}
8569

70+
void flashfsJournalFix(FlashfsJournalItem * data, size_t num)
71+
{
72+
uint8_t buff[4];
73+
for(size_t i = 0; i < num; i++)
74+
{
75+
if(data[i].logBegin != FLASHFS_ERASED_VAL && data[i].logEnd == FLASHFS_ERASED_VAL)
76+
{
77+
uint32_t addr = data[i].logBegin;
78+
uint32_t end = flashfsGetSize();
79+
while(addr < end)
80+
{
81+
flashfsReadAbs(addr, buff, 4);
82+
if(*reinterpret_cast<uint32_t*>(&buff[0]) == FLASHFS_ERASED_VAL)
83+
{
84+
flashfs.address = addr;
85+
flashfsLogEnd();
86+
break;
87+
}
88+
addr += 128;
89+
}
90+
break;
91+
}
92+
}
93+
}
94+
8695
int flashfsInit(void)
8796
{
8897
flashfs.partition = Espfc::Device::FlashDevice::findPartition();
8998
if(!flashfs.partition) return 0;
9099

91100
flashfs.buffer = (void*)&buff;
92101
flashfs.journalIdx = 0;
93-
flashfs.address = flashfsLogLoad();
102+
flashfs.address = 0;
103+
104+
flashfsJournalLoad(flashfs.journal, 0, FLASHFS_JOURNAL_ITEMS);
105+
for(size_t i = 0; i < FLASHFS_JOURNAL_ITEMS; i++)
106+
{
107+
const auto& it = flashfs.journal[i];
108+
if(it.logEnd == FLASHFS_ERASED_VAL) break;
109+
flashfs.address = it.logEnd;
110+
flashfs.journalIdx++;
111+
}
112+
flashfsJournalFix(flashfs.journal, FLASHFS_JOURNAL_ITEMS);
113+
94114
return 1;
95115
}
96116

@@ -161,7 +181,7 @@ void IRAM_ATTR flashfsWriteAbs(uint32_t address, const uint8_t *data, unsigned i
161181
esp_partition_write_raw(p, address, data, len);
162182
}
163183

164-
int flashfsReadAbs(uint32_t address, uint8_t *data, unsigned int len)
184+
int IRAM_ATTR flashfsReadAbs(uint32_t address, uint8_t *data, unsigned int len)
165185
{
166186
if(!flashfs.partition) return 0;
167187

lib/betaflight/src/platform.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ float motor_disarmed[MAX_SUPPORTED_MOTORS];
6262
uint32_t targetPidLooptime;
6363
float rcCommand[4];
6464

65-
int32_t GPS_home[2];
65+
int32_t GPS_home[2] = { 0, 0 };
6666
gpsSolutionData_t gpsSol;
6767

6868
const char* const lookupTableMixerType[] = {

lib/betaflight/src/platform.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,7 @@ typedef struct
13141314
const FlashfsRuntime * flashfsGetRuntime();
13151315

13161316
void flashfsJournalLoad(FlashfsJournalItem * data, size_t start, size_t num);
1317+
void flashfsJournalFix(FlashfsJournalItem * data, size_t num);
13171318

13181319
int flashfsInit(void);
13191320
uint32_t flashfsGetSize(void);

0 commit comments

Comments
 (0)