diff --git a/flash_system.sh b/flash_system.sh index 251d3ca..f449106 100755 --- a/flash_system.sh +++ b/flash_system.sh @@ -15,10 +15,9 @@ cd $DIR # Flash system fastboot --set-active=a -# TODO: clean this up. move simg2dimg into a common repo? if [ -d $HOME/openpilot/provisioning ]; then DIMG=$(mktemp) - $HOME/openpilot/provisioning/scripts/simg2dontcare.py $OUTPUT_DIR/$ROOTFS_IMAGE $DIMG + $DIR/tools/simg2dontcare.py $OUTPUT_DIR/$ROOTFS_IMAGE $DIMG fastboot erase system_a fastboot flash system_a $DIMG else diff --git a/tools/simg2dontcare.py b/tools/simg2dontcare.py new file mode 100755 index 0000000..5a95a0a --- /dev/null +++ b/tools/simg2dontcare.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 +import argparse +import sys +import struct +from enum import IntEnum + +# https://android.googlesource.com/platform/system/core/+/master/libsparse/sparse_format.h +class ChunkType(IntEnum): + RAW = 0xCAC1 + FILL = 0xCAC2 + DONT_CARE = 0xCAC3 + CRC32 = 0xCAC4 + +ChunkHeader = struct.Struct("<2H2I") + + +def process_image(input_image: str, output_image: str) -> None: + with open(input_image, "rb") as inf, open(output_image, "wb") as outf: + dat = inf.read(28) + outf.write(dat) + + header = struct.unpack("