diff --git a/flash_scripts/android_flash_base_aaos.sh b/flash_scripts/android_flash_base_aaos.sh new file mode 100644 index 0000000..ab13c80 --- /dev/null +++ b/flash_scripts/android_flash_base_aaos.sh @@ -0,0 +1,77 @@ +# Copyright (C) 2024 Intel Corporation +# Author: Chen, Gang G +# SPDX-License-Identifier: BSD-3-Clause + +#!/bin/sh + +ZIP_FILE=$(readlink -f $1) +VM_IMG=$(readlink -f $2) +EXTRACT_DISK=/dev/nvme0n1p5 + +usage() +{ + echo $1 + echo "Usage: $0 .zip " + echo "disk_name can be partition(/dev/nvme0n1pX) or virtual_disk(//aaos.img)" + echo "If you want to use virtual_disk(/home/root/aaos.img), please create it in advance" + echo "For example: create a 400GB image. please make sure your disk has enough space" + echo "command: fallocate -l 400G //aaos.img" +} + +if [ $# != 2 ]; then + usage "Invalid arguments" + exit 1 +fi + +if [ ! -f $ZIP_FILE ]; then + usage "$ZIP_FILE not exist" + exit 1 +fi + +if [ ! -e $VM_IMG ]; then + usage "$VM_IMG not exist" + exit 1 +fi + +echo "You are going to create image ($VM_IMG) for VM" +echo "You are going to format ($EXTRACT_DISK) as temporary extraction location" +echo "Please confirm that output image paths are correct !" +read -p "Continue ? [y/n]" yn +case $yn in + [Yy]*) ;; + [Nn]*) exit;; +esac + +mkfs.ext4 $VM_IMG -F + +if [ ! -e $EXTRACT_DISK ]; then + usage "$EXTRACT_DISK not exist" + exit 1 +fi + +mkfs.ext4 $EXTRACT_DISK -F + +TEMP_DIR=/home/root/image + +rm -rf $TEMP_DIR +mkdir -p $TEMP_DIR +mount $EXTRACT_DISK $TEMP_DIR + +cd $TEMP_DIR +case $ZIP_FILE in + *.zip) 7z x $ZIP_FILE;; + *.tar.gz) tar -xvzf $ZIP_FILE;; + *) echo "Please make sure the image suffix is ".gz" or "tar.gz"; exit" + exit 0 + ;; +esac + +simg2img super.img super.img.raw +mv super.img.raw super.img +simg2img config.img config.img.raw +mv config.img.raw config.img +cd - + +SIZE_GB=$(fdisk -l $VM_IMG | grep Disk | awk '{print $3}') +SIZE_GB=$(awk "BEGIN {print int($SIZE_GB)}") +python3 ./create_gpt_image.py --create $VM_IMG --size=${SIZE_GB}G --flashfiles $TEMP_DIR diff --git a/flash_scripts/android_flash_vm1_2.sh b/flash_scripts/android_flash_vm1_2.sh new file mode 100755 index 0000000..87e23ee --- /dev/null +++ b/flash_scripts/android_flash_vm1_2.sh @@ -0,0 +1,87 @@ +# Copyright (C) 2024 Intel Corporation +# Author: Chen, Gang G +# SPDX-License-Identifier: BSD-3-Clause + +#!/bin/sh + +usage() +{ + echo $1 + echo "Usage: $0 .zip " +} + +if [ $# != 4 ]; then + usage "Invalid arguments" + exit 1 +fi + +ZIP_FILE=$(readlink -f $1) +VM_RO_IMG=$(readlink -f $2) +VM1_RW_IMG=$(readlink -f $3) +VM2_RW_IMG=$(readlink -f $4) + +if [ ! -f $ZIP_FILE ]; then + usage "$ZIP_FILE not exist" + exit 1 +fi + +echo "You are going to create a readonly image ($VM_RO_IMG) for both VM1 and VM2" +echo "and two read-write images ($VM1_RW_IMG and $VM2_RW_IMG) for VM1 and VM2 separately" +echo "Please confirm that output image paths are correct !" +read -p "Continue ? [y/n]" yn +case $yn in + [Yy]*) ;; + [Nn]*) exit;; +esac + +mkfs.ext4 $VM_RO_IMG -F +mkfs.ext4 $VM1_RW_IMG -F +mkfs.ext4 $VM2_RW_IMG -F +TEMP_DIR=$(mktemp -d) +pushd $TEMP_DIR +7z x $ZIP_FILE +simg2img super.img super.img.raw +mv super.img.raw super.img +simg2img config.img config.img.raw +mv config.img.raw config.img +popd + +GPT_INI=/home/root/android-flashtool/gpt.ini +if [ -f $TEMP_DIR/gpt.ini ]; then + GPT_INI=$TEMP_DIR/gpt.ini + echo "Use gpt.ini in flashfiles: $GPT_INI" +elif [ -f $GPT_INI ]; then + echo "Use default gpt.ini: $GPT_INI" +else + echo "No gpt.ini found! exit!" + exit 0 +fi + +TEMP_INI=$(mktemp) +sed -e '/partitions =/s/teedata //g' $GPT_INI >$TEMP_INI +sed -e '/partitions =/s/share_data//g' -e '/partitions =/s/metadata //g' -e '/partitions =/s/persistent //g' -e '/partitions =/s/data //g' -i $TEMP_INI +SIZE_GB=$(fdisk -l $VM_RO_IMG | grep Disk | awk '{print $3}') +SIZE_GB=$(awk "BEGIN {print int($SIZE_GB)}") +python3 ./gpt_ini2bin.py $TEMP_INI > ${TEMP_DIR}/gpt.bin +python3 ./create_gpt_image.py --create $VM_RO_IMG --size=${SIZE_GB}G --flashfiles $TEMP_DIR + +cp $GPT_INI $TEMP_INI +sed -e '/partitions =/s/bootloader //g' -e '/partitions =/s/boot //g' -e '/partitions =/s/misc //g' -i $TEMP_INI +sed -e '/partitions =/s/acpio //g' -e '/partitions =/s/super //g' -e '/partitions =/s/vbmeta //g' -i $TEMP_INI +sed -e '/partitions =/s/share_data//g' -i $TEMP_INI #vm1/2 only +sed -e 's/partitions += vendor_boot//' -i $TEMP_INI +sed -e 's/partitions += config//' -i $TEMP_INI +sed -e 's/len = 128000/len = -1/' -i $TEMP_INI #vm1/2 only + +SIZE_GB=$(fdisk -l $VM1_RW_IMG | grep Disk | awk '{print $3}') +SIZE_GB=$(awk "BEGIN {print int($SIZE_GB)}") +python3 ./gpt_ini2bin.py $TEMP_INI > ${TEMP_DIR}/gpt.bin +python3 ./create_gpt_image.py --create $VM1_RW_IMG --size=${SIZE_GB}G --flashfiles $TEMP_DIR + +SIZE_GB=$(fdisk -l $VM2_RW_IMG | grep Disk | awk '{print $3}') +SIZE_GB=$(awk "BEGIN {print int($SIZE_GB)}") +python3 ./gpt_ini2bin.py $TEMP_INI > ${TEMP_DIR}/gpt.bin +python3 ./create_gpt_image.py --create $VM2_RW_IMG --size=${SIZE_GB}G --flashfiles $TEMP_DIR + +rm -rf ${TEMP_DIR}/* +sync diff --git a/flash_scripts/android_flash_vm3.sh b/flash_scripts/android_flash_vm3.sh new file mode 100755 index 0000000..3efdacc --- /dev/null +++ b/flash_scripts/android_flash_vm3.sh @@ -0,0 +1,77 @@ +# Copyright (C) 2024 Intel Corporation +# Author: Chen, Gang G +# SPDX-License-Identifier: BSD-3-Clause + +#!/bin/sh + +usage() +{ + echo $1 + echo "Usage: $0 .zip " +} + +if [ $# != 3 ]; then + usage "Invalid arguments" + exit 1 +fi + +ZIP_FILE=$(readlink -f $1) +VM_RO_IMG=$(readlink -f $2) +VM3_RW_IMG=$(readlink -f $3) + +if [ ! -f $ZIP_FILE ]; then + usage "$ZIP_FILE not exist" + exit 1 +fi + +echo "You are going to create image ($VM_RO_IMG) for VM1 and image($VM3_RW_IMG ) for VM3" +echo "Please confirm that output image paths are correct !" +read -p "Continue ? [y/n]" yn +case $yn in + [Yy]*) ;; + [Nn]*) exit;; +esac + +mkfs.ext4 $VM_RO_IMG -F +mkfs.ext4 $VM3_RW_IMG -F +TEMP_DIR=$(mktemp -d) +pushd $TEMP_DIR +7z x $ZIP_FILE +simg2img super.img super.img.raw +mv super.img.raw super.img +simg2img config.img config.img.raw +mv config.img.raw config.img +popd + +GPT_INI=/home/root/android-flashtool/gpt.ini +if [ -f $TEMP_DIR/gpt.ini ]; then + GPT_INI=$TEMP_DIR/gpt.ini + echo "Use gpt.ini in flashfiles: $GPT_INI" +elif [ -f $GPT_INI ]; then + echo "Use default gpt.ini: $GPT_INI" +else + echo "No gpt.ini found! exit!" + exit 0 +fi + +TEMP_INI=$(mktemp) +sed -e '/partitions =/s/teedata //g' $GPT_INI >$TEMP_INI +sed -e '/partitions =/s/share_data//g' -e '/partitions =/s/metadata //g' -e '/partitions =/s/persistent //g' -e '/partitions =/s/data //g' -i $TEMP_INI +SIZE_GB=$(fdisk -l $VM_RO_IMG | grep Disk | awk '{print $3}') +SIZE_GB=$(awk "BEGIN {print int($SIZE_GB)}") +python3 ./gpt_ini2bin.py $TEMP_INI > ${TEMP_DIR}/gpt.bin +python3 ./create_gpt_image.py --create $VM_RO_IMG --size=${SIZE_GB}G --flashfiles $TEMP_DIR + +cp $GPT_INI $TEMP_INI +sed -e '/partitions =/s/bootloader //g' -e '/partitions =/s/boot //g' -e '/partitions =/s/misc //g' -i $TEMP_INI +sed -e '/partitions =/s/acpio //g' -e '/partitions =/s/super //g' -e '/partitions =/s/vbmeta //g' -i $TEMP_INI +sed -e 's/partitions += vendor_boot//' -i $TEMP_INI +sed -e 's/partitions += config//' -i $TEMP_INI + +SIZE_GB=$(fdisk -l $VM3_RW_IMG | grep Disk | awk '{print $3}') +SIZE_GB=$(awk "BEGIN {print int($SIZE_GB)}") +python3 ./gpt_ini2bin.py $TEMP_INI > ${TEMP_DIR}/gpt.bin +python3 ./create_gpt_image.py --create $VM3_RW_IMG --size=${SIZE_GB}G --flashfiles $TEMP_DIR + +rm -rf ${TEMP_DIR}/* +sync diff --git a/flash_scripts/flash_vm1_2_rw.sh b/flash_scripts/flash_vm1_2_rw.sh new file mode 100755 index 0000000..32d8aa5 --- /dev/null +++ b/flash_scripts/flash_vm1_2_rw.sh @@ -0,0 +1,56 @@ +# Copyright (C) 2024 Intel Corporation +# Author: Chen, Gang G +# SPDX-License-Identifier: BSD-3-Clause + +#!/bin/sh +# The script will format vm1 and vm2 rw partitions and flash GPT table to them + +usage() +{ + echo $1 + echo "Usage: $0 " +} + +if [ $# != 2 ]; then + usage "Invalid arguments" + exit 1 +fi + +VM1_RW_IMG=$(readlink -f $1) +VM2_RW_IMG=$(readlink -f $2) + +echo "You are going to create two read-write images ($VM1_RW_IMG and $VM2_RW_IMG) for VM1 and VM2 separately" +echo "Please confirm that output image paths are correct !" +read -p "Continue ? [y/n]" yn +case $yn in + [Yy]*) ;; + [Nn]*) exit;; +esac + +mkfs.ext4 $VM1_RW_IMG -F +mkfs.ext4 $VM2_RW_IMG -F + + +TEMP_DIR=$(mktemp -d) + +TEMP_INI=$(mktemp) +rm -rf ${TEMP_DIR}/* +cp gpt.ini $TEMP_INI +sed -e '/partitions =/s/bootloader //g' -e '/partitions =/s/boot //g' -e '/partitions =/s/misc //g' -i $TEMP_INI +sed -e '/partitions =/s/acpio //g' -e '/partitions =/s/super //g' -e '/partitions =/s/vbmeta //g' -i $TEMP_INI +sed -e '/partitions =/s/share_data//g' -i $TEMP_INI #vm1/2 only +sed -e 's/partitions += vendor_boot//' -i $TEMP_INI +sed -e 's/partitions += config//' -i $TEMP_INI +sed -e 's/len = 128000/len = -1/' -i $TEMP_INI #vm1/2 only + +SIZE_GB=$(fdisk -l $VM1_RW_IMG | grep Disk | awk '{print $3}') +SIZE_GB=$(awk "BEGIN {print int($SIZE_GB)}") +python3 ./gpt_ini2bin.py $TEMP_INI > ${TEMP_DIR}/gpt.bin +python3 ./create_gpt_image.py --create $VM1_RW_IMG --size=${SIZE_GB}G --flashfiles $TEMP_DIR + +SIZE_GB=$(fdisk -l $VM2_RW_IMG | grep Disk | awk '{print $3}') +SIZE_GB=$(awk "BEGIN {print int($SIZE_GB)}") +python3 ./gpt_ini2bin.py $TEMP_INI > ${TEMP_DIR}/gpt.bin +python3 ./create_gpt_image.py --create $VM2_RW_IMG --size=${SIZE_GB}G --flashfiles $TEMP_DIR + +sync diff --git a/flash_scripts/flash_vm3_rw.sh b/flash_scripts/flash_vm3_rw.sh new file mode 100755 index 0000000..df5295d --- /dev/null +++ b/flash_scripts/flash_vm3_rw.sh @@ -0,0 +1,46 @@ +# Copyright (C) 2024 Intel Corporation +# Author: Chen, Gang G +# SPDX-License-Identifier: BSD-3-Clause + +#!/bin/sh +# the script will format vm3 RW partition and flash GPT table to it + +usage() +{ + echo $1 + echo "Usage: $0 " +} + +if [ $# != 1 ]; then + usage "Invalid arguments" + exit 1 +fi + +VM3_RW_IMG=$(readlink -f $1) + +echo "You are going to create image ($VM3_RW_IMG ) for VM3" +echo "Please confirm that output image paths are correct !" +read -p "Continue ? [y/n]" yn +case $yn in + [Yy]*) ;; + [Nn]*) exit;; +esac + +mkfs.ext4 $VM3_RW_IMG -F + +TEMP_DIR=$(mktemp -d) +TEMP_INI=$(mktemp) + +rm -rf ${TEMP_DIR}/* +cp gpt.ini $TEMP_INI +sed -e '/partitions =/s/bootloader //g' -e '/partitions =/s/boot //g' -e '/partitions =/s/misc //g' -i $TEMP_INI +sed -e '/partitions =/s/acpio //g' -e '/partitions =/s/super //g' -e '/partitions =/s/vbmeta //g' -i $TEMP_INI +sed -e 's/partitions += vendor_boot//' -i $TEMP_INI +sed -e 's/partitions += config//' -i $TEMP_INI + +SIZE_GB=$(fdisk -l $VM3_RW_IMG | grep Disk | awk '{print $3}') +SIZE_GB=$(awk "BEGIN {print int($SIZE_GB)}") +python3 ./gpt_ini2bin.py $TEMP_INI > ${TEMP_DIR}/gpt.bin +python3 ./create_gpt_image.py --create $VM3_RW_IMG --size=${SIZE_GB}G --flashfiles $TEMP_DIR + +sync