From ed3f9afccc1ff03420e63359977e57371b8396f4 Mon Sep 17 00:00:00 2001 From: Yong Lu Date: Sat, 7 Jul 2018 04:38:11 +0800 Subject: [PATCH 01/13] Add S241 into psl-device (#41) * Update NSA121B user address Signed-off-by: Lu Yong --- psl-devices | 1 + 1 file changed, 1 insertion(+) diff --git a/psl-devices b/psl-devices index 932eb23..46e085e 100644 --- a/psl-devices +++ b/psl-devices @@ -16,4 +16,5 @@ 0x04dd NallatechN250SP Xilinx 0x4000000 256 0x060d NallatechN250SP Xilinx 0x4000000 256 0x060F AlphadataVU3P Xilinx 0x1000000 64 SPIx8 0x3000000 +0x0660 SemptianNSA241 Xilinx 0x8000000 64 SPIx4 0x0661 FlysliceVU9P Xilinx 0x4000000 64 SPIx4 From a3102f7e40f3722eb601b9c8fa1afaac1480be8a Mon Sep 17 00:00:00 2001 From: Alexandre CASTELLANE Date: Fri, 7 Dec 2018 10:10:22 +0100 Subject: [PATCH 02/13] AD9V3 sub device ID corrected (#43) * AD9V3 sub device ID corrected Signed-off-by: Alexandre Castellane * update for SPI8 case Signed-off-by: Alexandre Castellane * change error message (card failure case) Signed-off-by: Alexandre Castellane --- README.md | 4 +++- capi-flash-script.sh | 2 +- psl-devices | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 68d8abb..ce7ffbd 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,9 @@ Uninstall: `sudo make uninstall` # capi-flash-script -Usage: `sudo capi-flash-script ` +Usage: +Single file flash memory : `sudo capi-flash-script ` +SPI8 with 2 flash memory : `sudo capi-flash-script ` This script can be used to flash a specific card in a system with one or more CAPI cards installed. diff --git a/capi-flash-script.sh b/capi-flash-script.sh index 11e6415..158d6c4 100755 --- a/capi-flash-script.sh +++ b/capi-flash-script.sh @@ -203,7 +203,7 @@ elif [[ ${fpga_type[$c]} == "Xilinx" ]]; then exit 0 fi else - printf "${bold}ERROR: ${normal}Card not listed in psl-devices!\n" + printf "${bold}ERROR: ${normal}Card not listed in psl-devices or previous card failed or is not responding\n" exit 0 fi diff --git a/psl-devices b/psl-devices index 46e085e..bf310e6 100644 --- a/psl-devices +++ b/psl-devices @@ -15,6 +15,6 @@ 0x060a NallatechKU60 Xilinx 0x2000000 256 0x04dd NallatechN250SP Xilinx 0x4000000 256 0x060d NallatechN250SP Xilinx 0x4000000 256 -0x060F AlphadataVU3P Xilinx 0x1000000 64 SPIx8 0x3000000 +0x060f AlphadataVU3P Xilinx 0x1000000 64 SPIx8 0x3000000 0x0660 SemptianNSA241 Xilinx 0x8000000 64 SPIx4 0x0661 FlysliceVU9P Xilinx 0x4000000 64 SPIx4 From 3d6ea197dba6ada7d03fe0d300f435e1df6fdc95 Mon Sep 17 00:00:00 2001 From: fmoyen Date: Wed, 17 Apr 2019 14:37:37 +0200 Subject: [PATCH 03/13] New reset checks --- capi-utils-common.sh | 82 +++++++++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 23 deletions(-) diff --git a/capi-utils-common.sh b/capi-utils-common.sh index b0c2f1f..6222e56 100644 --- a/capi-utils-common.sh +++ b/capi-utils-common.sh @@ -37,15 +37,46 @@ function perst_factory() { rm -rf "/var/cxl/capi-flash-script.lock" } +# Test if a card reset is done +function testcard +{ + cardId=$1 + cxlDir="/sys/class/cxl/card$cardId" + cxlafuFile="/dev/cxl/afu$cardId.0m" + cxlDirStatus=0 # 0->still here, 1->disapeared so reset is on going, 2-> first dir reappeared 3->back here so reset is done + + maxCount=50000 + count=0 + while true + do + case $cxlDirStatus in + 0) + [ $count -eq 0 ] && printf "." && count=$maxCount + [ ! -d $cxlDir ] && cxlDirStatus=1 && printf "\n$cxlDir deleted\n" + ;; + 1) + [ $count -eq 0 ] && printf "." && count=$maxCount + [ -d $cxlDir ] && cxlDirStatus=2 && printf "\n$cxlDir recreated\n" + ;; + 2) + [ $count -eq 0 ] && printf "." && count=$maxCount + [ -e $cxlafuFile ] && cxlDirStatus=3 && printf "\n$cxlafuFile recreated\n" + ;; + 3) + break + ;; + esac + count=$((count-1)) + done +} + +export -f testcard # function exportation in order to allow using it with timeout command below + # Reset a card and control what image gets loaded function reset_card() { - # Set return status - ret_status=0 # Timeout for reset - reset_timeout=30 - reset_count=0 - # get number of cards in system - n=`ls -d /sys/class/cxl/card* | awk -F"/sys/class/cxl/card" '{ print $2 }' | wc -w` + reset_timeout=60 + # eeh_max_freezes: default number of resets allowed per PCI device per # hour. Backup/restore this counter, since if card is rest too often, # it would be fenced away. @@ -56,36 +87,41 @@ function reset_card() { [ -n "$3" ] && printf "$3\n" || printf "Preparing to reset card\n" [ -n "$4" ] && reset_timeout=$4 - sleep 5 + # sleep 5 ## Why ? printf "Resetting card $1: " c=$1 printf $2 > /sys/class/cxl/card$c/load_image_on_perst ic=`cat /sys/class/cxl/card$c/load_image_on_perst` printf "load_image_on_perst is set to \"$ic\". Reset!\n" - printf 1 > /sys/class/cxl/card$c/reset - sleep 5 - while true; do - if [[ `ls -d /sys/class/cxl/card* 2> /dev/null | awk -F"/sys/class/cxl/card" '{ print $2 }' | wc -w` == "$n" ]]; then - break - fi - printf "." - sleep 1 - reset_count=$((reset_count + 1)) - if [[ $reset_count -eq $reset_timeout ]]; then - printf "${bold}ERROR:${normal} Reset timeout has occurred\n" - ret_status=1 - break - fi - done + + cxlDir="/sys/class/cxl/card$c" + + printf 1 > $cxlDir/reset # reset requested + + if timeout $reset_timeout bash -c "testcard $c" + then + ret_status=0 + else + ret_status=1 + fi + printf "\n" if [ -f /sys/kernel/debug/powerpc/eeh_max_freezes ]; then echo $eeh_max_freezes > /sys/kernel/debug/powerpc/eeh_max_freezes fi + if [ $ret_status -ne 0 ]; then + printf "${bold}ERROR:${normal} Reset timeout has occurred\n\n" exit 1 else - printf "Reset complete\n" +# Uncomment the 2 following lines should you want to give access to all users +# printf "Doing : sudo chmod -R ugo+rw /dev/cxl\n" +# sudo chmod -R ugo+rw /dev/cxl + printf "Newly /dev/cxl device will need sudo authorization" + printf "example: sudo snap_maint" + printf "If you don't want to bother with sudo command, you may do 'sudo chmod -R ugo+rw /dev/cxl'" + printf "Reset complete\n\n" fi } From b9f7b40b21a808cc24b168acf9662839fdb12bdd Mon Sep 17 00:00:00 2001 From: fmoyen Date: Wed, 17 Apr 2019 15:03:56 +0200 Subject: [PATCH 04/13] Reset Improvements --- capi-utils-common.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/capi-utils-common.sh b/capi-utils-common.sh index 6222e56..418e952 100644 --- a/capi-utils-common.sh +++ b/capi-utils-common.sh @@ -60,7 +60,7 @@ function testcard ;; 2) [ $count -eq 0 ] && printf "." && count=$maxCount - [ -e $cxlafuFile ] && cxlDirStatus=3 && printf "\n$cxlafuFile recreated\n" + [ -e $cxlafuFile ] && cxlDirStatus=3 && printf "$cxlafuFile recreated\n" ;; 3) break @@ -118,9 +118,9 @@ function reset_card() { # Uncomment the 2 following lines should you want to give access to all users # printf "Doing : sudo chmod -R ugo+rw /dev/cxl\n" # sudo chmod -R ugo+rw /dev/cxl - printf "Newly /dev/cxl device will need sudo authorization" - printf "example: sudo snap_maint" - printf "If you don't want to bother with sudo command, you may do 'sudo chmod -R ugo+rw /dev/cxl'" + printf "\nNew /dev/cxl/* device will need sudo authorization\n" + printf "example: sudo snap_maint -v\n" + printf "Tune /dev/cxl/* privileges if needed\n" printf "Reset complete\n\n" fi } From cf05b340641ca2752014f42a7aa92da669773a8b Mon Sep 17 00:00:00 2001 From: Yong Lu Date: Fri, 26 Apr 2019 16:06:27 +0800 Subject: [PATCH 05/13] add U200 device (#46) Signed-off-by: Lu Yong --- psl-devices | 1 + 1 file changed, 1 insertion(+) diff --git a/psl-devices b/psl-devices index bf310e6..771a95d 100644 --- a/psl-devices +++ b/psl-devices @@ -18,3 +18,4 @@ 0x060f AlphadataVU3P Xilinx 0x1000000 64 SPIx8 0x3000000 0x0660 SemptianNSA241 Xilinx 0x8000000 64 SPIx4 0x0661 FlysliceVU9P Xilinx 0x4000000 64 SPIx4 +0x0665 U200 Xilinx 0x1002000 64 SPIx4 From c50ae4175118c1a4374d2499df6a449893f56f44 Mon Sep 17 00:00:00 2001 From: fmoyen Date: Fri, 10 Jan 2020 17:28:03 +0100 Subject: [PATCH 06/13] capi-flash-script.sh: Bug correction caused by counting cards using lspci output Card may sometimes be seen by lspci but without corresponding /sys/class/cxl/cardX directory, making capi-flash-script.sh crash. Signed-off-by: fmoyen --- capi-flash-script.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/capi-flash-script.sh b/capi-flash-script.sh index 158d6c4..1637b8e 100755 --- a/capi-flash-script.sh +++ b/capi-flash-script.sh @@ -138,8 +138,7 @@ printf "\n${bold}Current date:${normal}\n$(date)\n\n" printf "${bold}%-7s %-30s %-29s %-20s %s${normal}\n" "#" "Card" "Flashed" "by" "Last Image" # print card information and flash history -i=0; -while read d; do +for i in `seq 0 $((n - 1))`; do p[$i]=$(cat /sys/class/cxl/card$i/device/subsystem_device) # check for legacy device if [[ ${p[$i]:0:6} == "0x04af" ]]; then @@ -158,8 +157,7 @@ while read d; do printf "%-7s %-30s %-29s %-20s %s\n" "card$i" "${line:6:25}" "${f:0:29}" "${f:30:20}" "${f:51}" fi done < "$package_root/psl-devices" - i=$[$i+1] -done < <(lspci -d "1014":"477" ) +done printf "\n" From 4cc7d8a38b50122f8e54c9c12d8d0d4fb5795fa0 Mon Sep 17 00:00:00 2001 From: Alexandre CASTELLANE Date: Wed, 22 Jan 2020 17:40:23 +0100 Subject: [PATCH 07/13] updated psl-devices (#49) Signed-off-by: Alexandre Castellane --- psl-devices | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/psl-devices b/psl-devices index 771a95d..fbef65a 100644 --- a/psl-devices +++ b/psl-devices @@ -1,21 +1,21 @@ 0x0000 Nallatech Altera 0x0001 Nallatech Altera 0x1001 Convey Xilinx -0x2001 AlphaData7v3 Xilinx 0x2000000 256 -0x2002 AlphaData7v3 Xilinx 0x2000000 256 +0x2001 AlphaData_AD7v3 Xilinx 0x2000000 256 +0x2002 AlphaData_AD7v3 Xilinx 0x2000000 256 0x3001 AlphaDataKU60 Xilinx 0x2000000 256 0x3003 AlphaDataKU60 Xilinx 0x2000000 256 -0x0604 AlphaData7v3 Xilinx 0x2000000 256 -0x0605 AlphaDataKU60 Xilinx 0x2000000 256 -0x0606 SemptianNSA121A Xilinx -0x0607 SemptianNSA121B Xilinx 0x4000000 256 -0x0664 SemptianNSA121B Xilinx 0x8000000 64 SPIx4 +0x0604 AlphaData_AD7v3 Xilinx 0x2000000 256 +0x0605 AlphaData_ADKU3 Xilinx 0x2000000 256 +0x0606 Semptian_NSA121A Xilinx +0x0607 Semptian_NSA121B Xilinx 0x4000000 256 +0x0664 Semptian_NSA121B Xilinx 0x8000000 64 SPIx4 0x0608 AlphaDataKU115 Xilinx 0x4000000 256 0x0609 BittwareVU095 Xilinx -0x060a NallatechKU60 Xilinx 0x2000000 256 -0x04dd NallatechN250SP Xilinx 0x4000000 256 -0x060d NallatechN250SP Xilinx 0x4000000 256 -0x060f AlphadataVU3P Xilinx 0x1000000 64 SPIx8 0x3000000 +0x060a Nallatech_N250S Xilinx 0x2000000 256 +0x04dd Nallatech_N250SP Xilinx 0x4000000 256 +0x060d Nallatech_N250SP Xilinx 0x4000000 256 +0x060f Alphadata_AD9V3 Xilinx 0x1000000 64 SPIx8 0x3000000 0x0660 SemptianNSA241 Xilinx 0x8000000 64 SPIx4 0x0661 FlysliceVU9P Xilinx 0x4000000 64 SPIx4 0x0665 U200 Xilinx 0x1002000 64 SPIx4 From acc7db467744d4ea2cad7952b67b763d39393706 Mon Sep 17 00:00:00 2001 From: Yong Lu Date: Mon, 10 Feb 2020 22:41:26 +0800 Subject: [PATCH 08/13] Update psl-devices --- psl-devices | 1 + 1 file changed, 1 insertion(+) diff --git a/psl-devices b/psl-devices index fbef65a..a094126 100644 --- a/psl-devices +++ b/psl-devices @@ -19,3 +19,4 @@ 0x0660 SemptianNSA241 Xilinx 0x8000000 64 SPIx4 0x0661 FlysliceVU9P Xilinx 0x4000000 64 SPIx4 0x0665 U200 Xilinx 0x1002000 64 SPIx4 +0x0669 U50 Xilinx 0x1002000 64 SPIx4 From e028e7c35047f87607b698d1471f6572892f81f4 Mon Sep 17 00:00:00 2001 From: Alexandre CASTELLANE Date: Tue, 25 Feb 2020 17:01:50 +0100 Subject: [PATCH 09/13] update psl-device with AD9H3 (#50) Signed-off-by: Alexandre Castellane --- psl-devices | 1 + 1 file changed, 1 insertion(+) diff --git a/psl-devices b/psl-devices index a094126..92a2816 100644 --- a/psl-devices +++ b/psl-devices @@ -16,6 +16,7 @@ 0x04dd Nallatech_N250SP Xilinx 0x4000000 256 0x060d Nallatech_N250SP Xilinx 0x4000000 256 0x060f Alphadata_AD9V3 Xilinx 0x1000000 64 SPIx8 0x3000000 +0x0667 Alphadata_AD9H3 Xilinx 0x1000000 64 SPIx8 0x3000000 0x0660 SemptianNSA241 Xilinx 0x8000000 64 SPIx4 0x0661 FlysliceVU9P Xilinx 0x4000000 64 SPIx4 0x0665 U200 Xilinx 0x1002000 64 SPIx4 From abf8150da2dc386d7549b2e1f229d2713cc5a56e Mon Sep 17 00:00:00 2001 From: Bruno MESNET Date: Mon, 9 Mar 2020 18:17:32 +0100 Subject: [PATCH 10/13] Display programming area --- capi-flash-script.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/capi-flash-script.sh b/capi-flash-script.sh index 1637b8e..a1eac54 100755 --- a/capi-flash-script.sh +++ b/capi-flash-script.sh @@ -208,6 +208,14 @@ fi # get flash address and block size if [ -z "$flash_address" ]; then flash_address=${flash_partition[$c]} + if [ $flash_address == "0x0000000" ]; then + printf "====================================================\n" + printf "${bold}== WARNING :${normal} YOU ARE PROGRAMMING IN FACTORY AREA! ==\n" + printf "====================================================\n" + else + printf "${bold}INFO :${normal} You are programming in USER area\n" + fi + fi if [ -z "$flash_block_size" ]; then flash_block_size=${flash_block[$c]} From 217f3b9016c79231134ce58de5d64ee3047d9bb9 Mon Sep 17 00:00:00 2001 From: Fabrice MOYEN Date: Thu, 30 Apr 2020 14:48:28 +0200 Subject: [PATCH 11/13] capi-flash-script.sh: OK to run if lock dir is older than system boot Signed-off-by: Fabrice MOYEN --- capi-flash-script.sh | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/capi-flash-script.sh b/capi-flash-script.sh index a1eac54..7daa969 100755 --- a/capi-flash-script.sh +++ b/capi-flash-script.sh @@ -110,15 +110,42 @@ if [ $capi_check -eq 0 ]; then exit 1 fi +LockDir=/var/cxl/capi-flash-script.lock + # make cxl dir if not present -mkdir -p /var/cxl/ +mkdir -p `dirname $LockDir` # mutual exclusion -if ! mkdir /var/cxl/capi-flash-script.lock 2>/dev/null; then - printf "${bold}ERROR:${normal} Another instance of this script is running\n" - exit 1 +if ! mkdir $LockDir 2>/dev/null; then + echo + printf "${bold}ERROR:${normal} Existing LOCK => Another instance of this script is maybe running\n" + + DateLastBoot=`who -b | awk '{print $3 " " $4}'` + EpochLastBoot=`date -d "$DateLastBoot" +%s` + + EpochLockDir=`stat --format=%Y $LockDir` + DateLockDir=`date --date @$EpochLockDir` + + echo + echo "Last BOOT: `date --date @$EpochLastBoot` ($EpochLastBoot)" + echo "Last LOCK modification: $DateLockDir ($EpochLockDir)" + + echo;echo "=======================================================" + if [ $EpochLockDir -lt $EpochLastBoot ]; then + echo "$LockDir modified BEFORE last boot" + echo "LOCK is not supposed to still be here" + echo " ==> Deleting and recreating $LockDir" + rmdir $LockDir + mkdir $LockDir + else + echo "$LockDir modified AFTER last boot" + printf "${bold}ERROR:${normal} Another instance of this script is running\n" + echo "Exiting..." + exit 1 + fi + fi -trap 'rm -rf "/var/cxl/capi-flash-script.lock"' 0 +trap 'rm -rf "$LockDir"' EXIT # get number of cards in system n=`ls -d /sys/class/cxl/card* | awk -F"/sys/class/cxl/card" '{ print $2 }' | wc -w` From c54cb67e7cb97d66edaae9820f9da2b1250a775e Mon Sep 17 00:00:00 2001 From: Alexandre CASTELLANE Date: Tue, 5 May 2020 17:19:45 +0200 Subject: [PATCH 12/13] update psldevices for 9H7 (#52) --- psl-devices | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/psl-devices b/psl-devices index 92a2816..279c2ee 100644 --- a/psl-devices +++ b/psl-devices @@ -1,23 +1,24 @@ 0x0000 Nallatech Altera 0x0001 Nallatech Altera 0x1001 Convey Xilinx -0x2001 AlphaData_AD7v3 Xilinx 0x2000000 256 -0x2002 AlphaData_AD7v3 Xilinx 0x2000000 256 -0x3001 AlphaDataKU60 Xilinx 0x2000000 256 -0x3003 AlphaDataKU60 Xilinx 0x2000000 256 -0x0604 AlphaData_AD7v3 Xilinx 0x2000000 256 -0x0605 AlphaData_ADKU3 Xilinx 0x2000000 256 +0x2001 AlphaData_AD7v3 Xilinx 0x02000000 256 +0x2002 AlphaData_AD7v3 Xilinx 0x02000000 256 +0x3001 AlphaDataKU60 Xilinx 0x02000000 256 +0x3003 AlphaDataKU60 Xilinx 0x02000000 256 +0x0604 AlphaData_AD7v3 Xilinx 0x02000000 256 +0x0605 AlphaData_ADKU3 Xilinx 0x02000000 256 0x0606 Semptian_NSA121A Xilinx -0x0607 Semptian_NSA121B Xilinx 0x4000000 256 -0x0664 Semptian_NSA121B Xilinx 0x8000000 64 SPIx4 -0x0608 AlphaDataKU115 Xilinx 0x4000000 256 +0x0607 Semptian_NSA121B Xilinx 0x04000000 256 +0x0664 Semptian_NSA121B Xilinx 0x08000000 64 SPIx4 +0x0608 AlphaDataKU115 Xilinx 0x04000000 256 0x0609 BittwareVU095 Xilinx -0x060a Nallatech_N250S Xilinx 0x2000000 256 -0x04dd Nallatech_N250SP Xilinx 0x4000000 256 -0x060d Nallatech_N250SP Xilinx 0x4000000 256 -0x060f Alphadata_AD9V3 Xilinx 0x1000000 64 SPIx8 0x3000000 -0x0667 Alphadata_AD9H3 Xilinx 0x1000000 64 SPIx8 0x3000000 -0x0660 SemptianNSA241 Xilinx 0x8000000 64 SPIx4 -0x0661 FlysliceVU9P Xilinx 0x4000000 64 SPIx4 -0x0665 U200 Xilinx 0x1002000 64 SPIx4 -0x0669 U50 Xilinx 0x1002000 64 SPIx4 +0x060a Nallatech_N250S Xilinx 0x02000000 256 +0x04dd Nallatech_N250SP Xilinx 0x04000000 256 +0x060d Nallatech_N250SP Xilinx 0x04000000 256 +0x060f Alphadata_AD9V3 Xilinx 0x01000000 64 SPIx8 0x03000000 +0x0667 Alphadata_AD9H3 Xilinx 0x01000000 64 SPIx8 0x03000000 +0x0668 Alphadata_AD9H7 Xilinx 0x04000000 64 SPIx8 0x84000000 +0x0660 SemptianNSA241 Xilinx 0x08000000 64 SPIx4 +0x0661 FlysliceVU9P Xilinx 0x04000000 64 SPIx4 +0x0665 U200 Xilinx 0x01002000 64 SPIx4 +0x0669 U50 Xilinx 0x01002000 64 SPIx4 From acf83aa509c6d628e524f3064a76442a8c56984b Mon Sep 17 00:00:00 2001 From: Bruno MESNET Date: Tue, 19 May 2020 16:41:17 +0200 Subject: [PATCH 13/13] Tune arg tests (#54) * better test arguments values * improve displayed message for user * add header and versionning * extend flash_address test * force reset to factory region if oc image * adding comments Signed-off-by: acastellane Co-authored-by: acastellane --- capi-flash-script.sh | 82 ++++++++++++++++++++++++++++++++++++-------- capi-reset.sh | 36 +++++++++++-------- 2 files changed, 88 insertions(+), 30 deletions(-) diff --git a/capi-flash-script.sh b/capi-flash-script.sh index 7daa969..c4658c9 100755 --- a/capi-flash-script.sh +++ b/capi-flash-script.sh @@ -16,11 +16,24 @@ # # Usage: sudo capi-flash-script.sh +tool_version=2.1 +# Changes History +# V2.0 code cleaning +# V2.1 add this header and tests oc_ or fw_ file names + # get capi-utils root [ -h $0 ] && package_root=`ls -l "$0" |sed -e 's|.*-> ||'` || package_root="$0" package_root=$(dirname $package_root) source $package_root/capi-utils-common.sh +printf "\n" +printf "==================================\n" +printf "== CAPI1.0/2.0 programming tool ==\n" +printf "==================================\n" +echo capi-flash_script version is $tool_version +printf "Tool compiled on: " +ls -l $package_root/capi-flash|cut -d ' ' -f '6-8' + force=0 program=`basename "$0"` card=-1 @@ -31,8 +44,6 @@ flash_block_size="" flash_type="" reset_factory=0 - - # Print usage message helper function function usage() { echo "Usage: sudo ${program} [OPTIONS]" @@ -227,7 +238,7 @@ elif [[ ${fpga_type[$c]} == "Xilinx" ]]; then printf "${bold}ERROR: ${normal}Wrong file extension: .bin must be used for boards with Xilinx FPGA\n" exit 0 fi -else +else printf "${bold}ERROR: ${normal}Card not listed in psl-devices or previous card failed or is not responding\n" exit 0 fi @@ -235,12 +246,44 @@ fi # get flash address and block size if [ -z "$flash_address" ]; then flash_address=${flash_partition[$c]} - if [ $flash_address == "0x0000000" ]; then - printf "====================================================\n" - printf "${bold}== WARNING :${normal} YOU ARE PROGRAMMING IN FACTORY AREA! ==\n" - printf "====================================================\n" + if [ $flash_address == "0x0000000" ] || [ $flash_address == "0x00000000" ]; then + if [[ $1 =~ "oc_" ]] + then + printf "===================================================================================\n" + echo "NOTE : You are in the process of programming an OPENCAPI image in FACTORY area!" + echo " A reboot or power cycle will be needed to re-enumerate the cards." + echo " Don't forget to sudo hange programming address to USER afterwards ( /lib/capi-utils/psl-devices)" + + printf "===================================================================================\n" + else + printf "========================================================================\n" + printf "${bold}== WARNING :${normal} YOU ARE IN THE PROCESS OF PROGRAMMING IN FACTORY AREA! \n" + printf "== If this is not intentional, sudo change programming address in /lib/capi-utils/psl-devices\n" + + printf "========================================================================\n" + fi else - printf "${bold}INFO :${normal} You are programming in USER area\n" + if [[ $1 =~ "oc_" ]] + then + printf "===================================================================================\n" + printf "WARNING: You are in the process of programming an OpenCAPI image in USER area! + Sudo change programming address in /lib/capi-utils/psl-devices if this is what you expect to do. + In order to achieve this, please change default CAPI2 User area to Factory area, +1) if card uses a single flash memory, just set single address to 0x00000000 +2) If card uses 2 SPI flash memories, you need to change primary address to 0x00000000 + while keeping the secondary flash selection bit active. + 2a) For AD9H7 cards and further coming cards using large memory range, + secondary selection bit is the Most significant bit of the 32bit address. + eg : 0x0668 Alphadata_AD9H7 Xilinx 0x04000000 64 SPIx8 0x84000000 # DEFAULT USER AREA + 0x0668 Alphadata_AD9H7 Xilinx 0x00000000 64 SPIx8 0x80000000 # FACTORY AREA + 2b) for other SPI8 cards the secondary selection bit is the Most significant + bit of the secondary address. + eg : 0x060f Alphadata_AD9V3 Xilinx 0x01000000 64 SPIx8 0x03000000 # DEFAULT USER AREA + 0x060f Alphadata_AD9V3 Xilinx 0x00000000 64 SPIx8 0x02000000 # FACTORY AREA\n" + printf "===================================================================================\n" + else + printf "${bold}INFO :${normal} You are programming in USER area\n" + fi fi fi @@ -257,7 +300,7 @@ fi # Deal with the second argument if [ $flash_type == "SPIx8" ]; then if [ $# -eq 1 ]; then - printf "${bold}ERROR:${normal} Input argument missing. The seleted device is SPIx8 and needs both primary and secondary bin files\n" + printf "${bold}ERROR:${normal} Input argument missing. The selected device is SPIx8 and needs both primary and secondary bin files\n" usage exit 1 fi @@ -280,11 +323,11 @@ fi if (($force != 1)); then # prompt to confirm while true; do - printf "Will flash ${bold}card$c${normal} with ${bold}$1${normal}" + printf "Will flash ${bold}card$c${normal} with: \n\t${bold}$1${normal}" if [ $flash_type == "SPIx8" ]; then - printf "and ${bold}$2${normal}" + printf "\nand \t${bold}$2${normal}\n" fi - read -p ". Do you want to continue? [y/n] " yn + read -p "Do you want to continue? [y/n] " yn case $yn in [Yy]* ) break;; [Nn]* ) exit;; @@ -294,7 +337,7 @@ if (($force != 1)); then else printf "Continue to flash ${bold}$1${normal} "; if [ $flash_type == "SPIx8" ]; then - printf "and ${bold}$2${normal} " + printf "and ${bold}$2${normal} " fi printf "to ${bold}card$c${normal}\n" fi @@ -313,7 +356,7 @@ if [ ! -x $package_root/capi-flash ]; then exit 1 fi -# Reset to card/flash registers to known state (factory) +# Reset to card/flash registers to known state (factory) if [ "$reset_factory" -eq 1 ]; then reset_card $c factory "Preparing card for flashing" fi @@ -334,5 +377,14 @@ wait $PID RC=$? if [ $RC -eq 0 ]; then # reset card only if Flashing was good - reset_card $c user + if [[ $1 =~ "oc_" ]] + then + # reset card only if Flashing was good + # reset to factory if programming an oc image + echo "Resetting card to factory area" + reset_card $c factory + else + # reset card only if Flashing was good + reset_card $c user + fi fi diff --git a/capi-reset.sh b/capi-reset.sh index fd6377b..96cc426 100755 --- a/capi-reset.sh +++ b/capi-reset.sh @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # +isnumber='^[0-9]+$' # get capi-utils root [ -h $0 ] && package_root=`ls -l "$0" |sed -e 's|.*-> ||'` || package_root="$0" @@ -33,28 +34,33 @@ function confirm { } if [ -n "$1" ]; then - # get number of cards in system - n=`ls -d /sys/class/cxl/card* | awk -F"/sys/class/cxl/card" '{ print $2 }' | wc -w` - card=$((10#$1)) - if (($card < 0 )) || (( "$card" > "$n" )); then - printf "${bold}ERROR:${normal} Wrong card number ${card}\n" - exit 1 - fi + # get number of cards in system + n=`ls -d /sys/class/cxl/card* | awk -F"/sys/class/cxl/card" '{ print $2 }' | wc -w` + if ! [[ $1 =~ $isnumber ]] ; then + echo "error: 1rst argument is not a number. usage: capi-reset 0 user" >&2; exit 1 + fi + card=$((10#$1)) + if (($card < 0 )) || (( "$card" > "$n-1" )); then + printf "${bold}ERROR:${normal} Wrong card number ${card}\n" + exit 1 + fi if [ -n "$2" ]; then region=$2; if [[ "$region" != "factory" && "$region" != "user" ]]; then - printf "${bold}ERROR:${normal} Only supports \"factory\" or \"user\".\n" - exit 1 - fi + printf "${bold}ERROR:${normal} Only supports \"factory\" or \"user\".\n" + exit 1 + fi reset_card $card $region "Resetting CAPI Adapter $card" else reset_card $card factory "Resetting CAPI Adapter $card" + #printf "Bad argument\n" + # exit 1 fi else confirm - #Find all the CAPI cards in the system - cardnums=`ls -d /sys/class/cxl/card* | awk -F"/sys/class/cxl/card" '{ print $2 }'` - for i in $cardnums; do - reset_card $i factory "Resetting CAPI Adapter $i" - done + #Find all the CAPI cards in the system + cardnums=`ls -d /sys/class/cxl/card* | awk -F"/sys/class/cxl/card" '{ print $2 }'` + for i in $cardnums; do + reset_card $i factory "Resetting CAPI Adapter $i" + done fi