1#!/usr/bin/env bash 2if [ -z "$ANDROID_BUILD_TOP" ] 3then 4 echo "You must run lunch to setup the environment" 5 exit 1 6fi 7 8set -e 9BOOTLOADER_IMG="bootloader.img" 10RADIO_IMG="radio.img" 11BOOTLOADER_UNPACKED="bootloader_unpacked" 12RADIO_UNPACKED="radio_unpacked" 13BUILD_IMG_PATH="$ANDROID_BUILD_TOP/vendor/google_devices/crosshatch/prebuilts" 14BOOTLOADER_PATH="$BUILD_IMG_PATH/$BOOTLOADER_IMG" 15RADIO_PATH="$BUILD_IMG_PATH/$RADIO_IMG" 16TOOL="$ANDROID_HOST_OUT/testcases/fuzzy_fastboot/x86_64/fuzzy_fastboot" 17CONFIG_PATH=$(dirname $0) 18UNPACK_TOOL="python2 $ANDROID_BUILD_TOP/vendor/google_devices/crosshatch/prebuilts/unpack.py" 19 20# Generate the garbage images 21RADIO_SIZE=$(wc -c <"$RADIO_PATH") 22BOOTLOADER_SIZE=$(wc -c <"$BOOTLOADER_PATH") 23head -c $RADIO_SIZE </dev/urandom>radio_garbage.img 24head -c $BOOTLOADER_SIZE </dev/urandom>bootloader_garbage.img 25 26# Symlink the good images 27ln -s "$BOOTLOADER_PATH" "$BOOTLOADER_IMG" 28ln -s "$RADIO_PATH" "$RADIO_IMG" 29 30# Unpack them 31$UNPACK_TOOL $BOOTLOADER_IMG -o $BOOTLOADER_UNPACKED 32$UNPACK_TOOL $RADIO_IMG -o $RADIO_UNPACKED 33 34# Make the output image directory 35mkdir -p "$CONFIG_PATH/output" 36 37# Run fuzzy_fastboot 38$TOOL "--search_path=$CONFIG_PATH" "--config=config.xml" "--output_path=output" "--serial_port=/dev/ttyUSB0" "$@" 39 40# Clean up 41rm radio_garbage.img 42rm bootloader_garbage.img 43rm "$BOOTLOADER_IMG" 44rm "$RADIO_IMG" 45rm -rf "$RADIO_UNPACKED" 46rm -rf "$BOOTLOADER_UNPACKED" 47