From eebbee793da9e0d514a0215f8734b54c29747640 Mon Sep 17 00:00:00 2001 From: Martin Ayotte Date: Tue, 22 Nov 2016 11:07:10 -0500 Subject: [PATCH 1/2] add spi-patch-for-A64-4.9.x.patc for pine64-dev --- .../pine64-dev/spi-patch-for-A64-4.9.x.patch | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 patch/kernel/pine64-dev/spi-patch-for-A64-4.9.x.patch diff --git a/patch/kernel/pine64-dev/spi-patch-for-A64-4.9.x.patch b/patch/kernel/pine64-dev/spi-patch-for-A64-4.9.x.patch new file mode 100644 index 0000000000..c3a6491af7 --- /dev/null +++ b/patch/kernel/pine64-dev/spi-patch-for-A64-4.9.x.patch @@ -0,0 +1,89 @@ +diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi b/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi +index e3c3d7d..522447c 100644 +--- a/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi ++++ b/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi +@@ -52,6 +52,11 @@ + #address-cells = <1>; + #size-cells = <1>; + ++ aliases { ++ spi0 = &spi0; ++ spi1 = &spi1; ++ }; ++ + cpus { + #address-cells = <1>; + #size-cells = <0>; +@@ -225,6 +230,35 @@ + allwinner,drive = ; + allwinner,pull = ; + }; ++ ++ spi0_pins_a: spi0@0 { ++ allwinner,pins = "PC0", "PC1", "PC2"; ++ allwinner,function = "spi0"; ++ allwinner,drive = ; ++ allwinner,pull = ; ++ }; ++ ++ spi0_cs0_pins_a: spi0_cs0@0 { ++ allwinner,pins = "PC3"; ++ allwinner,function = "spi0"; ++ allwinner,drive = ; ++ allwinner,pull = ; ++ }; ++ ++ spi1_pins_a: spi1@0 { ++ allwinner,pins = "PD1", "PD2", "PD3"; ++ allwinner,function = "spi1"; ++ allwinner,drive = ; ++ allwinner,pull = ; ++ }; ++ ++ spi1_cs0_pins_a: spi1_cs0@0 { ++ allwinner,pins = "PD0"; ++ allwinner,function = "spi1"; ++ allwinner,drive = ; ++ allwinner,pull = ; ++ }; ++ + }; + + uart0: serial@1c28000 { +@@ -387,6 +421,36 @@ + }; + }; + ++ spi0: spi@01c68000 { ++ compatible = "allwinner,sun6i-a31-spi"; ++ reg = <0x01c68000 0x1000>; ++ interrupts = ; ++ pinctrl-names = "default", "sleep"; ++ pinctrl-0 = <&spi0_pins_a>, <&spi0_cs0_pins_a>; ++ clocks = <&ccu CLK_BUS_SPI0>, <&ccu CLK_SPI0>; ++ clock-names = "ahb", "mod"; ++ clock-frequency = <0x5f5e100>; ++ resets = <&ccu RST_BUS_SPI0>; ++ status = "disabled"; ++ #address-cells = <1>; ++ #size-cells = <0>; ++ }; ++ ++ spi1: spi@01c69000 { ++ compatible = "allwinner,sun6i-a31-spi"; ++ reg = <0x01c69000 0x1000>; ++ interrupts = ; ++ pinctrl-names = "default", "sleep"; ++ pinctrl-0 = <&spi1_pins_a>, <&spi1_cs0_pins_a>; ++ clocks = <&ccu CLK_BUS_SPI1>, <&ccu CLK_SPI1>; ++ clock-names = "ahb", "mod"; ++ clock-frequency = <0x5f5e100>; ++ resets = <&ccu RST_BUS_SPI1>; ++ status = "disabled"; ++ #address-cells = <1>; ++ #size-cells = <0>; ++ }; ++ + usbphy: phy@01c19400 { + compatible = "allwinner,sun50i-a64-usb-phy"; + reg = <0x01c19400 0x14>, From c364f1c5f0255e593d697eeb1fdfdb4fc1865dbb Mon Sep 17 00:00:00 2001 From: Igor Pecovnik Date: Tue, 22 Nov 2016 21:42:37 +0100 Subject: [PATCH 2/2] RFC: nand-sata-install tool - fixed non working eMMC / SATA option, added estimated transfer time, invoke fdisk if target is not partitioned, option to select target FS type: ext4, ext3, ext2. Tested with all possible combination ... --- .../nand-sata-install/nand-sata-install.sh | 199 ++++++++++++------ 1 file changed, 133 insertions(+), 66 deletions(-) diff --git a/scripts/nand-sata-install/usr/lib/nand-sata-install/nand-sata-install.sh b/scripts/nand-sata-install/usr/lib/nand-sata-install/nand-sata-install.sh index d19673fe95..b2aacdff3e 100644 --- a/scripts/nand-sata-install/usr/lib/nand-sata-install/nand-sata-install.sh +++ b/scripts/nand-sata-install/usr/lib/nand-sata-install/nand-sata-install.sh @@ -1,10 +1,10 @@ #!/bin/bash # -# Copyright (c) 2014 Igor Pecovnik, igor.pecovnik@gma**.com -# -# www.igorpecovnik.com / images + support +# Copyright (c) Authors: http://www.armbian.com/authors # # NAND, eMMC, SATA and USB Armbian installer +# +# Remarks: # 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, ... # @@ -18,10 +18,12 @@ CWD="/usr/lib/nand-sata-install" EX_LIST="${CWD}/exclude.txt" nanddevice="/dev/nand" +logfile="/tmp/nand-sata-install.log" +rm -f $logfile # read in board info [[ -f /etc/armbian-release ]] && source /etc/armbian-release -backtitle="Armbian for $BOARD_NAME install script, http://www.armbian.com | Author: Igor Pecovnik" +backtitle="Armbian for $BOARD_NAME install script, http://www.armbian.com" title="NAND, eMMC, SATA and USB Armbian installer v""$VERSION" # exception @@ -66,24 +68,39 @@ create_armbian() # creating nand boot. Copy precompiled uboot rsync -aqc $BOOTLOADER/* /mnt/bootfs fi - + + # write stuff to log + echo "SD uuid: $sduuid" >> $logfile + echo "Satauid: $satauuid" >> $logfile + echo "Emmcuuid: $emmcuuid $eMMCFilesystemChoosen" >> $logfile + echo "Boot: \$1 $1 $eMMCFilesystemChoosen" >> $logfile + echo "Root: \$2 $2 $FilesystemChoosen" >> $logfile + echo "Usage: $USAGE" >> $logfile + echo "Dest: $DEST" >> $logfile + # 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 '.,') - - # creating rootfs + + # 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 - + | dialog --backtitle "$backtitle" --title "$title" --gauge "\n\n Creating rootfs on $2 ($USAGE Mb). \n\n \ + This will take around $((USAGE/60)) minutes to finish. Please wait!\n\n" 11 80 + # run rsync again to silently catch outstanding changes between / and /mnt/rootfs/ dialog --title "$title" --backtitle "$backtitle" --infobox "\n Cleaning up ... few seconds." 5 40 rsync -avrltD --delete --exclude-from=$EX_LIST / /mnt/rootfs >/dev/null 2>&1 + + # creating fstab from scratch rm -f /mnt/rootfs/etc/fstab + # creating fstab, kernel and boot script for NAND partition + # if [[ $1 == *nand* ]]; then + echo "Install to NAND" >> $logfile 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 @@ -113,64 +130,70 @@ create_armbian() 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 == ${emmccheck}p1 || $1 == ${emmccheck}p1 ]]; then - - # fix that we can have one exlude file - cp -R /boot/ /mnt/bootfs - - # eMMC install - # old boot scripts + fi + + + # Boot from eMMC, root = eMMMC or SATA / USB + # + if [[ $2 == ${emmccheck}p1 || $1 == ${emmccheck}p1 ]]; then - sed -e 's,root='"$root_partition"',root='"$emmcuuid"',g' -i /mnt/bootfs/boot/boot.cmd + if [[ $2 == ${SDA_ROOT_PART} ]]; then + local targetuuid=$satauuid + local choosen_fs=$FilesystemChoosen + echo "Boot on eMMC, root on USB/SATA" >> $logfile + echo "$emmcuuid /boot $eMMCFilesystemChoosen defaults 0 0" > /mnt/rootfs/etc/fstab + else + local targetuuid=$emmcuuid + local choosen_fs=$eMMCFilesystemChoosen + echo "Full install to eMMC" >> $logfile + fi + + # fix that we can have one exlude file + cp -R /boot /mnt/bootfs + # old boot scripts + sed -e 's,root='"$root_partition"',root='"$targetuuid"',g' -i /mnt/bootfs/boot/boot.cmd # new boot scripts if [[ -f /mnt/bootfs/boot/armbianEnv.txt ]]; then - sed -e 's,rootdev=.*,rootdev='"$emmcuuid"',g' -i /mnt/bootfs/boot/armbianEnv.txt + sed -e 's,rootdev=.*,rootdev='"$targetuuid"',g' -i /mnt/bootfs/boot/armbianEnv.txt else - sed -e 's,setenv rootdev.*,setenv rootdev '"$emmcuuid"',g' -i /mnt/bootfs/boot/boot.cmd + sed -e 's,setenv rootdev.*,setenv rootdev '"$targetuuid"',g' -i /mnt/bootfs/boot/boot.cmd fi mkimage -C none -A arm -T script -d /mnt/bootfs/boot/boot.cmd /mnt/bootfs/boot/boot.scr >/dev/null 2>&1 || (echo "Error"; exit 0) - # fstab adj - echo "$emmcuuid / ext4 defaults,noatime,nodiratime,commit=600,errors=remount-ro 0 1" > /mnt/rootfs/etc/fstab - + echo "$targetuuid / $choosen_fs defaults,noatime,nodiratime,commit=600,errors=remount-ro 0 1" >> /mnt/rootfs/etc/fstab if [[ $(type -t write_uboot_platform) != function ]]; then echo "Error: no u-boot package found, exiting" exit -1 fi - write_uboot_platform $DIR $emmccheck + + fi - elif [[ -f /boot/boot.cmd ]]; then - # old boot scripts + # Boot from SD card, root = SATA / USB + # + if [[ $2 == ${SDA_ROOT_PART} && -z $1 ]]; then + echo "Install to USB/SATA boot from SD" >> $logfile sed -e 's,root='"$root_partition"',root='"$satauuid"',g' -i /boot/boot.cmd + sed -e 's,root='"$root_partition"',root='"$satauuid"',g' -i /boot/boot.ini # new boot scripts if [[ -f /boot/armbianEnv.txt ]]; then sed -e 's,rootdev=.*,rootdev='"$satauuid"',g' -i /boot/armbianEnv.txt else sed -e 's,setenv rootdev.*,setenv rootdev '"$satauuid"',g' -i /boot/boot.cmd + sed -e 's,setenv rootdev.*,setenv rootdev '"$satauuid"',g' -i /boot/boot.ini fi mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr >/dev/null 2>&1 || (echo "Error"; exit 0) mkdir -p /mnt/rootfs/media/mmc/boot echo "$sduuid /media/mmc ext4 defaults 0 0" >> /mnt/rootfs/etc/fstab echo "/media/mmc/boot /boot none bind 0 0" >> /mnt/rootfs/etc/fstab echo "$satauuid / ext4 defaults,noatime,nodiratime,commit=600,errors=remount-ro 0 1" >> /mnt/rootfs/etc/fstab - elif [[ -f /boot/boot.ini ]]; then - # old boot scripts - sed -e 's,root='"$root_partition"',root='"$satauuid"',g' -i /boot/boot.ini - # new boot scripts - if [[ -f /boot/armbianEnv.txt ]]; then - sed -e 's,rootdev=.*,rootdev='"$satauuid"',g' -i /boot/armbianEnv.txt - else - sed -e 's,setenv rootdev.*,setenv rootdev '"$satauuid"',g' -i /boot/boot.ini - fi - mkdir -p /mnt/rootfs/media/mmc/boot - echo "$sduuid /media/mmc ext4 defaults 0 0" >> /mnt/rootfs/etc/fstab - echo "/media/mmc/boot /boot none bind 0 0" >> /mnt/rootfs/etc/fstab - echo "$satauuid / ext4 defaults,noatime,nodiratime,commit=600,errors=remount-ro 0 1" >> /mnt/rootfs/etc/fstab - fi + fi + + + # Restore TMP and swap echo "tmpfs /tmp tmpfs defaults,nosuid 0 0" >> /mnt/rootfs/etc/fstab cat /etc/fstab | grep swap >> /mnt/rootfs/etc/fstab + umountdevice "/dev/sda" } # create_armbian @@ -189,7 +212,9 @@ umountdevice() fi } # umountdevice -# Recognize root filesystem + +# recognize root filesystem +# recognize_root() { # replace with PARTUUID approach parsing /proc/cmdline when ready @@ -204,27 +229,30 @@ recognize_root() break; fi done -} # recognize_root +} -# Formatting NAND - no parameters. Fixed solution. + +# formatting sunxi NAND - no parameters, fixed solution. +# formatnand() { [[ ! -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 + (echo y;) | sunxi-nand-part -f a20 /dev/nand 65536 'bootloader 65536' 'linux 0' >> $logfile 2>&1 else - (echo y;) | sunxi-nand-part -f a10 /dev/nand 65536 'bootloader 65536' 'linux 0' >/dev/null 2>&1 + (echo y;) | sunxi-nand-part -f a10 /dev/nand 65536 'bootloader 65536' 'linux 0' >> $logfile 2>&1 fi - mkfs.vfat /dev/nand1 >/dev/null 2>&1 - mkfs.ext4 /dev/nand2 >/dev/null 2>&1 -} # formatnand + mkfs.vfat -qF /dev/nand1 >> $logfile 2>&1 + mkfs.ext4 -qF /dev/nand2 >> $logfile 2>&1 +} -# Formatting eMMC [device] example /dev/mmcblk1 + +# formatting eMMC [device] example /dev/mmcblk1 - one can select filesystem type +# formatemmc() { - # deletes all partitions - dialog --title "$title" --backtitle "$backtitle" --infobox "\n Formating eMMC ... one moment." 5 40 + # deletes all partitions on eMMC drive dd bs=1 seek=446 count=64 if=/dev/zero of=$1 >/dev/null 2>&1 # calculate capacity and reserve some unused space to ease cloning of the installation # to other media 'of the same size' (one sector less and cloning will fail) @@ -242,18 +270,45 @@ formatemmc() parted -s $1 -- mklabel msdos parted -s $1 -- mkpart primary ext4 2048s ${LASTSECTOR}s partprobe $1 - # create fs - mkfs.ext4 -qF $1"p1" >/dev/null 2>&1 + + # choose and create fs + IFS=" " + FilesystemTargets="1 ext4 2 ext3 3 ext2" + FilesystemOptions=($FilesystemTargets) + + FilesystemCmd=(dialog --title "Select filesystem type for eMMC $1" --backtitle "$backtitle" --menu "\n$infos" 9 60 16) + FilesystemChoices=$("${FilesystemCmd[@]}" "${FilesystemOptions[@]}" 2>&1 >/dev/tty) + + [[ $? -ne 0 ]] && exit 1 + eMMCFilesystemChoosen=${FilesystemOptions[(2*$FilesystemChoices)-1]} + + dialog --title "$title" --backtitle "$backtitle" --infobox "\nFormating $1 to $eMMCFilesystemChoosen ... please wait." 5 60 + mkfs.${eMMCFilesystemChoosen} -qF $1"p1" >> $logfile 2>&1 + emmcuuid=$(blkid -o export $1"p1" | grep -w UUID) -} # formatemmc +} + # formatting SATA/USB [device] example /dev/sda3 +# formatsata() { - 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 -} # formatsata + # choose and create fs + IFS=" " + FilesystemTargets="1 ext4 2 ext3 3 ext2" + FilesystemOptions=($FilesystemTargets) + + FilesystemCmd=(dialog --title "Select filesystem type for $1" --backtitle "$backtitle" --menu "\n$infos" 9 60 16) + FilesystemChoices=$("${FilesystemCmd[@]}" "${FilesystemOptions[@]}" 2>&1 >/dev/tty) + + [[ $? -ne 0 ]] && exit 1 + FilesystemChoosen=${FilesystemOptions[(2*$FilesystemChoices)-1]} + + dialog --title "$title" --backtitle "$backtitle" --infobox "\nFormating $1 to $FilesystemChoosen ... please wait." 5 60 + mkfs.${FilesystemChoosen} -qF $1 >> $logfile 2>&1 + tune2fs $1 -o journal_data_writeback >> $logfile 2>&1 +} + # choose target SATA/USB partition. checksatatarget() @@ -261,29 +316,37 @@ checksatatarget() IFS=" " SataTargets=$(awk '/sd/ {print "/dev/"$4}' &1 >/dev/tty) + [[ $? -ne 0 ]] && exit 1 SDA_ROOT_PART=${SataOptions[(2*$SataChoices)-1]} -} # checksatatarget +} + # show warning [TEXT] ShowWarning() -{ +{ dialog --title "$title" --backtitle "$backtitle" --cr-wrap --colors --yesno " \Z1$(toilet -f mono12 WARNING)\Zn\n$1" 17 74 [[ $? -ne 0 ]] && exit 1 -} # ShowWarning +} + main() { export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + # if mounted + umount /mnt/rootfs >> $logfile 2>&1 + umount /mnt/bootfs >> $logfile 2>&1 + # This tool must run under root if [[ $EUID -ne 0 ]]; then @@ -318,7 +381,7 @@ main() [[ ${#options[@]} -eq 0 || "$root_partition" == "$emmcuuid" || "$root_partition" == "/dev/nand2" ]] && 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) + cmd=(dialog --title "Choose an option:" --backtitle "$backtitle" --menu "\nCurrent root: $root_partition \n \n" 12 60 7) choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty) [[ $? -ne 0 ]] && exit 1 @@ -337,6 +400,8 @@ main() formatnand fi create_armbian "$dest_boot" "$dest_root" + umount /mnt/rootfs + umount /mnt/bootfs ;; 2) title="$ichip boot / SATA root install" @@ -353,6 +418,8 @@ main() umountdevice "${SDA_ROOT_PART//[0-9]*/}" formatsata "$SDA_ROOT_PART" create_armbian "$dest_boot" "$SDA_ROOT_PART" + umount /mnt/rootfs + umount /mnt/bootfs ;; 3) title="SD boot / SATA root install"