#!/usr/bin/env python3 """Read a U-Boot environment file (uboot.env, non-redundant format). Format: 4-byte little-endian CRC32 of the data area, then NUL-terminated "name=value" strings, ended by an empty string. U-Boot reads CONFIG_ENV_SIZE bytes and computes the CRC over all of them but the first 4, so the file is only accepted by a U-Boot built with the size it was saved with. Usage: uboot-env.py check FILE ENV_SIZE exit 0 if a U-Boot with this CONFIG_ENV_SIZE accepts FILE, else 1 uboot-env.py size FILE print the size the CRC is valid for (empty and exit 1 if none) uboot-env.py vars FILE print name=value per line (newlines in values become spaces); exit 1 if no size validates the CRC """ import struct import sys import zlib def crc_ok(data, size): if len(data) < size or size <= 4: return False return zlib.crc32(data[4:size]) == struct.unpack("