riotboot: Mode selection for boards#16011
Conversation
|
While I'm not a big fan of adding any more preprocessor stuff where not
absolutely necessary, in this case yes, I think that'd be nice.
(To the point where the introduction of a function could be
postponed until *any* board does a startup check that is *not* just
setting and reading a GPIO pin).
|
bootloaders/riotboot_dfu/Makefile
Outdated
| ifneq (,$(filter bootloader_alternative_mode,$(FEATURES_USED))) | ||
| CFLAGS += -DALTERNATIVE_MODE | ||
| endif |
There was a problem hiding this comment.
I would add a PSEUDOMODULE instead (answering your question)
boards/common/particle-mesh/board.c
Outdated
| bool board_bootloader_alternative_mode(void) | ||
| { | ||
| /* If the application button is pressed, this indicates that the bootloader | ||
| * should switch to its alternative mode (eg. DFU recovery). */ | ||
| gpio_init(BTN0_PIN, BTN0_MODE); | ||
| return !gpio_read(BTN0_PIN); | ||
| } |
There was a problem hiding this comment.
The button should probably be configurable no? I imagine many will implement this, and it will pretty much be the same only maybe with different pin numbers.
There was a problem hiding this comment.
If we're going with the Ben's suggestion, the board.h of providing boards would
#eefine BTN_BOOTLOADER_PIN BTN0_PINetc -- but per board it can IMO be fixed (especially on boards that have only one button)
|
Based on benpicco's original comment and dylad's note on IRC I think this can be vastly simplified, to the point where any board's BTN0 makes the bootloader divert when pressed, and the boards can override that. So no features, no pseudomodules, no dependencies, just a small preprocessor default and an optional GPIO step. |
|
Thanks for all your input, this is all much simpler now. (If and when boards need an actual function to be evaluated, that can still be added at that point, but maybe it never will.) My remaining qualm is that the documentation, even though written, is not visible, for bootloaders are not part of what's built into the documentation. (Which also means that riotboot/README.md is not rendered). It's all prepared though, so whenever we do something there it should show up in the docs. |
|
Sorry for the many fixups; I think by all I've fumbled around here it should be much more readable if I squash. |
fdeea7b to
5f18e29
Compare
|
Does this mean it's good for squashing final review? |
This is fine by me. |
51d8ce5 to
2669f05
Compare
|
Looks good to me. I succesfully tested this PR on SAML21-XPRO, press & hold BTN0, then reset and the board stays in bootloader mode as expected. |
dylad
left a comment
There was a problem hiding this comment.
last comments, you can squash directly.
Boards can override this; by default it's BTN0
2669f05 to
d770917
Compare
|
Last changes addressed, thanks for pointing them out. CI seems to be happy -- are you too? |
dylad
left a comment
There was a problem hiding this comment.
ACK.
Looks good to me.
I tested this PR on SAML21-XPRO and it works as expected.
|
Here we go |
Contribution description
For USB bootloaders, it is common to have a way of entering the bootloader even when the application is not cooperating. A typical way is to poll a button on startup. (For example, the bootloaders shipped with nrf52840dongle and the particle xenon boards to that; the latter in a more elaborate fashion that includes blink patterns).
It doesn't help with remote bricking, and it doesn't help against flash writes to the bootloader (both of which might be mitigated by additional means), but solves the common case of "I forgot to give my application the right USEMODULES to get back into DFU" or "crash at board_init".
Testing procedure
make -C bootloaders/riotboot_dfu BOARD=particle-xenon PROGRAMMER=openocd DEBUG_ADAPTER=stlink all flashdfu-util -land seeing "Found DFU" (unless, of course, there happens to be a valid image in there; an openocdflash erase_sector 0 0 lastbefore the original programming ensures a cleans state)FEATURES_REQUIRED += riotbootto examples/filesystem/MakefileUSEMODULE += usbus_dfu, and the board doesn't even come up. (That's probably a different bug, at least an ACM TTY should come up). Add the USEMODULE to filesystem example.dfu-util -lthe device now shows "Found DFU", indicating it's in bootloader mode.Open questions
CFLAGS+=-D.... That looks uncommon, but creating a complete pseudomodule for it sounds extraneous. What's the best way?extern bool ...everywhere it's used.