From b2910c1455eb084346ca1e5be4038f8d121ed3c1 Mon Sep 17 00:00:00 2001 From: Qubot <1445788683@qq.com> Date: Wed, 24 Jan 2024 15:12:33 +0800 Subject: [PATCH] change burn_to_emmc --- .../packages/bsp/common/usr/sbin/burn_to_emmc | 61 +++++++++---------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/external/packages/bsp/common/usr/sbin/burn_to_emmc b/external/packages/bsp/common/usr/sbin/burn_to_emmc index c1b8690..72cd91a 100755 --- a/external/packages/bsp/common/usr/sbin/burn_to_emmc +++ b/external/packages/bsp/common/usr/sbin/burn_to_emmc @@ -47,7 +47,7 @@ root_partition_device="${root_partition::-2}" # find targets: NAND, EMMC, SATA, SPI flash, NVMe [[ -b /dev/nand ]] && nandcheck=$(ls -d -1 /dev/nand* | grep -w 'nand' | awk '{print $NF}'); emmccheck=$(ls -d -1 /dev/mmcblk* | grep -w 'mmcblk[0-9]' | grep -v "$root_partition_device"); -diskcheck=$(lsblk -l | awk -F" " '/ disk / {print $1}' | grep -E '^sd|^nvme') +diskcheck=$(lsblk -l | awk -F" " '/ disk / {print $1}' | grep -E '^sd|^nvme|^mmc' | grep -v "$root_partition_device_name" | grep -v boot) spicheck=$(grep 'mtd' /proc/partitions | awk '{print $NF}') # define makefs and mount options @@ -71,7 +71,7 @@ mountopts[ext4]='defaults,noatime,commit=600,errors=remount-ro,x-gvfs-hide 0 1' mountopts[btrfs]='defaults,noatime,commit=600,compress=lzo,x-gvfs-hide 0 2' mountopts[f2fs]='defaults,noatime,x-gvfs-hide 0 2' -# Create boot and root file system "$1" = boot, "$2" = root (Example: create_bananapi "/dev/nand1" "/dev/sda3") +# Create boot and root file system "$1" = boot, "$2" = root (Example: create_bananapi "/dev/mmcblk1p1" "/dev/mmcblk1p1") create_bananapi() { # create mount points, mount and clean @@ -135,7 +135,7 @@ create_bananapi() lsof / | awk 'NR==1 || $4~/[0-9][uw]/' | grep -v "^COMMAND" >> $logfile # count files is needed for progress bar - #dialog --title " $title " --backtitle "$backtitle" --infobox "\n Counting files ... few seconds." 5 60 + dialog --title " $title " --backtitle "$backtitle" --infobox "\n Counting files ... few seconds." 5 60 TODO=$(rsync -ahvrltDn --delete --stats --exclude-from=$EX_LIST / "${TempDir}"/rootfs | grep "Number of files:"|awk '{print $4}' | tr -d '.,') echo -e "\nCopying ${TODO} files to $2. \c" >> $logfile @@ -190,11 +190,11 @@ create_bananapi() fi done | \ - #dialog --backtitle "$backtitle" --title " $title " --gauge "\n\n Transferring rootfs to $2 ($USAGE MB). \n\n \ - # This will take approximately $(( $((USAGE/300)) * 1 )) minutes to finish. Please wait!\n\n" 11 80 + dialog --backtitle "$backtitle" --title " $title " --gauge "\n\n Transferring rootfs to $2 ($USAGE MB). \n\n \ + This will take approximately $(( $((USAGE/300)) * 1 )) minutes to finish. Please wait!\n\n" 11 80 # run rsync again to silently catch outstanding changes between / and "${TempDir}"/rootfs/ - #dialog --title "$title" --backtitle "$backtitle" --infobox "\n Cleaning up ... Almost done." 5 60 + dialog --title "$title" --backtitle "$backtitle" --infobox "\n Cleaning up ... Almost done." 5 60 rsync -avrltD --delete --exclude-from=$EX_LIST / "${TempDir}"/rootfs >/dev/null 2>&1 # creating fstab from scratch @@ -206,8 +206,6 @@ create_bananapi() echo "tmpfs /tmp tmpfs defaults,nosuid 0 0" >> "${TempDir}"/rootfs/etc/fstab grep swap /etc/fstab >> "${TempDir}"/rootfs/etc/fstab - sed -i '/burn/d' ${TempDir}/rootfs/etc/rc.local - # creating fstab, kernel and boot script for NAND partition # if [[ $1 == *nand* ]]; then @@ -443,8 +441,8 @@ format_emmc() [[ -n $BTRFS && ! `uname -r | grep '^3.' ` ]] && FilesystemTargets=$FilesystemTargets" 5 $BTRFS" FilesystemOptions=($FilesystemTargets) - #FilesystemCmd=(dialog --title "Select filesystem type for eMMC $1" --backtitle "$backtitle" --menu "\n$infos" 10 60 16) - #FilesystemChoices=$("${FilesystemCmd[@]}" "${FilesystemOptions[@]}" 2>&1 >/dev/tty) + FilesystemCmd=(dialog --title "Select filesystem type for eMMC $1" --backtitle "$backtitle" --menu "\n$infos" 10 60 16) + FilesystemChoices=$("${FilesystemCmd[@]}" "${FilesystemOptions[@]}" 2>&1 >/dev/tty) FilesystemChoices=1 [[ $? -ne 0 ]] && exit 9 @@ -472,7 +470,7 @@ format_emmc() PART_TABLE_TYPE=$(parted "$root_partition_device" print -sm | awk -F ":" -v pattern="$root_partition_device" '$0 ~ pattern {print $6}') parted -s "$1" -- mklabel "$PART_TABLE_TYPE" - #dialog --title "$title" --backtitle "$backtitle" --infobox "\nFormating $1 to $eMMCFilesystemChoosen ... please wait." 5 60 + dialog --title "$title" --backtitle "$backtitle" --infobox "\nFormating $1 to $eMMCFilesystemChoosen ... please wait." 5 60 # we can't boot from btrfs or f2fs if [[ $eMMCFilesystemChoosen =~ ^(btrfs|f2fs)$ ]]; then local partedFsType="${eMMCFilesystemChoosen}" @@ -557,7 +555,7 @@ format_disk() check_partitions() { IFS=" " - AvailablePartitions=$(lsblk -l | awk -F" " '/ part | raid..? / {print $1}' | grep -E '^sd|^nvme|^md') + AvailablePartitions=$(lsblk -l | awk -F" " '/ part | raid..? / {print $1}' | grep -E '^sd|^nvme|^md|^mmc') if [[ -z $AvailablePartitions ]]; then dialog --title "$title" --backtitle "$backtitle" --colors --msgbox \ "\n\Z1There are no avaliable partitions. Please create them.\Zn" 7 60 @@ -565,7 +563,7 @@ check_partitions() apt-get -y -q install gdisk >/dev/null 2>&1 gdisk /dev/$diskcheck fi - AvailablePartitions=$(lsblk -l | awk -F" " '/ part | raid..? / {print $1}' | grep -E '^sd|^nvme|^md' | uniq | sed 's|^|/dev/|' | nl | xargs echo -n) + AvailablePartitions=$(lsblk -l | awk -F" " '/ part | raid..? / {print $1}' | grep -E '^sd|^nvme|^md|^mmc' | uniq | sed 's|^|/dev/|' | nl | xargs echo -n) PartitionOptions=($AvailablePartitions) PartitionCmd=(dialog --title 'Select destination:' --backtitle "$backtitle" --menu "\n$infos" 10 60 16) @@ -658,24 +656,22 @@ main() dest_root='/dev/nand2' fi - ## Boot + RootFS relocation options - #[[ -n $diskcheck ]] && options+=(1 'Boot from SD - system on SATA, USB or NVMe') - #[[ -n $nandcheck || -n $emmccheck ]] && options+=(2 "Boot from $ichip - system on $ichip") - #[[ ( -n $nandcheck || -n $emmccheck ) && -n $diskcheck ]] && options+=(3 "Boot from $ichip - system on SATA, USB or NVMe") - #[[ -n $spicheck ]] && options+=(4 'Boot from SPI - system on SATA, USB or NVMe') + # Boot + RootFS relocation options + [[ -n $diskcheck ]] && options+=(1 'Boot from SD - system on SATA, USB or NVMe') + [[ -n $nandcheck || -n $emmccheck ]] && options+=(2 "Boot from $ichip - system on $ichip") + [[ ( -n $nandcheck || -n $emmccheck ) && -n $diskcheck ]] && options+=(3 "Boot from $ichip - system on SATA, USB or NVMe") + [[ -n $spicheck ]] && options+=(4 'Boot from SPI - system on SATA, USB or NVMe') - ## U-boot install/update options - #[[ -n ${root_partition_device} ]] && options+=(5 'Install/Update the bootloader on SD/eMMC') - #[[ ( $LINUXFAMILY == odroidxu4 || $LINUXFAMILY == mvebu* || $LINUXFAMILY == mt7623 ) && ( -b /dev/mmcblk0boot0 || -b /dev/mmcblk1boot0 ) ]] && options+=(6 'Install/Update the bootloader on special eMMC partition') - #[[ -n $spicheck && $(type -t write_uboot_platform_mtd) == function ]] && options+=(7 'Install/Update the bootloader on SPI Flash') + # U-boot install/update options + [[ -n ${root_partition_device} ]] && options+=(5 'Install/Update the bootloader on SD/eMMC') + [[ ( $LINUXFAMILY == odroidxu4 || $LINUXFAMILY == mvebu* || $LINUXFAMILY == mt7623 ) && ( -b /dev/mmcblk0boot0 || -b /dev/mmcblk1boot0 ) ]] && options+=(6 'Install/Update the bootloader on special eMMC partition') + [[ -n $spicheck && $(type -t write_uboot_platform_mtd) == function ]] && options+=(7 'Install/Update the bootloader on SPI Flash') - #[[ ${#options[@]} -eq 0 || "$root_uuid" == "$emmcuuid" || "$root_uuid" == "/dev/nand2" ]] && \ - #dialog --ok-label 'Cancel' --title ' Warning ' --backtitle "$backtitle" --colors --no-collapse --msgbox '\n\Z1There are no targets. Please check your drives.\Zn' 7 52 - #cmd=(dialog --title 'Choose an option:' --backtitle "$backtitle" --menu "\nCurrent root: $root_uuid \n \n" 14 60 7) - #choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty) - #[[ $? -ne 0 ]] && exit 16 - - choices=2 + [[ ${#options[@]} -eq 0 || "$root_uuid" == "$emmcuuid" || "$root_uuid" == "/dev/nand2" ]] && \ + dialog --ok-label 'Cancel' --title ' Warning ' --backtitle "$backtitle" --colors --no-collapse --msgbox '\n\Z1There are no targets. Please check your drives.\Zn' 7 52 + cmd=(dialog --title 'Choose an option:' --backtitle "$backtitle" --menu "\nCurrent root: $root_uuid \n \n" 14 60 7) + choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty) + [[ $? -ne 0 ]] && exit 16 for choice in $choices do @@ -691,7 +687,7 @@ main() 2) title="$ichip install" command='Power off' - #show_warning "This script will erase your $ichip. Continue?" + show_warning "This script will erase your $ichip. Continue?" if [[ -n $emmccheck ]]; then umount_device "$emmccheck" format_emmc "$emmccheck" @@ -762,9 +758,8 @@ main() esac done - #dialog --title "$title" --backtitle "$backtitle" --yes-label "$command" --no-label 'Exit' --yesno "\nAll done. $command $REMOVESDTXT" 7 70 - poweroff - #[[ $? -eq 0 ]] && "$(echo ${command,,} | sed 's/ //')" + dialog --title "$title" --backtitle "$backtitle" --yes-label "$command" --no-label 'Exit' --yesno "\nAll done. $command $REMOVESDTXT" 7 70 + [[ $? -eq 0 ]] && "$(echo ${command,,} | sed 's/ //')" } # main main "$@"