File
Blob: scripts/backup_flash.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Back up and verify 32 MiB of flash. Reading enters the bootloader and resets the board.""" |
| 3 | import argparse |
| 4 | from serial_device import device_port |
| 5 | import subprocess |
| 6 | |
| 7 | from flash_backup import backup_directory, create_backup, require_backup |
| 8 | from project import ROOT |
| 9 | |
| 10 | def main(): |
| 11 | parser = argparse.ArgumentParser(description=__doc__) |
| 12 | parser.add_argument("--check", action="store_true", help="Check saved files and SHA-256 without contacting hardware") |
| 13 | args = parser.parse_args() |
| 14 | try: |
| 15 | if args.check: |
| 16 | image = require_backup() |
| 17 | print(f"Saved backup and SHA-256 verified: {image}") |
| 18 | else: |
| 19 | port = device_port() |
| 20 | image = create_backup(backup_directory(), port) |
| 21 | print(f"Flash backup verified and preserved: {image}") |
| 22 | except (OSError, ValueError, RuntimeError, subprocess.CalledProcessError) as error: |
| 23 | raise SystemExit(str(error)) from None |
| 24 | |
| 25 | |
| 26 | if __name__ == "__main__": |
| 27 | main() |