From 25b6709991e26c347c36f11e49b5e3253362fad4 Mon Sep 17 00:00:00 2001 From: Piotr Szczepanik Date: Wed, 7 Oct 2020 23:45:14 +0200 Subject: [PATCH] Added SPI flashing to nand-sata-install's SPI -> SATA, USB, NVMe option --- .../bsp/common/usr/sbin/nand-sata-install | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/packages/bsp/common/usr/sbin/nand-sata-install b/packages/bsp/common/usr/sbin/nand-sata-install index c9cbdcecd..23c42fad3 100755 --- a/packages/bsp/common/usr/sbin/nand-sata-install +++ b/packages/bsp/common/usr/sbin/nand-sata-install @@ -10,6 +10,7 @@ # Import: # DIR: path to u-boot directory # write_uboot_platform: function to write u-boot to a block device +# write_uboot_platform_mtd: function to write u-boot to a mtd (eg. SPI flash) device [[ -f /usr/lib/u-boot/platform_install.sh ]] && source /usr/lib/u-boot/platform_install.sh @@ -587,6 +588,20 @@ stop_running_services() done } +# show warning and write u-boot to SPI flash $1 = spi device name, $2 = u-boot files directory +write_uboot_to_spi_flash() +{ + local MTD_BLK="/dev/$1" + local DIR="$2" + local MESSAGE="This script will update the bootloader on SPI Flash $MTD_BLK. Continue?\nIt will take up to a few minutes." + dialog --title "$title" --backtitle "$backtitle" --cr-wrap --colors --yesno " \Z1$(toilet -W -f ascii9 WARNING)\Zn\n$MESSAGE" 16 53 + if [[ $? -eq 0 ]]; then + write_uboot_platform_mtd "$DIR" $MTD_BLK + update_bootscript + echo 'Done' + fi +} + main() { export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin @@ -691,6 +706,15 @@ main() show_warning "This script will erase your device $DISK_ROOT_PART. Continue?" format_disk "$DISK_ROOT_PART" create_armbian 'spi' "$DISK_ROOT_PART" + + if [[ $(type -t write_uboot_platform_mtd) == function ]]; then + dialog --title "$title" --backtitle "$backtitle" --yesno \ + "Do you want to write the bootloader to SPI flash?\n\nIt is required if you have not done it before or if you have some non-Armbian bootloader in SPI." 8 60 + + if [[ $? -eq 0 ]]; then + write_uboot_to_spi_flash $spicheck "$DIR" + fi + fi ;; 5) show_warning 'This script will update the bootloader on SD/eMMC. Continue?' @@ -711,11 +735,7 @@ main() return ;; 7) - MTD_BLK="/dev/${spicheck}" - show_warning "This script will update the bootloader on SPI Flash $MTD_BLK. Continue?" - write_uboot_platform_mtd "$DIR" $MTD_BLK - update_bootscript - echo 'Done' + write_uboot_to_spi_flash $spicheck "$DIR" return ;; esac