Compare commits

...

33 Commits

Author SHA1 Message Date
crt0mega 2378c7cd14 Merge pull request 'Improved script portability' (#19) from depsterr/master into master
Reviewed-on: #19
2021-07-06 19:17:31 +00:00
depsterr c4e56a64c7 Fixed duplicate string in options 2021-03-09 19:49:49 +01:00
depsterr dc9a075235 Include changes #20 and #23. 2021-03-09 19:15:28 +01:00
depsterr b6204adbd8 Merge branch 'master' of https://github.com/sailfish-on-dontbeevil/flash-it 2021-03-09 19:14:04 +01:00
depsterr 4e5f916555 fixed issue with copying boot files 2021-03-09 18:53:18 +01:00
Adam Pigg c95b0249f9
Merge pull request #23 from white-gecko/feature/pp12-fix
Fix options from #18.
2021-03-08 19:17:05 +00:00
Natanael Arndt 2df425c829 Fix options 2021-03-08 19:18:14 +01:00
Adam Pigg 81deccd4e9
Merge pull request #20 from white-gecko/feature/pp12
Add PinePhone 1.2 to image selection.
2021-03-08 12:52:13 +00:00
Natanael Arndt 5059792eb9 Fix #18. Add PinePhone 1.2 to image selection. 2021-03-08 12:08:55 +01:00
depsterr 0e62ac551c Improved script portability 2021-03-06 17:02:10 +01:00
Adam Pigg 801d0287fc
Merge pull request #17 from white-gecko/feature/check_sudo_dependency
Introduce check_sudo_dependency.
2021-03-06 11:11:31 +00:00
Natanael Arndt 79a63f5816 Fix #16. Introduce check_sudo_dependency. 2021-03-06 10:58:22 +01:00
Adam Pigg 19d3b5637c
Merge pull request #15 from simonschmeisser/include-crust
hack that loads compiled crust from pine64
2020-12-30 14:51:15 +00:00
Simon Schmeisser 97eb6078f7 hack that loads compiled crust from pine64 2020-11-16 21:36:05 +01:00
Adam Pigg 24b9738262 Add pinetabdev device, which uses the normal pinetab rootfs, but
different uboot script
2020-10-22 12:12:30 +01:00
Dylan Van Assche 6c3dbc09f1
Merge pull request #11 from sailfish-on-dontbeevil/fix-copy-dtb
Copy all files/folders in /boot to the boot partition.
2020-09-05 19:14:07 +00:00
Adam Pigg e7152942bc Copy all files/folders in /boot to the boot partition.
New uboot looks in allwinne/* for the dtb files, and the new kernel
properly populates its /boot folder with the allwinner folder and the
backup files in /boot
2020-09-05 19:33:34 +01:00
Dylan Van Assche 9cf68b7b36
Merge pull request #9 from sailfish-on-dontbeevil/glob-expansion-failure
Fix glob expansion which resulted in some boot failures
2020-05-05 15:59:45 +02:00
Dylan Van Assche 1bd68e90e6
Fix glob expansion which resulted in some boot failures 2020-05-01 15:33:46 +02:00
Dylan Van Assche 51baade149
Switch back to master branch 2020-05-01 07:14:04 +00:00
Dylan Van Assche 1deabc8180
Merge pull request #8 from sailfish-on-dontbeevil/pinephone-revisions
Enable pinephone revisions
2020-04-30 18:16:58 +00:00
Dylan Van Assche 1fc0092d16
Enable pinephone revisions 2020-04-30 20:16:23 +02:00
Dylan Van Assche c7f878a2f7
Merge pull request #7 from depsterr/master
fixed issue with check always returning true
2020-03-03 08:32:59 +00:00
depsterr f734780f4e fixed issue with check always returning true 2020-02-25 15:30:12 +01:00
Dylan Van Assche c1c656b1a6
Merge pull request #4 from neochapay/master
Allow to install rootfs from custom dir and raw images
2020-02-19 17:26:17 +00:00
Sergey Chupligin 193e4f346f Allow to create raw image 2020-02-17 20:08:27 +03:00
Sergey Chupligin 2ef43447b4 Allow to install rootfs from custom dir 2020-02-17 18:24:13 +03:00
Adam Pigg fbf2477b1c
Merge pull request #2 from depsterr/master
Adding support for installing to sd cards as well as preventing unnecessary downloads.
2020-02-06 09:47:18 +00:00
depsterr ae7bb2d79a realised that ls commands will differ for platforms 2020-02-06 10:34:35 +01:00
depsterr f5a271b56f fixed accidental row concatination 2020-02-05 21:37:01 +01:00
depsterr fb322d05dd fixed wrong ls checks 2020-02-05 21:29:40 +01:00
depsterr fc9557a42d added comments and removed need to redownload 2020-02-05 21:15:10 +01:00
depsterr 841cf43d59 added support for sd card drives 2020-02-05 20:45:53 +01:00
1 changed files with 262 additions and 137 deletions

View File

@ -1,191 +1,316 @@
#!/bin/bash
#!/bin/sh
VERSION="0.2.0"
VERSION="0.3.3"
BRANCH=master
CUSTOM=""
UBOOT_JOB=u-boot
UBOOT_DIR=u-boot-bootloader
ROOTFS_PINEPHONE_JOB=pinephone-rootfs
ROOTFS_PINEPHONE_1_0_JOB=pinephone-1.0-rootfs
ROOTFS_PINEPHONE_1_1_JOB=pinephone-1.1-rootfs
ROOTFS_PINETAB_JOB=pinetab-rootfs
ROOTFS_PINETABDEV_JOB=pinetab-rootfs
ROOTFS_DEVKIT_JOB=devkit-rootfs
ROOTFS_PINEPHONE_DIR=pinephone
ROOTFS_PINEPHONE_1_0_DIR=pinephone-1.0
ROOTFS_PINEPHONE_1_1_DIR=pinephone-1.1
ROOTFS_PINETAB_DIR=pinetab
ROOTFS_PINETABDEV_DIR=pinetab
ROOTFS_DEVKIT_DIR=devkit
UBOOT_PINEPHONE_1_0_DIR=pinephone-1.0
UBOOT_PINEPHONE_1_1_DIR=pinephone-1.1
UBOOT_PINETAB_DIR=pinetab
UBOOT_PINETABDEV_DIR=pinetabdev
UBOOT_DEVKIT_DIR=devkit
MOUNT_DATA=./data
MOUNT_BOOT=./boot
# Parse arguments
# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
unset POSITIONAL
while [ "$#" -gt 0 ]; do
case "$1" in
-b|--branch)
BRANCH="$2"
shift 2
;;
-h|--help)
printf '%s\n' "Sailfish OS flashing script for Pine64 devices
This script will download the latest Sailfish OS image for the Pine
Phone, Pine Phone dev kit, or Pine Tab. It requires that you have a
micro SD card inserted into the computer.
case $key in
-b|--branch)
BRANCH="$2"
shift
shift
;;
-h|--help)
echo "Sailfish OS flashing script for Pine64 devices"
echo ""
printf '%s\n' \
"This script will download the latest Sailfish OS image for the Pine" \
"Phone, Pine Phone dev kit, or Pine Tab. It requires that you have a" \
"micro SD card inserted into the computer." \
"" \
"usage: flash-it.sh [-b BRANCH]" \
"" \
"Options:" \
"" \
" -b, --branch BRANCH Download images from a specific Git branch." \
" -h, --help Print this help and exit." \
"" \
"This command requires: parted, sudo, wget, tar, unzip, lsblk," \
"mkfs.ext4." \
""\
"Some distros do not have parted on the PATH. If necessary, add" \
"parted to the PATH before running the script."
usage: flash-it.sh [-b BRANCH]
exit 0
shift
;;
*) # unknown argument
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
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.
This command requires: parted; sudo, doas or su; wget or curl; tar, unzip, lsblk,
and mkfs.ext4.
Some distros do not have parted on the PATH. If necessary, add
parted to the PATH before running the script."
exit 0
;;
-c|--custom)
CUSTOM="$2"
shift 2
;;
*) # unknown argument
POSITIONAL="$POSITIONAL:$1" # save it in a list for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
# Retrieve saved arguments
IFS=: set -- ${POSITIONAL#:}
# Helper functions
# Run as root
as_root() {
command -V sudo >/dev/null 2>&1 && {
sudo "$@"
return "$?"
}
command -V doas >/dev/null 2>&1 && {
doas "$@"
return "$?"
}
command -V su >/dev/null 2>&1 && {
su -c "$*"
return "$?"
}
}
# Print message to stderr and exit
die() {
printf '%s\n' "$*" >&2
exit "${status:-2}"
}
# Error out if the given command is not found on the PATH.
function check_dependency {
dependency=$1
command -v $dependency >/dev/null 2>&1 || {
echo >&2 "${dependency} not found. Please make sure it is installed and on your PATH."; exit 1;
}
check_dependency() {
command -V "$1" >/dev/null 2>&1 ||
status=1 die "$1 not found. Please make sure it is installed and in your PATH."
}
# Check if one or more of depends are present
check_alternative_dependencies() {
IFS=', ' all="$*"
unset found
while [ "$1" ]; do
command -V "$1" >/dev/null 2>&1 && {
found=y
break
}
shift
done
[ "$found" ] || die "None of '$all found'. Please make sure one of them is installed and in your PATH."
}
# Determine if wget supports the --show-progress option (introduced in
# 1.16). If so, make use of that instead of spewing out redirects and
# loads of info into the terminal.
function wget_cmd {
wget --show-progress > /dev/null 2>&1
status=$?
set_wget_cmd() {
if command -V wget >/dev/null 2>&1; then
# Exit code 2 means command parsing error (i.e. option does not
# exist).
if [ "$status" == "2" ]; then
echo "wget -O"
else
echo "wget -q --show-progress -O"
fi
if wget --help 2>&1 | grep -q 'show-progress'; then
WGET="wget -q --show-progress -O"
else
WGET="wget -O"
fi
else
WGET="curl -Lo"
fi
}
# Add sbin to the PATH to make sure all commands are found
export PATH="$PATH:/sbin:/usr/sbin:/usr/local/sbin"
# Check dependencies
check_dependency "parted"
check_dependency "sudo"
check_dependency "wget"
check_dependency "tar"
check_dependency "unzip"
check_dependency "lsblk"
check_dependency "mkfs.ext4"
check_alternative_dependencies sudo doas su
check_alternative_dependencies wget curl
check_dependency tar
check_dependency unzip
check_dependency lsblk
check_dependency parted
check_dependency mkfs.ext4
check_dependency losetup
# Different branch for some reason?
if [ "${BRANCH}" != "master" ]; then
echo -e "\e[1m\e[97m!!! Will flash image from ${BRANCH} branch !!!\e[0m"
# If use custom dir check it
if [ "$CUSTOM" ]; then
if [ ! -d "$CUSTOM" ]; then
die "!!! Directory $CUSTOM not exist !!!"
fi
if [ ! -f "$CUSTOM/rootfs.tar.bz2" ]; then
die "!!! rootfs $CUSTOM/rootfs.tar.bz2 not found !!!"
fi
if [ ! -f "$CUSTOM/u-boot-sunxi-with-spl.bin" ]; then
die "!!! uboot image $CUSTOM/u-boot-sunxi-with-spl.bin not found !!!"
fi
if ! [ -f "$CUSTOM/boot.scr" ]; then
die "!!! uboot config $CUSTOM/boot.scr not found !!!"
fi
else
# Different branch for some reason?
if [ "$BRANCH" != master ]; then
printf '%s\n' "!!! Will flash image from $BRANCH branch !!!"
fi
# Header
printf '%s\n' "Sailfish OS Pine64 device flasher V$VERSION
======================================
"
# Image selection
printf '%s\n' "Which image do you want to flash?"
: $(( i = 0 ))
for opt in "PinePhone 1.0 (Development) device" "PinePhone 1.1 (Brave Heart) or 1.2 (Community Editions) device" "PineTab device" "PineTab Dev device" "Dont Be Evil devkit"; do
: $(( i += 1 ))
printf '%s\n' "$i) $opt"
done
printf '%s' "#? "
read -r OPTION
case "$OPTION" in
1) ROOTFS_JOB=$ROOTFS_PINEPHONE_1_0_JOB; ROOTFS_DIR=$ROOTFS_PINEPHONE_1_0_DIR; UBOOT_DEV_DIR=$UBOOT_PINEPHONE_1_0_DIR;;
2) ROOTFS_JOB=$ROOTFS_PINEPHONE_1_1_JOB; ROOTFS_DIR=$ROOTFS_PINEPHONE_1_1_DIR; UBOOT_DEV_DIR=$UBOOT_PINEPHONE_1_1_DIR;;
3) ROOTFS_JOB=$ROOTFS_PINETAB_JOB; ROOTFS_DIR=$ROOTFS_PINETAB_DIR; UBOOT_DEV_DIR=$UBOOT_PINETAB_DIR;;
4) ROOTFS_JOB=$ROOTFS_PINETABDEV_JOB; ROOTFS_DIR=$ROOTFS_PINETABDEV_DIR; UBOOT_DEV_DIR=$UBOOT_PINETABDEV_DIR;;
5) ROOTFS_JOB=$ROOTFS_DEVKIT_JOB; ROOTFS_DIR=$ROOTFS_DEVKIT_DIR; UBOOT_DEV_DIR=$UBOOT_DEVKIT_DIR;;
*) die "Invalid selection";;
esac
# Downloading images
printf '%s\n' "Downloading images..."
set_wget_cmd
UBOOT_DOWNLOAD="https://gitlab.com/sailfishos-porters-ci/dont_be_evil-ci/-/jobs/artifacts/$BRANCH/download?job=$UBOOT_JOB"
$WGET "$UBOOT_JOB.zip" "$UBOOT_DOWNLOAD" || {
die "UBoot image download failed. Aborting."
}
UBOOT2_JOB=u-boot-sunxi-with-spl-pinephone.bin
UBOOT_DOWNLOAD2="https://gitlab.com/pine64-org/crust-meta/-/jobs/artifacts/master/raw/u-boot-sunxi-with-spl-pinephone.bin?job=build"
$WGET "$UBOOT2_JOB" "$UBOOT_DOWNLOAD2" || {
die "UBoot image download failed. Aborting."
}
ROOTFS_DOWNLOAD="https://gitlab.com/sailfishos-porters-ci/dont_be_evil-ci/-/jobs/artifacts/$BRANCH/download?job=$ROOTFS_JOB"
$WGET "$ROOTFS_JOB.zip" "$ROOTFS_DOWNLOAD" || {
die "Root filesystem image download failed. Aborting."
}
fi
# Header
echo -e "\e[1m\e[91mSailfish OS Pine64 device flasher V$VERSION\e[0m"
echo "======================================"
echo ""
# Image selection
echo -e "\e[1mWhich image do you want to flash?\e[0m"
select OPTION in "PinePhone device" "PineTab device" "Dont Be Evil devkit"; do
case $OPTION in
"PinePhone device" ) ROOTFS_JOB=$ROOTFS_PINEPHONE_JOB; ROOTFS_DIR=$ROOTFS_PINEPHONE_DIR; break;;
"PineTab device" ) ROOTFS_JOB=$ROOTFS_PINETAB_JOB; ROOTFS_DIR=$ROOTFS_PINETAB_DIR; break;;
"Dont Be Evil devkit" ) ROOTFS_JOB=$ROOTFS_DEVKIT_JOB; ROOTFS_DIR=$ROOTFS_DEVKIT_DIR; break;;
esac
done
# Downloading images
echo -e "\e[1mDownloading images...\e[0m"
WGET=$(wget_cmd)
UBOOT_DOWNLOAD="https://gitlab.com/sailfishos-porters-ci/dont_be_evil-ci/-/jobs/artifacts/$BRANCH/download?job=$UBOOT_JOB"
$WGET "${UBOOT_JOB}.zip" "${UBOOT_DOWNLOAD}" || {
echo >&2 "UBoot image download failed. Aborting."
exit 2
}
ROOTFS_DOWNLOAD="https://gitlab.com/sailfishos-porters-ci/dont_be_evil-ci/-/jobs/artifacts/$BRANCH/download?job=$ROOTFS_JOB"
$WGET "${ROOTFS_JOB}.zip" "${ROOTFS_DOWNLOAD}" || {
echo >&2 "Root filesystem image download failed. Aborting."
exit 2
}
# Select flash target
echo -e "\e[1mWhich SD card do you want to flash?\e[0m"
printf '%s\n' "Which SD card do you want to flash?"
lsblk
read -p "Device node (/dev/sdX): " DEVICE_NODE
echo "Flashing image to: $DEVICE_NODE"
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."
printf '%s\n%s\n' "raw" "Device node (/dev/sdX): "
read -r DEVICE_NODE
printf '%s\n' "Flashing image to: $DEVICE_NODE
WARNING: All data will be erased! You have been warned!
Some commands require root permissions, you might be asked to enter your password."
#create loop file for raw.img
if [ "$DEVICE_NODE" = raw ]; then
as_root dd if=/dev/zero of=sdcard.img bs=1 count=0 seek=4G
DEVICE_NODE=./sdcard.img
fi
# Creating EXT4 file system
echo -e "\e[1mCreating EXT4 file system...\e[0m"
for PARTITION in $(ls ${DEVICE_NODE}*)
do
printf '%s\n' "Creating EXT4 file system..."
for PARTITION in "$DEVICE_NODE"*; do
echo "Unmounting $PARTITION"
sudo umount $PARTITION
as_root umount "$PARTITION"
done
sudo parted $DEVICE_NODE mklabel msdos --script
sudo parted $DEVICE_NODE mkpart primary ext4 1MB 250MB --script
sudo parted $DEVICE_NODE mkpart primary ext4 250MB 100% --script
sudo mkfs.ext4 -F -L boot "${DEVICE_NODE}1" # 1st partition = boot
sudo mkfs.ext4 -F -L data "${DEVICE_NODE}2" # 2nd partition = data
as_root parted "$DEVICE_NODE" mklabel msdos --script
as_root parted "$DEVICE_NODE" mkpart primary ext4 1MB 250MB --script
as_root parted "$DEVICE_NODE" mkpart primary ext4 250MB 100% --script
if [ "$DEVICE_NODE" = ./sdcard.img ]; then
printf '%s\n' "Prepare loop file"
as_root losetup -D
as_root losetup -Pf sdcard.img
LOOP_NODE="$(echo /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 -q -E 'mmcblk|loop'; then
BOOTPART="${DEVICE_NODE}p1"
DATAPART="${DEVICE_NODE}p2"
else
BOOTPART="${DEVICE_NODE}1"
DATAPART="${DEVICE_NODE}2"
fi
as_root mkfs.ext4 -F -L boot "$BOOTPART" # 1st partition = boot
as_root mkfs.ext4 -F -L data "$DATAPART" # 2nd partition = data
# Flashing u-boot
echo -e "\e[1mFlashing U-boot...\e[0m"
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
printf '%s\n' "Flashing U-boot..."
if [ "$CUSTOM" ]; then
as_root dd if="$CUSTOM/u-boot-sunxi-with-spl.bin" of="$DEVICE_NODE" bs=8k seek=1
else
unzip "$UBOOT_JOB.zip"
as_root dd if="./u-boot-sunxi-with-spl-pinephone.bin" of="$DEVICE_NODE" bs=8k seek=1
fi
sync
# Flashing rootFS
echo -e "\e[1mFlashing rootFS...\e[0m"
unzip "${ROOTFS_JOB}.zip"
TEMP=`ls $ROOTFS_DIR/*/*.tar.bz2`
echo "$TEMP"
printf '%s\n' "Flashing rootFS..."
mkdir "$MOUNT_DATA"
sudo mount "${DEVICE_NODE}2" "$MOUNT_DATA" # Mount data partition
sudo tar -xpf "$TEMP" -C "$MOUNT_DATA"
if [ "$CUSTOM" ]; then
TEMP="$CUSTOM/rootfs.tar.bz2"
else
unzip "$ROOTFS_JOB.zip"
TEMP="$(echo $ROOTFS_DIR/*/*.tar.bz2)"
echo "$TEMP"
fi
as_root mount "$DATAPART" "$MOUNT_DATA" # Mount data partition
as_root tar -xpf "$TEMP" -C "$MOUNT_DATA"
sync
# Copying kernel to boot partition
echo -e "\e[1mCopying kernel to boot partition...\e[0m"
printf '%s\n' "Copying kernel to boot partition..."
mkdir "$MOUNT_BOOT"
sudo mount "${DEVICE_NODE}1" "$MOUNT_BOOT" # Mount boot partition
sudo cp $MOUNT_DATA/boot/* $MOUNT_BOOT
sudo cp "./u-boot-bootloader/$ROOTFS_DIR/boot.scr" "$MOUNT_BOOT/boot.scr"
as_root mount "$BOOTPART" "$MOUNT_BOOT" # Mount boot partition
printf '%s\n' "Boot partition mount: $MOUNT_BOOT"
as_root chmod a+rx "$MOUNT_DATA/boot"
as_root cp -r "$MOUNT_DATA/boot"/* "$MOUNT_BOOT"
echo "$MOUNT_BOOT"
if [ "$CUSTOM" ]; then
as_root cp "$CUSTOM/boot.scr" "$MOUNT_BOOT/boot.scr"
else
as_root cp "./u-boot-bootloader/$UBOOT_DEV_DIR/boot.scr" "$MOUNT_BOOT/boot.scr"
fi
sync
# Clean up files
echo -e "\e[1mCleaning up!\e[0m"
for PARTITION in $(ls ${DEVICE_NODE}*)
do
printf '%s\n' "Cleaning up!"
for PARTITION in "$DEVICE_NODE"*; do
echo "Unmounting $PARTITION"
sudo umount $PARTITION
as_root umount "$PARTITION"
done
rm "${UBOOT_JOB}.zip"
rm -r "$UBOOT_DIR"
rm "${ROOTFS_JOB}.zip"
rm -r "$ROOTFS_DIR"
rm -rf "$MOUNT_DATA"
rm -rf "$MOUNT_BOOT"
as_root losetup -D
if [ -z "$CUSTOM" ]; then
rm -r "$UBOOT_JOB.zip" "$UBOOT2_JOB" "$UBOOT_DIR" "$ROOTFS_JOB.zip" "$ROOTFS_DIR"
fi
as_root rm -rf "$MOUNT_DATA" "$MOUNT_BOOT"
# Done :)
echo -e "\e[1mFlashing $DEVICE_NODE OK!\e[0m"
echo "You may now remove the SD card and insert it in your Pine64 device!"
printf '%s\n' "Flashing $DEVICE_NODE OK!
You may now remove the SD card and insert it in your Pine64 device!"