Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LittleFS for BL602 #1159

Merged

Conversation

giedriuslt
Copy link
Contributor

This adds LittleFS support for BL602 as requested in #1117
It is using media partition, which is defined in partition layout, but unused. Offsets are currently static, so only supports layout from BLDevCube 1.4.8.
Scripts also work.

@openshwprojects
Copy link
Owner

Thanks, how much does it increase the resulting OTA file?

@giedriuslt
Copy link
Contributor Author

Actual binary increases by 40KB to 780KB, we have 800KB limit there.
Compressed OTA increases by 21KB to 417KB, we have 544KB limit there. So should be no issues.

@openshwprojects
Copy link
Owner

openshwprojects commented Mar 31, 2024 via email

@giedriuslt
Copy link
Contributor Author

Yes, OTA works without any issues after my recent fixes. I uploaded it more than 10 times while testing, no issues.

@openshwprojects
Copy link
Owner

I don't know much about BLdevCube versions, can you elaborate on "Offsets are currently static, so only supports layout from BLDevCube 1.4.8."?
Is this ready for production, or will it prevent users from using older BLdevcube?

@giedriuslt
Copy link
Contributor Author

giedriuslt commented Mar 31, 2024

Partition layout file is different between 1.4.8 and 1.8.9
Specifically 1.8.9 increased firmware size by 64KB and moved others. It actually would be useful for us, but now everybody used 1.4.8 so we are stuck.
In 1.4.8 media partition starts at 0x192000

[[pt_entry]]
type = 3
name = "media"
device = 0
address0 = 0x192000
size0 = 0x57000
address1 = 0
size1 = 0
# compressed image must set len,normal image can left it to 0
len = 0

while in 1.8.9 it starts later at 0x1A2000.

[[pt_entry]]
type = 3
name = "media"
device = 0
address0 = 0x1A2000
size0 = 0x47000
address1 = 0
size1 = 0
# compressed image must set len,normal image can left it to 0
len = 0

So to avoid accidentally writing to wrong place, i made it to support 1.4.8 layout and added check in initialization. If layout is not as expected, little fs won't work, but everything else should be fine

@divadiow
Copy link
Contributor

divadiow commented Apr 3, 2024

Partition layout file is different between 1.4.8 and 1.8.9 Specifically 1.8.9 increased firmware size by 64KB and moved others. It actually would be useful for us, but now everybody used 1.4.8 so we are stuck. In 1.4.8 media partition starts at 0x192000

[[pt_entry]]
type = 3
name = "media"
device = 0
address0 = 0x192000
size0 = 0x57000
address1 = 0
size1 = 0
# compressed image must set len,normal image can left it to 0
len = 0

while in 1.8.9 it starts later at 0x1A2000.

[[pt_entry]]
type = 3
name = "media"
device = 0
address0 = 0x1A2000
size0 = 0x47000
address1 = 0
size1 = 0
# compressed image must set len,normal image can left it to 0
len = 0

So to avoid accidentally writing to wrong place, i made it to support 1.4.8 layout and added check in initialization. If layout is not as expected, little fs won't work, but everything else should be fine

does this explain why when OTA flashing BL602 update on top of a 1.8.9 flashed device it didn't come back up? I had to revert to 1.4.8 UART flash to bring it back to life and OTA. this was in the recent past, not this build

@divadiow
Copy link
Contributor

divadiow commented Apr 3, 2024

I have 4mb BL602 if you need anything testing

@divadiow
Copy link
Contributor

divadiow commented Apr 3, 2024

I'll do a methodical end-to-end test from 1.4.8 flash to OTA upgrade then same again from blank using 1.8.9. testing lfs after each OTA.

I've just OTAd to this PR and lfs works. I could have sworn I used 1.4.8 to flash it but I MAY have used the 1.8.9 partition file with 1.4.8 BLDC, and the 4mb one at that. Will update with test findings later.

@giedriuslt
Copy link
Contributor Author

I don't think this should matter. OTA code reads partition layout, so should work regardless.

@divadiow
Copy link
Contributor

divadiow commented Apr 3, 2024

OK.

with 1.4.8:

image

-whole chip erase
-flash OpenBL602_1.17.509.bin using BLDC 1.4.8 from OBK SDK including old partition and boot files. nothing changed
-OTA to OpenBL602_1159_merge_63e44ebd7d2f_OTA.bin.xz.ota
-created autoexec.bat
-listed OK and edited, saved. autoexec still OK after reboot

image

with 1.8.9:

image

-whole chip erase
-flash OpenBL602_1.17.509.bin using BLDC 1.8.9 using latest boot2, dts and 2mb partition config
-OTA to OpenBL602_1159_merge_63e44ebd7d2f_OTA.bin.xz.ota
-created autoexec.bat attempt but no file created and BL602 lockup. have to reboot. at autoexec creation time I get this in uart log

[19:59:59.498] - [MTD] >>>>>> Hanlde info Dump >>>>>>
name media
id 0
offset 0x001a2000(1712128)
size 0x00047000(284Kbytes)
xip_addr 0x23191000
[MTD] <<<<<< Hanlde info End <<<<<<
Current task sp data:
RA:230357c8, mstatus:80007880
A0:4201e84c A1:4202b690 A2:4202b6a8 A3:78000000 A4:00000
[19:59:59.503] - 00c A5:23035acc A6:23035acc A7:42029e54
T0:2308a61c T1:00000000 T2:ffffffff T3:00000000 T4:00000000 T5:00000019 T6:0000000a
S0:4202b67c S1:4202b670 S2:4202b690 S3:0000000c S4:4201e84c S5:4202b68c S6:230ae000 S7:4202b6a8
S8:00000001 S9:230ae000 S10:230af000 S11:002ffc00
Exception Entry--->>>
mcause 38000005, mepc 23035152, mtval 00000020
Exception code: 5
msg: Load access fault

