Merge pull request #4 from neochapay/master
Allow to install rootfs from custom dir and raw images
This commit is contained in:
commit
c1c656b1a6
86
flash-it.sh
86
flash-it.sh
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
VERSION="0.2.0"
|
VERSION="0.2.0"
|
||||||
BRANCH=master
|
BRANCH=master
|
||||||
|
CUSTOM=""
|
||||||
UBOOT_JOB=u-boot
|
UBOOT_JOB=u-boot
|
||||||
UBOOT_DIR=u-boot-bootloader
|
UBOOT_DIR=u-boot-bootloader
|
||||||
ROOTFS_PINEPHONE_JOB=pinephone-rootfs
|
ROOTFS_PINEPHONE_JOB=pinephone-rootfs
|
||||||
|
@ -38,6 +39,9 @@ case $key in
|
||||||
"" \
|
"" \
|
||||||
"Options:" \
|
"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." \
|
" -b, --branch BRANCH Download images from a specific Git branch." \
|
||||||
" -h, --help Print this help and exit." \
|
" -h, --help Print this help and exit." \
|
||||||
"" \
|
"" \
|
||||||
|
@ -50,6 +54,11 @@ case $key in
|
||||||
exit 0
|
exit 0
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-c|--custom)
|
||||||
|
CUSTOM="$2"
|
||||||
|
shift
|
||||||
|
shift
|
||||||
|
;;
|
||||||
*) # unknown argument
|
*) # unknown argument
|
||||||
POSITIONAL+=("$1") # save it in an array for later
|
POSITIONAL+=("$1") # save it in an array for later
|
||||||
shift # past argument
|
shift # past argument
|
||||||
|
@ -91,7 +100,30 @@ check_dependency "tar"
|
||||||
check_dependency "unzip"
|
check_dependency "unzip"
|
||||||
check_dependency "lsblk"
|
check_dependency "lsblk"
|
||||||
check_dependency "mkfs.ext4"
|
check_dependency "mkfs.ext4"
|
||||||
|
check_dependency "losetup"
|
||||||
|
|
||||||
|
# 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?
|
# Different branch for some reason?
|
||||||
if [ "${BRANCH}" != "master" ]; then
|
if [ "${BRANCH}" != "master" ]; then
|
||||||
echo -e "\e[1m\e[97m!!! Will flash image from ${BRANCH} branch !!!\e[0m"
|
echo -e "\e[1m\e[97m!!! Will flash image from ${BRANCH} branch !!!\e[0m"
|
||||||
|
@ -126,22 +158,21 @@ $WGET "${ROOTFS_JOB}.zip" "${ROOTFS_DOWNLOAD}" || {
|
||||||
echo >&2 "Root filesystem image download failed. Aborting."
|
echo >&2 "Root filesystem image download failed. Aborting."
|
||||||
exit 2
|
exit 2
|
||||||
}
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
# Select flash target
|
# Select flash target
|
||||||
echo -e "\e[1mWhich SD card do you want to flash?\e[0m"
|
echo -e "\e[1mWhich SD card do you want to flash?\e[0m"
|
||||||
lsblk
|
lsblk
|
||||||
|
echo "raw"
|
||||||
read -p "Device node (/dev/sdX): " DEVICE_NODE
|
read -p "Device node (/dev/sdX): " DEVICE_NODE
|
||||||
echo "Flashing image to: $DEVICE_NODE"
|
echo "Flashing image to: $DEVICE_NODE"
|
||||||
echo "WARNING: All data will be erased! You have been warned!"
|
echo "WARNING: All data will be erased! You have been warned!"
|
||||||
echo "Some commands require root permissions, you might be asked to enter your sudo password."
|
echo "Some commands require root permissions, you might be asked to enter your sudo password."
|
||||||
|
|
||||||
# use p1, p2 extentions instead of 1, 2 when using sd drives
|
#create loop file for raw.img
|
||||||
if [[ $(echo $DEVICE_NODE | grep mmcblk) ]]; then
|
if [ $DEVICE_NODE == "raw" ]; then
|
||||||
BOOTPART="${DEVICE_NODE}p1"
|
sudo dd if=/dev/zero of=sdcard.img bs=1 count=0 seek=4G
|
||||||
DATAPART="${DEVICE_NODE}p2"
|
DEVICE_NODE="./sdcard.img"
|
||||||
else
|
|
||||||
BOOTPART="${DEVICE_NODE}1"
|
|
||||||
DATAPART="${DEVICE_NODE}2"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Creating EXT4 file system
|
# Creating EXT4 file system
|
||||||
|
@ -154,21 +185,47 @@ done
|
||||||
sudo parted $DEVICE_NODE mklabel msdos --script
|
sudo parted $DEVICE_NODE mklabel msdos --script
|
||||||
sudo parted $DEVICE_NODE mkpart primary ext4 1MB 250MB --script
|
sudo parted $DEVICE_NODE mkpart primary ext4 1MB 250MB --script
|
||||||
sudo parted $DEVICE_NODE mkpart primary ext4 250MB 100% --script
|
sudo parted $DEVICE_NODE mkpart primary ext4 250MB 100% --script
|
||||||
|
|
||||||
|
if [ $DEVICE_NODE == "./sdcard.img" ]; then
|
||||||
|
echo "Prepare loop file"
|
||||||
|
sudo losetup -D
|
||||||
|
sudo losetup -Pf sdcard.img
|
||||||
|
LOOP_NODE=`ls /dev/loop?p1 | cut -c10-10`
|
||||||
|
DEVICE_NODE="/dev/loop$LOOP_NODE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# use p1, p2 extentions instead of 1, 2 when using sd drives
|
||||||
|
if [ [ $(echo $DEVICE_NODE | grep mmcblk) ] || [ $(echo $DEVICE_NODE | grep loop)] ]; then
|
||||||
|
BOOTPART="${DEVICE_NODE}p1"
|
||||||
|
DATAPART="${DEVICE_NODE}p2"
|
||||||
|
else
|
||||||
|
BOOTPART="${DEVICE_NODE}1"
|
||||||
|
DATAPART="${DEVICE_NODE}2"
|
||||||
|
fi
|
||||||
|
|
||||||
sudo mkfs.ext4 -F -L boot $BOOTPART # 1st partition = boot
|
sudo mkfs.ext4 -F -L boot $BOOTPART # 1st partition = boot
|
||||||
sudo mkfs.ext4 -F -L data $DATAPART # 2nd partition = data
|
sudo mkfs.ext4 -F -L data $DATAPART # 2nd partition = data
|
||||||
|
|
||||||
# Flashing u-boot
|
# Flashing u-boot
|
||||||
echo -e "\e[1mFlashing U-boot...\e[0m"
|
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"
|
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
|
sudo dd if="./u-boot-bootloader/u-boot/u-boot-sunxi-with-spl.bin" of="$DEVICE_NODE" bs=8k seek=1
|
||||||
|
fi
|
||||||
sync
|
sync
|
||||||
|
|
||||||
# Flashing rootFS
|
# Flashing rootFS
|
||||||
echo -e "\e[1mFlashing rootFS...\e[0m"
|
echo -e "\e[1mFlashing rootFS...\e[0m"
|
||||||
|
mkdir "$MOUNT_DATA"
|
||||||
|
if [ "$CUSTOM" != "" ]; then
|
||||||
|
TEMP="${CUSTOM}/rootfs.tar.bz2"
|
||||||
|
else
|
||||||
unzip "${ROOTFS_JOB}.zip"
|
unzip "${ROOTFS_JOB}.zip"
|
||||||
TEMP=`ls $ROOTFS_DIR/*/*.tar.bz2`
|
TEMP=`ls $ROOTFS_DIR/*/*.tar.bz2`
|
||||||
echo "$TEMP"
|
echo "$TEMP"
|
||||||
mkdir "$MOUNT_DATA"
|
fi
|
||||||
sudo mount $DATAPART "$MOUNT_DATA" # Mount data partition
|
sudo mount $DATAPART "$MOUNT_DATA" # Mount data partition
|
||||||
sudo tar -xpf "$TEMP" -C "$MOUNT_DATA"
|
sudo tar -xpf "$TEMP" -C "$MOUNT_DATA"
|
||||||
sync
|
sync
|
||||||
|
@ -178,7 +235,11 @@ echo -e "\e[1mCopying kernel to boot partition...\e[0m"
|
||||||
mkdir "$MOUNT_BOOT"
|
mkdir "$MOUNT_BOOT"
|
||||||
sudo mount $BOOTPART "$MOUNT_BOOT" # Mount boot partition
|
sudo mount $BOOTPART "$MOUNT_BOOT" # Mount boot partition
|
||||||
sudo cp $MOUNT_DATA/boot/* $MOUNT_BOOT
|
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"
|
sudo cp "./u-boot-bootloader/$ROOTFS_DIR/boot.scr" "$MOUNT_BOOT/boot.scr"
|
||||||
|
fi
|
||||||
sync
|
sync
|
||||||
|
|
||||||
# Clean up files
|
# Clean up files
|
||||||
|
@ -188,12 +249,17 @@ do
|
||||||
echo "Unmounting $PARTITION"
|
echo "Unmounting $PARTITION"
|
||||||
sudo umount $PARTITION
|
sudo umount $PARTITION
|
||||||
done
|
done
|
||||||
|
|
||||||
|
sudo losetup -D
|
||||||
|
|
||||||
|
if [ "$CUSTOM" == "" ]; then
|
||||||
rm "${UBOOT_JOB}.zip"
|
rm "${UBOOT_JOB}.zip"
|
||||||
rm -r "$UBOOT_DIR"
|
rm -r "$UBOOT_DIR"
|
||||||
rm "${ROOTFS_JOB}.zip"
|
rm "${ROOTFS_JOB}.zip"
|
||||||
rm -r "$ROOTFS_DIR"
|
rm -r "$ROOTFS_DIR"
|
||||||
rm -rf "$MOUNT_DATA"
|
fi
|
||||||
rm -rf "$MOUNT_BOOT"
|
sudo rm -rf "$MOUNT_DATA"
|
||||||
|
sudo rm -rf "$MOUNT_BOOT"
|
||||||
|
|
||||||
# Done :)
|
# Done :)
|
||||||
echo -e "\e[1mFlashing $DEVICE_NODE OK!\e[0m"
|
echo -e "\e[1mFlashing $DEVICE_NODE OK!\e[0m"
|
||||||
|
|
Loading…
Reference in New Issue