-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
mimxrt/mboot: Adds bootloader support. #8229
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
Conversation
@robert-hh thanks a lot for all the support and testing - this one was quite a journey |
@dpgeorge I have added some more information to the commit message. Maybe as a hint for you, if you want to try the bootloader out. You can just flash the .hex file on your Teensy. There are no extra steps to take. Then you will have the "normal" firmware plus the bootloader installed on your board. From then on any firmware upgrade does not require you to press the darn button on that board anymore 😄. I have tested the bootloader on four different boards with my Jenkins test automation setup. In addition @robert-hh has also tested it hundreds of times, too. I guess I can say that we are quite confident that it works reliably. |
Hi, this is a really interesting feature! I've done a fair bit of work with the stm32 port mboot bootloader, there's a couple of features here that sound quite useful.
Do you mean this detach request is sent when the device is in "normal" runtime mode to trigger a reboot to bootloader? This sounds quite useful, I've wanted something like this on stm32. Is the micropython app currently running given a chance to shutdown cleanly here though?
Merging the elf / bin / hex files is handy, that could certainly simplify initial deployment certainly, rather than having to ensure both hex files are delivered / flashed correctly, and yeah it'd be nice to debug both the bootloader & main firmware in the one session. On the flip side, mboot has a number of other features like signed/encrypted firmware updates or flashing a dfu from internal vfs filesystem, etc... I'd love to see micropython as a platform moving towards having a common bootloader codebase that could be used on many / most ports with a common set of features. |
Hi @andrewleech Thanks for your feedback. The bootloader has be written by myself from the ground up. To be fair I had tremendous help by @robert-hh who supported with a lot of discussions, testing and provided hardware. The only thing you need to do in order to detach from the firmware is to add a dfu-runtime descriptor to the MicroPython firmware. There is only one callback provided by TinyUSB which needs to be filled out. In my implementation I set a flag in an no-init RAM section ( to let the bootloader know it has to start dfu mode) and trigger a soft reset. Most certainly this could be improved to properly shut down MicroPython, too. I also thought about allowing a firmware upgrade from VFS but I did not yet implement that feature. Regarding debugging you can only debug the firmware with the "combined" .elf file. Probably it is possible to also add the bootloader symbols but I did not try it out. Regarding your platform idea. I would say that code wise it is already 80% portable. The flash access for instance is included from the mimxrt port. However there are some intricate parts like for instance the Linker Script which would require more attention. Nonetheless there are still many features missing. In any case I will concentrate to improve the bootloader for the mimxrt port which is kind of my baby 😄. |
It would definitely be a good idea to try and unify the bootloaders across the different ports, so that features can be reused and they are functionally similar (from a user's point of view). @alphaFred what would you say to renaming this bootloader |
Yes the consolidation doesn't have to happen at once, can certainly be an iterative process :-) Similar to at least making the name match though, it's probably worth looking at / copying the If at least the make / board defines are broadly compatible between the two, that will go a long way towards making it easy for users to migrate between ports, and means that any future refactoring ot code into common libraries will have less breaking changes for existing users. |
That would be possible 👍. |
@robert-hh and myself had quite a long discussion about how to make integration of the bootloader as seamless as possible. In the beginning I also had a flag which would allow building the port with/without bootloader. We abandoned that idea because in that case we would have to provide twice the number of firmware binaries. We thought that there is no harm in always shipping the bootloader. From a users perspective the firmware still behaves the same,just with added features. Therefore I am a bit reluctant to add such a switch to be honest. @dpgeorge Would you say that make option is required for the PR to be merged? |
No, not required. But I'd need to do a full review first. If the bootloader is always enabled on all builds for all boards then that does keep things simple (stm32 might have gone that way if mboot was there from the beginning...). |
Puh I was kinda nervous, thinking about the effort to go back to splitting the whole thing up again 😄.
Yes of course. And I am looking forward to that whenever you can find the time. Quite frankly there is no difference for a user. The VFS size and (memory location) remained the same. So for someone using the port now it is just the same as with previous updates to the firmware. Take a debugger and flash the binary. Your VFS will remain. Except on Teensy I believe but don't nail me on that one. |
One of the improvements for Teensy with the new bootloader is, that the VFS is not touched. The PJRC Teensy bootloader erases the whole flash, while the new bootloader keeps the file system intact. |
@dpgeorge I changed the name to |
8a9ff7d
to
29e5c39
Compare
@dpgeorge just rebased PR to not get too far behind. No issues. Still ready for review. |
b18898e
to
9babd85
Compare
@dpgeorge rebased and integrated changes merged in by @robert-hh for MIMXRT1015 support. All supported boards have been retested by me and/or Robert. Everything is still working fine. |
8c58533
to
e02427c
Compare
158d257
to
174a0ec
Compare
174a0ec
to
aebc771
Compare
aebc771
to
2e62317
Compare
I had a play with this PR and it works well. When the board is running uPy, using But I could not find a Also, it would be good if this PR could be split into a few commits. For example:
|
When building this I get a compiler warning, which turns into an error with
|
@dpgeorge first of all thank you for your review. I will take care of the points you made. Regarding I hope that makes sense. Feel free to comment on my approach. I am always open for feedback. I have to thank Robert again for his help! |
2e62317
to
8d8c7de
Compare
Splits `mimxrt_flash.c` into low-level driver functions and MicroPython code. Signed-off-by: Philipp Ebensberger
Refactors USB phy0 initialization routine. Signed-off-by: Philipp Ebensberger
Adds DFU bootloader for mimxrt port. The bootloader binary is packaged into the "normal" firmware binary. Therefore when setting up a new board the bootloader will be available automatically by just loading the normal firmware binary onto it. Signed-off-by: Philipp Ebensberger
Adds runtime DFU descriptor to firmware. Allows to reset into DFU bootloader. Signed-off-by: Philipp Ebensberger
Adds method to jump into DFU bootloader via MicroPython code. Signed-off-by: Philipp Ebensberger
Fixes code formatting with curly brackets on `for` loops and adds `void` argument to empty function declarations and definitions. Signed-off-by: Philipp Ebensberger
8d8c7de
to
58fa825
Compare
I can not replicate the error. In the CI pipeline there is also no issue. Maybe you use a different (newer?) gcc toolchain? I use the same version (9.2.1) like our CI pipeline. |
I did not see that error either when did a confirmation compile & test yesterday. But I had similar errors (arry out-of-bound) with gcc 11.2-2022.02. So I moved back to gcc 10.3-2021.07- |
@dpgeorge I did not look if it is mentioned somewhere, but once a firmware with the bootloader is installed, the intended command for further firmware updates is:
After a second or two, updating will start. No need to activate the bootloader before at the board's REPL. That does not exclude using the previous firmware upload mechanisms as the fallback option. |
Has this pr passed into the mists of time or is it still under consideration? |
I guess it depends. I certainly would love for it to be merged. But at the moment I have very little spare time in order to update the PR TO latest main branch to begin with. |
And I should add that I am under the impression that it would be more appreciated if the update mechanism would be UF2. |
This is an automated heads-up that we've just merged a Pull Request See #13763 A search suggests this PR might apply the STATIC macro to some C code. If it Although this is an automated message, feel free to @-reply to me directly if |
Support for a UF2 bootloader was added in PR #15983, so closing this one. |
Adds bootloader for mimxrt port with DFU support.
Signed-off-by: Philipp Ebensberger