@divadiow
Copy link
Contributor

divadiow commented Apr 3, 2024

dunno if this helps at all but these are the boot logs from each. same PR build of OBK. only difference is the BLDC used and the config/partition files. I had chatgpt compare differences but im not ultimately sure what the big picture is regarding errors in one but not the other

uart_1.4.8.txt
uart_1.8.9.txt

@openshwprojects
Copy link
Owner

@divadiow so do you think it's safe to merge it?

@divadiow
Copy link
Contributor

divadiow commented Apr 4, 2024

in my test the device locked when creating autoexec if OBK conversion was with 1.8.9 BLDC + new 2mb partition config file. I could repeat the same test more times? @giedriuslt does "not work" mean a locked-up device requiring reboot if you attempt to create autoexec?

If layout is not as expected, little fs won't work, but everything else should be fine

I have not tried this on a 2mb device, but you'd think me using the 2mb partition file would create the same partition layout.

@divadiow
Copy link
Contributor

divadiow commented Apr 4, 2024

I'm also curious about the way forward with usage of 1.4.8 and 1.8.9+ and the historical use of both to free devices with OBK.

Should everyone be required to reflash with 1.8.9 so development of BL602 can progress without concern for old partition layout?
What else needs changing in OBK if 1.8.9 is used? What do the boot log errors specific to 1.8.9 mean and are they an issue?
And then of course how does the latest SDK fit into all of this?

@giedriuslt
Copy link
Contributor Author

I would not expect it to crash. I expected it to show error. I think this needs to be investigated.

@divadiow
Copy link
Contributor

divadiow commented Apr 4, 2024

I'll repeat the same test more. And try with 2mb other device

@divadiow
Copy link
Contributor

divadiow commented Apr 4, 2024

@giedriuslt was one of your tests flash fresh using 1.8.9 then OTA to PR then try create autoexec?

@divadiow
Copy link
Contributor

divadiow commented Apr 4, 2024

hmm. I've flashed the dev board 3 times. full chip erase in between. each does the same load access fault before the chip dies when creating autoexec. first 2 flashes were with 2mb toml and 3rd with 4mb toml.

image

this is the full log from reboot after OTA to PR then through to final hang on autoexec.bat creation

I have not tried a different device yet. do I need to?
uart_1.8.9_postOTAcreateautoexec.txt

@giedriuslt
Copy link
Contributor Author

So, I fixed the crash, file creation did not check if LittleFS is available, but now UI app needs to be fixed, because it reports save complete while api returns 400 error.

@divadiow
Copy link
Contributor

divadiow commented Apr 4, 2024

updated to 1159_merge_29e43a1447bf on device flashed with 1.8.9 and now the device doesn't hang when attempting to create autoexec. shame this means only users who flashed with 1.4.8 will get LittleFS when 1.8.9 and the new partition layout are probably the way forward.

[20:08:48.879] - 28, MQTT 0(23), bWifi 1, secondsWithNoPing 301, socks 2/21
[20:08:49.880] - Info:MAIN:Time 371, idle 0/s, free 106728, MQTT 0(23), bWifi 1, secondsWithNoPing 302, socks 2/21
[20:08:50.883] - Info:MAIN:Time 372, idle 0/s, free 106728, MQTT 0(23), bWifi 1, secondsWithNoPing 303, socks 2/21
[20:08:51.887] - Info:MAIN:Time 373, idle 0/s, free 106728, MQTT 0(23), bWifi 1, secondsWithNoPing 304, socks 2/21
**[20:08:52.191] - [MTD] >>>>>> Hanlde info Dump >>>>>>
name media
id 0
offset 0x001a2000(1712128)
size 0x00047000(284Kbytes)
xip_addr 0x23191000
[MTD] <<<<<< Hanlde info End <<<<<<**
[20:08:52.892] - Info:MAIN:Time 374, idle 0/s, free 106688, MQTT 0(23), bWifi 1, secondsWithNoPing 305, socks 2/21
[20:08:53.894] - Info:MAIN:Time 375, idle 0/s, free 104152, MQTT 0(23), bWifi 1, secondsWithNoPing 306, socks 3/21
[20:08:54.900] - Info:MA
[20:08:54.901] - IN:Time 376, idle 0/s, free 106688, MQTT 0(23), bWifi 1, secondsWithNoPing 307, socks 2/21
[20:08:55.900] - Info:MAIN:Time 377, idle 0/s, free 106688, MQTT 0(23), bWifi 1, secondsWithNoPing 308, socks 2/21
[20:08:56.902] - Info:MAIN:Time 378, idle 0/s, free 106688, MQTT 0(23), bWifi 1, secondsWithNoPing 309, socks 2/21
[20:08:57.905] - Info:MAIN:Time 379, idle 0/s, free 106400, MQTT 0(23), bWifi 1, secondsWithNoPing 310, socks 3/
[20:08:57.906] - 21

but excellent work still!

@openshwprojects
Copy link
Owner

Thanki you for testing. I think I wil merge it for now . Hopefully we can also support alternate partition format soon...

@openshwprojects openshwprojects merged commit f1c1894 into openshwprojects:main Apr 9, 2024
9 checks passed
Copy link

github-actions bot commented Apr 9, 2024

🎉 This PR is included in version 1.17.541 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@divadiow
Copy link
Contributor

xref to issue using OTA Zengge exploit and expecting LFS: https://www.elektroda.com/rtvforum/viewtopic.php?p=21323714#21323714

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants