From 2ef43447b4e7c20fe301046aecacdac2697496e9 Mon Sep 17 00:00:00 2001 From: Sergey Chupligin Date: Mon, 17 Feb 2020 18:24:13 +0300 Subject: [PATCH] Allow to install rootfs from custom dir --- flash-it.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/flash-it.sh b/flash-it.sh index 5b00ac1..5624e4a 100755 --- a/flash-it.sh +++ b/flash-it.sh @@ -2,6 +2,7 @@ VERSION="0.2.0" BRANCH=master +CUSTOM="" UBOOT_JOB=u-boot UBOOT_DIR=u-boot-bootloader ROOTFS_PINEPHONE_JOB=pinephone-rootfs @@ -38,6 +39,9 @@ case $key in "" \ "Options:" \ "" \ + " -c, --custom Install from custom dir. Just put you rootfs.tar.bz2" \ + " and u-boot-sunxi-with-spl.bin into dir and system will "\ + " istalled from it" \ " -b, --branch BRANCH Download images from a specific Git branch." \ " -h, --help Print this help and exit." \ "" \ @@ -50,6 +54,11 @@ case $key in exit 0 shift ;; + -c|--custom) + CUSTOM="$2" + shift + shift + ;; *) # unknown argument POSITIONAL+=("$1") # save it in an array for later shift # past argument @@ -92,6 +101,28 @@ check_dependency "unzip" check_dependency "lsblk" check_dependency "mkfs.ext4" +# If use custom dir check it +if [ "$CUSTOM" != "" ]; then + if ! [ -d "$CUSTOM" ]; then + echo -e "\e[1m\e[97m!!! Directory ${CUSTOM} not exist !!!\e[0m" + exit 2; + fi + + if ! [ -f "$CUSTOM/rootfs.tar.bz2" ]; then + echo -e "\e[1m\e[97m!!! rootfs ${CUSTOM}/rootfs.tar.bz2 not found !!!\e[0m" + exit 2; + fi + + if ! [ -f "$CUSTOM/u-boot-sunxi-with-spl.bin" ]; then + echo -e "\e[1m\e[97m!!! uboot image ${CUSTOM}/u-boot-sunxi-with-spl.bin not found !!!\e[0m" + exit 2; + fi + + if ! [ -f "$CUSTOM/boot.scr" ]; then + echo -e "\e[1m\e[97m!!! uboot config ${CUSTOM}/boot.scr not found !!!\e[0m" + exit 2; + fi +else # Different branch for some reason? if [ "${BRANCH}" != "master" ]; then echo -e "\e[1m\e[97m!!! Will flash image from ${BRANCH} branch !!!\e[0m" @@ -126,6 +157,7 @@ $WGET "${ROOTFS_JOB}.zip" "${ROOTFS_DOWNLOAD}" || { echo >&2 "Root filesystem image download failed. Aborting." exit 2 } +fi # Select flash target echo -e "\e[1mWhich SD card do you want to flash?\e[0m" @@ -159,16 +191,24 @@ sudo mkfs.ext4 -F -L data $DATAPART # 2nd partition = data # Flashing u-boot echo -e "\e[1mFlashing U-boot...\e[0m" +if [ "$CUSTOM" != "" ]; then +sudo dd if="${CUSTOM}/u-boot-sunxi-with-spl.bin" of="$DEVICE_NODE" bs=8k seek=1 +else unzip "${UBOOT_JOB}.zip" sudo dd if="./u-boot-bootloader/u-boot/u-boot-sunxi-with-spl.bin" of="$DEVICE_NODE" bs=8k seek=1 +fi sync # Flashing rootFS echo -e "\e[1mFlashing rootFS...\e[0m" +mkdir "$MOUNT_DATA" +if [ "$CUSTOM" != "" ]; then +TEMP="${CUSTOM}/rootfs.tar.bz2" +else unzip "${ROOTFS_JOB}.zip" TEMP=`ls $ROOTFS_DIR/*/*.tar.bz2` echo "$TEMP" -mkdir "$MOUNT_DATA" +fi sudo mount $DATAPART "$MOUNT_DATA" # Mount data partition sudo tar -xpf "$TEMP" -C "$MOUNT_DATA" sync @@ -178,7 +218,11 @@ echo -e "\e[1mCopying kernel to boot partition...\e[0m" mkdir "$MOUNT_BOOT" sudo mount $BOOTPART "$MOUNT_BOOT" # Mount boot partition sudo cp $MOUNT_DATA/boot/* $MOUNT_BOOT +if [ "$CUSTOM" != "" ]; then +sudo cp "${CUSTOM}/boot.scr" "$MOUNT_BOOT/boot.scr" +else sudo cp "./u-boot-bootloader/$ROOTFS_DIR/boot.scr" "$MOUNT_BOOT/boot.scr" +fi sync # Clean up files @@ -188,10 +232,13 @@ do echo "Unmounting $PARTITION" sudo umount $PARTITION done + +if [ "$CUSTOM" == "" ]; then rm "${UBOOT_JOB}.zip" rm -r "$UBOOT_DIR" rm "${ROOTFS_JOB}.zip" rm -r "$ROOTFS_DIR" +fi rm -rf "$MOUNT_DATA" rm -rf "$MOUNT_BOOT"