-
-
Notifications
You must be signed in to change notification settings - Fork 947
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
Make Clock Persistant. #595
Conversation
Works perfectly, thanks. Some ideas:
|
Thanks @hubmartin, glad to hear its working :D this PR is definitely still early in its implementation. I just wanted to get it listed and start gathering feedback on what it should encompass! All great ideas I'm implement them in some fashion. I also want to move backing up the time outside of the |
After some more discussion in the chat, we came to the question - how do you findd out if your firmware rebooted? If we test cutting-edge branches and watch reboots, then even when you look at them you don't know it happened. This might be an issue to test stability of FW. What I suggest is also a reset counter in noninit section. Not sure how to reset it or where to show it, but for example you cech it every day to know the firmware did not crashed. What do you think? |
You can see the uptime in SystemInfo. |
use better linker constant names
Code readability cleanup
Allow settings to stop naggin me that it has added assosiation types
Ok a few new changes up for review ....I did not find anywhere I liked to Also added it to the MCUBOOT linker file and tested it...because you know it is not going to work well if the segment is not defined there ;) |
A note for me for later, the bootloader should be modified to clear this NVM area upon any recovery action. Be that an OTA/User revert/ recovery firmware. |
If you put all the noninit variables to the structure which will be the only variable in noninit (or class in C++?) and set |
Not a bad idea but does not solve my concerns per se. My concern is more with if a data format changes on a Sealed watch how can we be sure to update them, we would need to either change the The major concern I have is this example. The solutions to this I can see are.
I do not like the idea of YET another version number to store, document and maintain, where using a hash "just works" for the grand majority of use cases... Except in development where the hash does not change and you need it to clear, Or as above you do not want it to clear. However in development.... we can probably use a build flag for this, but I would want to code it that it wont stick on MCUBOOT images. My 100% concern here is protecting sealed watches from ever assuming that there is valid data there when there may not be. As developers we can assume and take risks that must not be present in a release build. Hence the idea of moving to a hash. Its updated often enough and commonly enough that any build using it will almost guarentee a wipe without requiring boot loader changes (which I'm honestly afraid of outside the linker-script change this requires). It also really should only effect developers actively working with values here. These items, in my opinion, are meant to be transient backups. They are only valid on boot, only to be written to except at boot. As such they are not scratch ram and the program should be able to load sane defaults anyway in the event the memory is corrupt. So Hash pros are,
Cons:
I also pondered out the idea of using the actual version string. EG "1.3.0" or similar. My concerns here became we love to make dev OTAs for our community members, This puts a lot of burden on us to make sure we do not merge a PR that breaks with damaged data, since our dev build did not increment the version number. I feel that is to much risk. I also pondered using a manual version number like 0xDEADXXXX, This has the same concerns as above, where it is on us as a developer to maintain that... So balancing all of that out, the hash seems like a very clean automated way, with no boot loader code changes, to handle keeping this memory region in a known state. |
I think this seems very sensible. I'm not sure the concern about data resetting is that valid for a developer device. I don't imagine you will be persisting lots of data to this memory area |
It won't have any drastic consequences though and can always be fixed by a companion. Good if avoided, but a minor thing nonetheless. |
If we wanted to clear the noinit each time a DFU is flashed, we don't need a hash, we can just clear it when a DFU is flashed, and maybe also when a previous firmware version is rolled back to. But maybe we don't want it to clear because we should eventually expect that the firmware doesn't require resetting ever and the only time a user will reset it is for a firmware update. If we clear the noinit in this case anyway, the noinit section is now doing nothing for users. |
This was just an example, since the main firmware should be assuming that these values are correct upon load and not need to handle error checking....the date time class is not super likely to fail however I agree but not knowing what this is going to be extended to I feel like we should have some for of data validation. :)
I thought about that, I could not find a sane way other then forcing us to maintain yet another version string to allow it to persist through updates "risk" free. I just have the heavy fear that during development, and while the firmware is being constantly updated this can cause issues and subtle bugs that are easily avoided. I am also personally afraid to touch the boot loader more then necessary. As it is asking everyone to update is just barely worth it IMO. Right now the only changes just moves the stack...relatively inconsequential compared to writing more code!
Yeah I'm not at all concerned about developer units This is 100% for the consumer units to feel more polished. Its almost really just something to help hide crashes and panics by faking that its working properly after a restart ;) All of this said I would love to come up with something that allows it to persist updates when appropriate. I just have yet to logic out a sane way todo so. No need to introduce bugs and risk due to poor variable initialization which is the ultimate fear :) |
Since I do not have any better solution, I would stick with with one of these options for magic word:
The complete clearing logic should be in the app, since many people (and me :)) do not have bootloader at all. My feeling is that this PR has to mainly deal with random/forced reboots, which it perfectly does. |
Now dynamically allocates noinit area size stores it after the bss before the heap and stack.
Made a change to not need bootloader changes. Little "riskier" but with the bootloader likely not changing much it should work out fine. |
Added some comments for any developers planning to use this segment in the future. @JF002 this is ready to merge, No changes to the boot-loader segment are needed, The only thing left to add would be an offset to account for the bootloader I guess? If we need that I will add it. |
Thanks for this PR @geekbozu ! |
This is the start of a PR for adding some persistant storage in ram for things like the time. Step Count. Other items that would benefit from being kept through a soft reboot.
We accomplish this by declaring a .noinit section in ram which will not be cleared during initialization. We can then assign Global Variables to that section preventing them from being cleared during softboot.
We use a magic variable to determine if ram has been reset. We check to see if it matches the expected value and restore the system variables if it matches.
If it does not match we need to "backup" the current variables and then set the magic word. For now we just set the word and let the system init.
Currently only time is implemented.
Currently, with no chance of not requiring it, There is a bootloader modification to be done. Once we determine the size of this Persistent storage space and the changes to the linker script are solidified we can adjust the linker script for the bootloader and proceed to get that updated.
Also ran CLang format on the files...hope it did it right :)