-
-
Notifications
You must be signed in to change notification settings - Fork 728
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
Best practices to fit changes onto flash? (WAS: rationale for writing settings onto flash on change only) #1699
Comments
Hello and welcome👋🏼 This is indeed wise, originally I made the call that most users wont change their settings over 10k times 🙃 and took the quicker path to the code. I think this is the wiser approach, though rather than reading the entire struct into memory, you could just call a memcmp() over the ROM address and the struct in ram (which may be less code). Otherwise logic stands :) The 1K flash gap is there for the bootup logo / animation so it cant be used for application code. Things that would shrink the size of the binary:
The first two of those has been on my list forever to do, but effort > reward. |
Thank you.
I fully agree with you. Although I just thought such optimization could be useful.
What a smart approach!
Aaaaha!!! Somehow I couldn't figure this out easily - I forgot about animation data. Thanks for this technical input!
Unfortunately, I do not have enough of skills to achieve the first two (not on my own at least). I tried what I could do:
No luck.
As far as I understand something will have to be done eventually because all the features will stop to fit otherwise.
Got it. Well, here is my suggestion then: if size optimization task will get more or less clear Thank you a lot for the response and for clarifications. |
TLDR
UPDATE 2: This message has been started just as a pull request but it turned into very deep rabbit hole for me. But I would like to keep the original part as is.
TL;DR: by the "price" of using extra
sizeof(systemSettingsType)
bytes in RAM, this patch (presumably) reduceswrite
operations into internal flash, hence prolonging lifecycle for it by reducingflash wear-out
effect.According to datasheet for
STM32F103
(which is used forTS80P
model), it has limit of10'000
write cycles (page57
, table29
) which is usually "standard" amount for generic purpose MCU which is not small amount. However, as far as I'm aware (and correct me if I'm wrong!) MCU flash doesn't have modernwear leveling
algorithms (unlike modern consumer-grade flash storage chips, therefore this commit could be useful from described perspective).UPDATE 1: All builds have been successfull except only one: TS80P / ZH_CN. It ran out of ROM by 44 bytes. See below.
Intro
Hello. First of all, I would like to thank everyone who is involved in IronOS because this is really incredible project on so many levels. But the longer I was scouting through the code just out of my own curiosity, the more I was getting some thoughts to share. So in addition to my words of appreciation, I started to think about helping the project back not only by my words but by commits.
Please, keep in mind that I'm not a professional in:
So I'm fully open to any criticism but even if my patch(es) will be declined, I would like to hear an explanation why (if possible).
Rationale
Current code flow
saveSettings()
function is being called every time on exit from settings menu unconditionally;flash_save_buffer()
platform-dependent function is being called bysaveSettings()
unconditionally;flash_save_buffer()
implementations (regardless the platform) not only overwrite flash storage unconditionally with settings' buffer but zeroing storage before re-writing settings.Proposal
Implementation of tiny check inside of
saveSettings()
before callingflash_save_buffer()
will reduce unnecessary writings onto flash. Suggested code flow:currentSettings
;currentSettings
withsystemSettings
buffer which is going to be stored;This approach may be too straightforward, but implementing a check for every setting (has it been changed in menu?) may make code base a bit messy.
Testing
Although I
makewas going to make pull-request with this patch fordev
branch (which is the main active development branch of the project - as far as I understand), I didsuccessfullymostly successfully the following tests:v2.21
release tag - to test the patch on the stable version;alpine linux 16.3
insidelxc
container;TS80P_EN.hex
has been tested successfully on my own personal soldering iron for a couple of hours;v2.21
source code tree without this patch produces the same warning for usingmemcpy
insideloadSettings
during compilation just like with this patch, therefore the patch has nothing to do with this warning:TS80P / ZH_CN build problem
Here the problem starts.
During the final checks before asking for pull request, I discovered that there is the issue with fitting
TS80P-ZH_CN
into flash:Since the main documentation is the code, after digging around and with a hint from
flash.c
, I have the following understanding of flash map forTS100
/TS80
/TS80P
models:0
4000
16KB
4000
B800
46KB
F800
400
1KB
FC00
400
1KB
Is this correct?
And is my understanding correct that if I change this line to
flash_size=63k
then the flash map will be like this:0
4000
16KB
4000
BC00
47KB
FC00
400
1KB
Now I have even more questions:
saveSettings()
anyway?The way how I see the main problem: IronOS gets so rich with features, and some languages are so complicated that eventually it may not be fitting into flash on some devices anymore with new patches & features. Are there any tricks & hacks for compressing binaries even more? I'm not talking about options of optimizations for compilers since it's
-Os
already (as far as I noticed) but maybe there is something else can be done.If the original suggestion will be considered valuable and someone will help me to fix the ROM size issue, then I would be happy to apply for a proper feature pull-request of my patch.
I can't wait to hear any feedback about this. Thank you a lot for your time especially if you've read all of this.
The text was updated successfully, but these errors were encountered: