eMMC installer for H3 based boards
This commit is contained in:
parent
22c82b99f7
commit
12a7223afe
Binary file not shown.
Binary file not shown.
@ -4,7 +4,7 @@
|
||||
#
|
||||
# www.igorpecovnik.com / images + support
|
||||
#
|
||||
# NAND, SATA and USB Armbian installer
|
||||
# NAND, eMMC, SATA and USB Armbian installer
|
||||
# nand boot za a10: git clone -b dev/a10-nand-ext4 https://github.com/mmplayer/u-boot-sunxi --depth 1
|
||||
# Should work with: Cubietruck, Cubieboards, BananaPi, Olimex Lime+Lime2+Micro, Hummingboard, ...
|
||||
#
|
||||
@ -15,276 +15,306 @@ CWD="/usr/lib/nand-sata-install"
|
||||
EX_LIST="${CWD}/exclude.txt"
|
||||
backtitle="Armbian install script, http://www.armbian.com | Author: Igor Pecovnik"
|
||||
title="NAND, SATA and USB Armbian installer"
|
||||
emmcdevice="/dev/mmcblk1"
|
||||
nanddevice="/dev/nand"
|
||||
if cat /proc/cpuinfo | grep -q 'sun4i'; then DEVICE_TYPE="a10"; else DEVICE_TYPE="a20"; fi # Determine device
|
||||
BOOTLOADER="${CWD}/${DEVICE_TYPE}/bootloader" # Define bootloader
|
||||
nandcheck=$(grep nand /proc/partitions) # check NAND
|
||||
emmcchech=$(grep mmcblk1 /proc/partitions) # check eMMC
|
||||
satacheck=$(grep sd /proc/partitions) # check SATA/USB
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
# Main function for creating boot and root file system
|
||||
#
|
||||
# Accept two device parameters: $1 = boot, $2 = root (Example: create_armbian "/dev/nand1" "/dev/sda3")
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
# Create boot and root file system $1 = boot, $2 = root (Example: create_armbian "/dev/nand1" "/dev/sda3")
|
||||
create_armbian ()
|
||||
{
|
||||
# create mount points, mount and clean
|
||||
sync
|
||||
mkdir -p /mnt/bootfs /mnt/rootfs
|
||||
[ -n "$2" ] && mount $2 /mnt/rootfs
|
||||
[[ -n "$1" && "$1" != "$2" ]] && mount $1 /mnt/bootfs
|
||||
rm -rf /mnt/bootfs/* /mnt/rootfs/*
|
||||
|
||||
|
||||
# calculate usage and see if it fits on destination
|
||||
USAGE=$(df -BM | grep ^/dev | head -1 | awk '{print $3}' | tr -cd '[0-9]. \n')
|
||||
DEST=$(df -BM | grep ^/dev | grep /mnt/rootfs | awk '{print $4}' | tr -cd '[0-9]. \n')
|
||||
if [ $USAGE -gt $DEST ]; then
|
||||
dialog --title "$title" --backtitle "$backtitle" --colors --infobox\
|
||||
"\n\Z1Partition too small.\Zn Needed: $USAGE Mb Avaliable: $DEST Mb" 5 60
|
||||
umountdevice "$1"; umountdevice "$2"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$1" == *nand* ]]; then
|
||||
# creating nand boot. Copy precompiled uboot
|
||||
rsync -aqc $BOOTLOADER/* /mnt/bootfs
|
||||
fi
|
||||
|
||||
# count files is needed for progress bar
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\n Counting files ... few seconds." 5 40
|
||||
TODO=$(rsync -ahvrltDn --delete --stats --exclude-from=$EX_LIST / /mnt/rootfs |grep "Number of files:"|awk '{print $4}' | tr -d '.,')
|
||||
|
||||
# unmount devices
|
||||
umountdevice "$1"; umountdevice "$2"
|
||||
# creating rootfs
|
||||
rsync -avrltD --delete --exclude-from=$EX_LIST / /mnt/rootfs | nl | awk '{ printf "%.0f\n", 100*$1/"'"$TODO"'" }' \
|
||||
| dialog --backtitle "$backtitle" --title "$title" --gauge "\n\n Creating rootfs on $2 ($USAGE Mb). Please wait!" 10 80
|
||||
|
||||
# create mount points, mount and clean
|
||||
mkdir -p /mnt/bootfs /mnt/rootfs
|
||||
[ -n "$1" ] && mount $1 /mnt/bootfs
|
||||
[ -n "$2" ] && mount $2 /mnt/rootfs
|
||||
rm -rf /mnt/bootfs/* /mnt/rootfs/*
|
||||
# creating fstab - root partition
|
||||
sed -e 's,'"$root_partition"','"$2"',g' -i /mnt/rootfs/etc/fstab
|
||||
|
||||
# calculate usage and see if it fits on destination
|
||||
USAGE=$(df -BM | grep ^/dev | head -1 | awk '{print $3}' | tr -cd '[0-9]. \n')
|
||||
DEST=$(df -BM | grep ^/dev | grep /mnt/rootfs | awk '{print $4}' | tr -cd '[0-9]. \n')
|
||||
if [ $USAGE -gt $DEST ]; then
|
||||
dialog --title "$title" --backtitle "$backtitle" --colors --infobox\
|
||||
"\n\Z1Partition too small.\Zn Needed: $USAGE Mb Avaliable: $DEST Mb" 5 60
|
||||
umountdevice "$1"; umountdevice "$2"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# creating nand boot. Copy precompiled uboot
|
||||
rsync -aqc $BOOTLOADER/* /mnt/bootfs
|
||||
|
||||
# count files is needed for progress bar
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\nCounting files ... few seconds." 5 60
|
||||
TODO=$(rsync -ahvrltDn --delete --stats --exclude-from=$EX_LIST / /mnt/rootfs |grep "Number of files:"|awk '{print $4}' | tr -d '.,')
|
||||
|
||||
# creating rootfs
|
||||
rsync -avrltD --delete --exclude-from=$EX_LIST / /mnt/rootfs | nl | awk '{ printf "%.0f\n", 100*$1/"'"$TODO"'" }' \
|
||||
| dialog --backtitle "$backtitle" --title "$title" --gauge "\n Creating rootfs on $2 ($USAGE Mb). Please wait!" 8 60
|
||||
|
||||
# creating fstab - root partition
|
||||
sed -e 's,'"$root_partition"','"$2"',g' -i /mnt/rootfs/etc/fstab
|
||||
|
||||
# creating fstab, kernel and boot script for NAND partition
|
||||
if [ -n "$1" ]; then
|
||||
REMOVESDTXT="and remove SD to boot from NAND"
|
||||
sed -i '/boot/d' /mnt/rootfs/etc/fstab
|
||||
echo "$1 /boot vfat defaults 0 0" >> /mnt/rootfs/etc/fstab
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\nConverting kernel ... few seconds." 5 60
|
||||
mkimage -A arm -O linux -T kernel -C none -a "0x40008000" -e "0x40008000" -n "Linux kernel" -d \
|
||||
/boot/zImage /mnt/bootfs/uImage >/dev/null 2>&1
|
||||
cp /boot/script.bin /mnt/bootfs/
|
||||
cat > /mnt/bootfs/uEnv.txt <<EOF
|
||||
# creating fstab, kernel and boot script for NAND partition
|
||||
if [[ "$1" == *nand* ]]; then
|
||||
|
||||
REMOVESDTXT="and remove SD to boot from NAND"
|
||||
sed -i '/boot/d' /mnt/rootfs/etc/fstab
|
||||
echo "$1 /boot vfat defaults 0 0" >> /mnt/rootfs/etc/fstab
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\nConverting kernel ... few seconds." 5 60
|
||||
mkimage -A arm -O linux -T kernel -C none -a "0x40008000" -e "0x40008000" -n "Linux kernel" -d \
|
||||
/boot/zImage /mnt/bootfs/uImage >/dev/null 2>&1
|
||||
cp /boot/script.bin /mnt/bootfs/
|
||||
cat > /mnt/bootfs/uEnv.txt <<EOF
|
||||
console=ttyS0,115200
|
||||
root=$2 rootwait
|
||||
extraargs="console=tty1 hdmi.audio=EDID:0 disp.screen0_output_mode=EDID:0 consoleblank=0 loglevel=1"
|
||||
EOF
|
||||
sync
|
||||
[[ $DEVICE_TYPE = "a20" ]] && echo "machid=10bb" >> /mnt/bootfs/uEnv.txt
|
||||
# ugly hack becouse we don't have sources for A10 nand uboot
|
||||
if [[ $(cat /var/run/machine.id) == "Cubieboard" ]]; then
|
||||
cp /mnt/bootfs/uEnv.txt /mnt/rootfs/boot/uEnv.txt
|
||||
cp /mnt/bootfs/script.bin /mnt/rootfs/boot/script.bin
|
||||
cp /mnt/bootfs/uImage /mnt/rootfs/boot/uImage
|
||||
fi
|
||||
umountdevice "/dev/nand"
|
||||
tune2fs -o journal_data_writeback /dev/nand2 >/dev/null 2>&1
|
||||
tune2fs -O ^has_journal /dev/nand2 >/dev/null 2>&1
|
||||
e2fsck -f /dev/nand2 >/dev/null 2>&1
|
||||
elif [[ -f /boot/boot.cmd ]]; then
|
||||
sed -e 's,root='"$root_partition"',root='"$2"',g' -i /boot/boot.cmd
|
||||
mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
|
||||
mkdir -p /mnt/rootfs/media/mmc/boot
|
||||
if ! grep -q "/boot" /mnt/rootfs/etc/fstab; then # in two partition setup
|
||||
echo "/dev/mmcblk0p1 /media/mmc ext4 defaults 0 0" >> /mnt/rootfs/etc/fstab
|
||||
echo "/media/mmc/boot /boot none bind 0 0" >> /mnt/rootfs/etc/fstab
|
||||
fi
|
||||
sed -i "s/data=writeback,//" /mnt/rootfs/etc/fstab
|
||||
elif [[ -f /boot/boot.ini ]]; then
|
||||
sed -e 's,root='"$root_partition"',root='"$2"',g' -i /boot/boot.ini
|
||||
sed -i "s/data=writeback,//" /mnt/rootfs/etc/fstab
|
||||
sync
|
||||
|
||||
[[ $DEVICE_TYPE = "a20" ]] && echo "machid=10bb" >> /mnt/bootfs/uEnv.txt
|
||||
# ugly hack becouse we don't have sources for A10 nand uboot
|
||||
if [[ $(cat /var/run/machine.id) == "Cubieboard" ]]; then
|
||||
cp /mnt/bootfs/uEnv.txt /mnt/rootfs/boot/uEnv.txt
|
||||
cp /mnt/bootfs/script.bin /mnt/rootfs/boot/script.bin
|
||||
cp /mnt/bootfs/uImage /mnt/rootfs/boot/uImage
|
||||
fi
|
||||
umountdevice "/dev/nand"
|
||||
tune2fs -o journal_data_writeback /dev/nand2 >/dev/null 2>&1
|
||||
tune2fs -O ^has_journal /dev/nand2 >/dev/null 2>&1
|
||||
e2fsck -f /dev/nand2 >/dev/null 2>&1
|
||||
|
||||
elif [[ "$2" == "/dev/mmcblk1p1" ]]; then
|
||||
|
||||
# eMMC install
|
||||
# fix that we can have one exlude file
|
||||
cp -R /boot/ /boot/mnt/rootfs
|
||||
# determine u-boot and write it
|
||||
name_of_ubootpackage=$(aptitude versions '~i linux-u-boot*'|head -1| awk '{print $2}' | sed 's/linux-u-boot-//g' | cut -f1 -d"-")
|
||||
version_of_ubootpkg=$(aptitude versions '~i linux-u-boot*'| tail -1 | awk '{print $2}')
|
||||
arhitecture=$(dpkg --print-architecture)
|
||||
uboot="/usr/lib/linux-u-boot-"$name_of_ubootpackage"_"$version_of_ubootpkg"_"$arhitecture""/u-boot-sunxi-with-spl.bin
|
||||
dd if=$uboot of=$emmcdevice bs=1024 seek=8
|
||||
|
||||
elif [[ -f /boot/boot.cmd ]]; then
|
||||
sed -e 's,root='"$root_partition"',root='"$2"',g' -i /boot/boot.cmd
|
||||
mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
|
||||
mkdir -p /mnt/rootfs/media/mmc/boot
|
||||
if ! grep -q "/boot" /mnt/rootfs/etc/fstab; then # in two partition setup
|
||||
echo "/dev/mmcblk0p1 /media/mmc ext4 defaults 0 0" >> /mnt/rootfs/etc/fstab
|
||||
echo "/media/mmc/boot /boot none bind 0 0" >> /mnt/rootfs/etc/fstab
|
||||
fi
|
||||
sed -i "s/data=writeback,//" /mnt/rootfs/etc/fstab
|
||||
elif [[ -f /boot/boot.ini ]]; then
|
||||
sed -e 's,root='"$root_partition"',root='"$2"',g' -i /boot/boot.ini
|
||||
sed -i "s/data=writeback,//" /mnt/rootfs/etc/fstab
|
||||
fi
|
||||
umountdevice "/dev/sda"
|
||||
}
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
# Let's unmount all targets
|
||||
#
|
||||
# Accept device as parameter: for example /dev/sda unmounts all their mounts
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
umountdevice() {
|
||||
sync
|
||||
if [ -n "$1" ]; then
|
||||
device=$1; device="${device//[0-9]*/}"
|
||||
for n in ${device}*; do
|
||||
if [ "${device}" != "$n" ]; then
|
||||
if mount|grep -q ${n}; then
|
||||
umount -l $n >/dev/null 2>&1
|
||||
if [ -n "$1" ]; then
|
||||
device=$1;
|
||||
for n in ${device}*; do
|
||||
if [ "${device}" != "$n" ]; then
|
||||
if mount|grep -q ${n}; then
|
||||
umount -l $n >/dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# Recognize root filesystem
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
recognize_root (){
|
||||
local device="/dev/"$(lsblk -idn -o NAME | grep mmcblk0)
|
||||
local partitions=$(($(fdisk -l $device | grep $device | wc -l)-1))
|
||||
local device="/dev/"$(lsblk -idn -o NAME | grep mmcblk0)"p"$partitions
|
||||
local root_device=$(mountpoint -d /)
|
||||
for file in /dev/* ; do
|
||||
local current_device=$(printf "%d:%d" $(stat --printf="0x%t 0x%T" $file))
|
||||
if [ $current_device = $root_device ]; then
|
||||
root_partition=$file
|
||||
break;
|
||||
fi
|
||||
done
|
||||
|
||||
local device="/dev/"$(lsblk -idn -o NAME | grep mmcblk0)
|
||||
local partitions=$(($(fdisk -l $device | grep $device | wc -l)-1))
|
||||
local device="/dev/"$(lsblk -idn -o NAME | grep mmcblk0)"p"$partitions
|
||||
local root_device=$(mountpoint -d /)
|
||||
for file in /dev/* ; do
|
||||
local current_device=$(printf "%d:%d" $(stat --printf="0x%t 0x%T" $file))
|
||||
if [ $current_device = $root_device ]; then
|
||||
root_partition=$file
|
||||
break;
|
||||
fi
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
# Formatting NAND
|
||||
#
|
||||
# No parameters. Fixed solution.
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
# Formatting NAND - no parameters. Fixed solution.
|
||||
formatnand(){
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\nFormating ... up to one minute." 5 60
|
||||
if [[ "$DEVICE_TYPE" = "a20" ]]; then
|
||||
(echo y;) | sunxi-nand-part -f a20 /dev/nand 65536 'bootloader 65536' 'linux 0' >/dev/null 2>&1
|
||||
else
|
||||
(echo y;) | sunxi-nand-part -f a10 /dev/nand 65536 'bootloader 65536' 'linux 0' >/dev/null 2>&1
|
||||
fi
|
||||
mkfs.vfat /dev/nand1 >/dev/null 2>&1
|
||||
mkfs.ext4 /dev/nand2 >/dev/null 2>&1
|
||||
|
||||
[[ ! -e /dev/nand ]] && echo "NAND error" && exit 0
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\nFormating ... up to one minute." 5 40
|
||||
if [[ "$DEVICE_TYPE" = "a20" ]]; then
|
||||
(echo y;) | sunxi-nand-part -f a20 /dev/nand 65536 'bootloader 65536' 'linux 0' >/dev/null 2>&1
|
||||
else
|
||||
(echo y;) | sunxi-nand-part -f a10 /dev/nand 65536 'bootloader 65536' 'linux 0' >/dev/null 2>&1
|
||||
fi
|
||||
mkfs.vfat /dev/nand1 >/dev/null 2>&1
|
||||
mkfs.ext4 /dev/nand2 >/dev/null 2>&1
|
||||
|
||||
}
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
# Formatting SATA/USB
|
||||
#
|
||||
# Accept device as parameter: for example /dev/sda3
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
# Formatting eMMC [device] example /dev/mmcblk1
|
||||
formatemmc()
|
||||
{
|
||||
|
||||
# deletes all partitions
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\n Formating eMMC ... one moment." 5 40
|
||||
dd bs=1 seek=446 count=64 if=/dev/zero of=$1 >/dev/null 2>&1
|
||||
parted -s $1 -- mklabel msdos
|
||||
parted -s $1 -- mkpart primary ext4 2048s -1s
|
||||
partprobe $1
|
||||
# create fs
|
||||
mkfs.ext4 -q $1"p1"
|
||||
|
||||
}
|
||||
|
||||
|
||||
# formatting SATA/USB [device] example /dev/sda3
|
||||
formatsata(){
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\Formating ... up to one minute." 5 60
|
||||
mkfs.ext4 $1 >/dev/null 2>&1
|
||||
tune2fs $1 -o journal_data_writeback >/dev/null 2>&1
|
||||
|
||||
dialog --title "$title" --backtitle "$backtitle" --infobox "\nFormating ... up to one minute." 5 40
|
||||
mkfs.ext4 $1 >/dev/null 2>&1
|
||||
tune2fs $1 -o journal_data_writeback >/dev/null 2>&1
|
||||
|
||||
}
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
# Choose target SATA/USB partition.
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
# choose target SATA/USB partition.
|
||||
function checksatatarget
|
||||
{
|
||||
IFS=" "
|
||||
SataTargets=$(cat /proc/partitions | grep sd | awk '{print "/dev/"$4}' | grep -E '[0-9]{1,4}' | nl | xargs echo -n)
|
||||
if [[ "$SataTargets" == "" ]]; then
|
||||
dialog --title "$title" --backtitle "$backtitle" --colors --infobox\
|
||||
"\n\Z1There are no avaliable partitions. Please create them.\Zn" 5 60
|
||||
|
||||
IFS=" "
|
||||
SataTargets=$(cat /proc/partitions | grep sd | awk '{print "/dev/"$4}' | grep -E '[0-9]{1,4}' | nl | xargs echo -n)
|
||||
if [[ "$SataTargets" == "" ]]; then
|
||||
dialog --title "$title" --backtitle "$backtitle" --colors --infobox\
|
||||
"\n\Z1There are no avaliable partitions. Please create them.\Zn" 5 60
|
||||
exit 1
|
||||
fi
|
||||
SataOptions=($SataTargets)
|
||||
SataCmd=(dialog --title "Select destination:" --backtitle "$backtitle" --menu "\n$infos" 10 60 16)
|
||||
SataChoices=$("${SataCmd[@]}" "${SataOptions[@]}" 2>&1 >/dev/tty)
|
||||
if [ $? -ne 0 ]; then exit 1; fi
|
||||
SDA_ROOT_PART=${SataOptions[(2*$SataChoices)-1]}
|
||||
fi
|
||||
|
||||
SataOptions=($SataTargets)
|
||||
SataCmd=(dialog --title "Select destination:" --backtitle "$backtitle" --menu "\n$infos" 10 60 16)
|
||||
SataChoices=$("${SataCmd[@]}" "${SataOptions[@]}" 2>&1 >/dev/tty)
|
||||
if [ $? -ne 0 ]; then exit 1; fi
|
||||
SDA_ROOT_PART=${SataOptions[(2*$SataChoices)-1]}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
# Show warning, TEXT is a parameter
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
# show warning [TEXT]
|
||||
function ShowWarning
|
||||
{
|
||||
# show big warning
|
||||
dialog --title "$title" --backtitle "$backtitle" --cr-wrap --colors --yesno " \Z1$(toilet -f mono12 WARNING)\Zn\n$1" 17 74
|
||||
if [ $? -ne 0 ]; then exit 1; fi
|
||||
|
||||
dialog --title "$title" --backtitle "$backtitle" --cr-wrap --colors --yesno " \Z1$(toilet -f mono12 WARNING)\Zn\n$1" 17 74
|
||||
if [ $? -ne 0 ]; then exit 1; fi
|
||||
|
||||
}
|
||||
|
||||
|
||||
########################################################################################################################
|
||||
#
|
||||
# Prepare main selection
|
||||
#
|
||||
########################################################################################################################
|
||||
# This tool must run under root
|
||||
|
||||
if [[ ${EUID} -ne 0 ]]; then
|
||||
echo "This tool must run as root. Exiting ..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
# This tool must run under root
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
if [[ ${EUID} -ne 0 ]]; then
|
||||
echo "This tool must run as root. Exiting ..."
|
||||
exit 1
|
||||
fi
|
||||
# Downloading dependencies
|
||||
|
||||
if [ $(dpkg-query -W -f='${Status}' dialog 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
|
||||
echo "Downloading dependencies ... please wait"
|
||||
apt-get install -qq -y dialog >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
# Downloading dependencies
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
if [ $(dpkg-query -W -f='${Status}' dialog 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
|
||||
echo "Downloading dependencies ... please wait"
|
||||
apt-get install -qq -y dialog >/dev/null 2>&1
|
||||
fi
|
||||
# Check if we run it from SD card
|
||||
|
||||
if [[ "$(sed -n 's/^DEVNAME=//p' /sys/dev/block/$(mountpoint -d /)/uevent)" != mmcblk* ]]; then
|
||||
dialog --title "$title" --backtitle "$backtitle" --colors --infobox "\n\Z1This tool must run from SD-card!\Zn" 5 42
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
# Check if we run it from SD card
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
if [[ "$(sed -n 's/^DEVNAME=//p' /sys/dev/block/$(mountpoint -d /)/uevent)" != mmcblk* ]]; then
|
||||
dialog --title "$title" --backtitle "$backtitle" --colors --infobox "\n\Z1This tool must run from SD-card!\Zn" 5 42
|
||||
exit 1
|
||||
fi
|
||||
recognize_root
|
||||
IFS="'"
|
||||
options=()
|
||||
if [[ -n "$emmcchech" ]]; then
|
||||
ichip="eMMC";
|
||||
dest_boot="/dev/mmcblk1p1";
|
||||
dest_root="/dev/mmcblk1p1";
|
||||
else
|
||||
ichip="NAND";
|
||||
dest_boot="/dev/nand1";
|
||||
dest_root="/dev/nand2";
|
||||
fi
|
||||
|
||||
[[ -n "$nandcheck" || -n "$emmcchech" ]] && options=(${options[@]} 1 'Boot from '$ichip' - system on '$ichip)
|
||||
[[ ( -n "$nandcheck" || -n "$emmcchech" ) && -n "$satacheck" ]] && options=(${options[@]} 2 'Boot from '$ichip' - system on SATA or USB')
|
||||
[[ -n "$satacheck" ]] && options=(${options[@]} 3 'Boot from SD - system on SATA or USB')
|
||||
|
||||
[[ ${#options[@]} -eq 0 ]] && dialog --title "$title" --backtitle "$backtitle" --colors --infobox "\n\Z1There are no targets. Please check your drives.\Zn" 5 60 && exit 1
|
||||
|
||||
cmd=(dialog --title "Choose an option:" --backtitle "$backtitle" --menu "\nCurrent root: $root_partition \n \n" 14 60 7)
|
||||
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
|
||||
if [ $? -ne 0 ]; then exit 1; fi
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
# Main selection
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
for choice in $choices
|
||||
do
|
||||
case $choice in
|
||||
1)
|
||||
title="$ichip install"
|
||||
command="Power off"
|
||||
ShowWarning "This script will erase your $ichip. Continue?"
|
||||
if [[ -n "$emmcchech" ]]; then
|
||||
umountdevice "/dev/mmcblk1"
|
||||
formatemmc "/dev/mmcblk1"
|
||||
else
|
||||
umountdevice "/dev/nand"
|
||||
formatnand
|
||||
fi
|
||||
create_armbian "$dest_boot" "$dest_root"
|
||||
;;
|
||||
2)
|
||||
title="$ichip boot / SATA root install"
|
||||
command="Power off"
|
||||
checksatatarget
|
||||
ShowWarning "This script will erase your $ichip and $SDA_ROOT_PART. Continue?"
|
||||
if [[ -n "$emmcchech" ]]; then
|
||||
umountdevice "/dev/mmcblk1"
|
||||
formatemmc "/dev/mmcblk1"
|
||||
else
|
||||
umountdevice "/dev/nand"
|
||||
formatnand
|
||||
fi
|
||||
umountdevice "${SDA_ROOT_PART//[0-9]*/}"
|
||||
formatsata "$SDA_ROOT_PART"
|
||||
create_armbian "$dest_boot" "$SDA_ROOT_PART"
|
||||
;;
|
||||
3)
|
||||
title="SD boot / SATA root install"
|
||||
command="Reboot"
|
||||
checksatatarget
|
||||
ShowWarning "This script will erase your device $SDA_ROOT_PART. Continue?"
|
||||
formatsata "$SDA_ROOT_PART"
|
||||
create_armbian "" "$SDA_ROOT_PART"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if cat /proc/cpuinfo | grep -q 'sun4i'; then DEVICE_TYPE="a10"; else DEVICE_TYPE="a20"; fi # Determine device
|
||||
BOOTLOADER="${CWD}/${DEVICE_TYPE}/bootloader" # Define bootloader
|
||||
nandcheck=$(grep nand /proc/partitions) # check NAND
|
||||
satacheck=$(grep sd /proc/partitions) # check SATA/USB
|
||||
recognize_root # find out root partitions
|
||||
IFS="'"
|
||||
options=()
|
||||
[[ -n "$nandcheck" ]] && options=(${options[@]} 1 'Boot from NAND - system on NAND')
|
||||
[[ -n "$nandcheck" && -n "$satacheck" ]] && options=(${options[@]} 2 'Boot from NAND - system on SATA or USB')
|
||||
[[ -n "$satacheck" ]] && options=(${options[@]} 3 'Boot from SD - system on SATA or USB')
|
||||
[[ ${#options[@]} -eq 0 ]] && dialog --title "$title" --backtitle "$backtitle" --colors --infobox\
|
||||
"\n\Z1There are no targets. Please check your drives.\Zn" 5 60 && exit 1
|
||||
|
||||
cmd=(dialog --title "Choose an option:" --backtitle "$backtitle" --menu "\nCurrent root: $root_partition \n \n" 14 60 7)
|
||||
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
|
||||
if [ $? -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for choice in $choices
|
||||
do
|
||||
case $choice in
|
||||
1)
|
||||
title="NAND install"
|
||||
command="Power off"
|
||||
ShowWarning "This script will erase your device /dev/nand. Continue?"
|
||||
formatnand
|
||||
create_armbian "/dev/nand1" "/dev/nand2"
|
||||
;;
|
||||
2)
|
||||
title="NAND boot / SATA root install"
|
||||
command="Power off"
|
||||
checksatatarget
|
||||
ShowWarning "This script will erase your device /dev/nand and $SDA_ROOT_PART. Continue?"
|
||||
formatnand
|
||||
formatsata "$SDA_ROOT_PART"
|
||||
create_armbian "/dev/nand1" "$SDA_ROOT_PART"
|
||||
;;
|
||||
3)
|
||||
title="SD boot / SATA root install"
|
||||
command="Reboot"
|
||||
checksatatarget
|
||||
ShowWarning "This script will erase your device $SDA_ROOT_PART. Continue?"
|
||||
formatsata "$SDA_ROOT_PART"
|
||||
create_armbian "" "$SDA_ROOT_PART"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
dialog --title "$title" --backtitle "$backtitle" --yes-label "$command" --no-label "Exit" \
|
||||
--yesno "\nAll done. $command $REMOVESDTXT" 7 60
|
||||
if [ $? -eq 0 ]; then "$(echo ${command,,} | sed 's/ //')"; fi
|
||||
dialog --title "$title" --backtitle "$backtitle" --yes-label "$command" --no-label "Exit" --yesno "\nAll done. $command $REMOVESDTXT" 7 60
|
||||
if [ $? -eq 0 ]; then "$(echo ${command,,} | sed 's/ //')"; fi
|
||||
Loading…
Reference in New Issue
Block a user