#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-or-later """Check or explicitly erase a removable card for an N810 A/B installation.""" import argparse import json import os from pathlib import Path import plistlib import struct import subprocess import sys import hashlib from ab_runtime import atomic,digest MIB=1024*1024 def layout(m, capacity): sizes=[32*MIB,m['slot_mib']*MIB,m['slot_mib']*MIB] starts=[MIB] for size in sizes: starts.append(starts[-1]+size) if capacity < m.get('minimum_card_bytes', 0): raise ValueError('Card lacks space for the installed data and SD swap') if capacity-starts[-1] < m['files']['data.ext4']['bytes'] or capacity%512 or capacity//512 > 0xffffffff: raise ValueError('Card does not fit the A/B layout') sizes.append(capacity-starts[-1]) table=bytearray(MIB);struct.pack_into('