Skip to content

Improve SPI Flashing#36

Merged
samueldr merged 18 commits intoTow-Boot:developmentfrom
samueldr:feature/better-spi-flashing
Jun 26, 2021
Merged

Improve SPI Flashing#36
samueldr merged 18 commits intoTow-Boot:developmentfrom
samueldr:feature/better-spi-flashing

Conversation

@samueldr
Copy link
Contributor

@samueldr samueldr commented Jun 25, 2021

This brings some changes to the way SPI flashing is done.

Prevent flashing to the wrong board

(Fixes #3)

In this somewhat breaking change, the script will fail if the $board_identifier variable doesn't match a build-time hardcoded constant. This constant is coincidentally the identifier used in the attrset for the board. Though it could have been different if we desired so. The main thing to know is that this identifier will stay the same for the same board, allowing scripts to distinguish between boards.

Flashing anyway

The easiest method is to drop to the shell (using ESC or CTRL-C during boot) and using env set board_identifier XYZ where XYZ is the name of the board you want to flash to.

Saved environment missing $board_identifier

While unlikely as the last stable version did not manage environment, and this will land on the same release as #34, here's the problem.

You might have a saved environment without $board_identifier set. The fix is simple, use env default board_identifier to reset that specific variable, and env save to save the environment.

Hardened flashing scheme

(Fixes #28)

The idea is to first brick the SPI-installed firmware in a way the Boot ROM will not recognize. This means that if the installation is failing in an uncontrolled manner, the user should be able to recover using an alternate boot method (e.g. SD card or eMMC).

Then, after bricking, flash almost all of the new firmware. Then flash the missing bit.

By writing the "magic number" the Boot ROM looks for last, we harden ourselves from accidental partial writes. E.g. if there was sudden power loss.

@samueldr samueldr force-pushed the feature/better-spi-flashing branch 4 times, most recently from 45465e4 to d5bc5f7 Compare June 26, 2021 05:05
@samueldr samueldr marked this pull request as ready for review June 26, 2021 05:05
samueldr added 17 commits June 26, 2021 01:34
This will be used to discriminate against boards in installer and
updater scripts.
This helps prevent the dangerous situation where you could write the
wrong firmware to the wrong board.

While writing the firmware for another family of board is likely not an
issue, writing a firmware that looks valid enough to the boot rom for
the board is likely to put the user in a pickle.

Fixes Tow-Boot#3
This barely changes the behaviour compared to previously.
The goal here is to minimize the changes when looking at the upcoming fallback logic.
This is done by splitting the write in a head and tail of the firmware.

We first remove the SPI Flash from the boot chain by making it invalid
(zeroing out the start).

Then we write the end of the firmware.

Finally we write the "head".

Hopefully any unexpected failure (e.g. sudden power loss) happens
before the head is written, this way the user is not "bricked".
@samueldr samueldr force-pushed the feature/better-spi-flashing branch from d5bc5f7 to d1130c4 Compare June 26, 2021 05:34
@samueldr samueldr added this to the "next" milestone Jun 26, 2021
@samueldr samueldr merged commit 20ebdc8 into Tow-Boot:development Jun 26, 2021
@samueldr samueldr deleted the feature/better-spi-flashing branch June 26, 2021 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

More robust install / upgrade Make installer scripts aware of the target board

1 participant