Skip to content

Commit

Permalink
Support SPIx4 and SPIx8 (#39)
Browse files Browse the repository at this point in the history
* Update NSA121B user address
* Allow capi-reset.sh to reset user region
* Adding code for SPIx4 and SPIx8, prepare for CAPI2.0
* add FX609
* Update README.md: change bit to bin file

Signed-off-by: Lu Yong <luyong@cn.ibm.com>

* Update print format for writing/reading flash blocks

Signed-off-by: Kenneth Hill <khill@us.ibm.com>
  • Loading branch information
luyong6 authored and kenhill committed Jun 26, 2018
1 parent 0e88aac commit 8293833
Show file tree
Hide file tree
Showing 5 changed files with 354 additions and 188 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Uninstall: `sudo make uninstall`

# capi-flash-script

Usage: `sudo capi-flash-script <path-to-bit-file>`
Usage: `sudo capi-flash-script <path-to-bin-file>`

This script can be used to flash a specific card in a system with one or more CAPI cards installed.

Expand Down
77 changes: 60 additions & 17 deletions capi-flash-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Usage: sudo capi-flash-script.sh <path-to-bit-file>
# Usage: sudo capi-flash-script.sh <path-to-bin-file>

# get capi-utils root
[ -h $0 ] && package_root=`ls -l "$0" |sed -e 's|.*-> ||'` || package_root="$0"
Expand All @@ -26,7 +26,9 @@ program=`basename "$0"`
card=-1

flash_address=""
flash_address2=""
flash_block_size=""
flash_type=""

reset_factory=0

Expand All @@ -40,7 +42,8 @@ function usage() {
echo " [-r] Reset adapter to factory before writing to flash."
echo " [-V] Print program version (${version})"
echo " [-h] Print this help message."
echo " <path-to-bit-file>"
echo " <path-to-bin-file>"
echo " <path-to-secondary-bin-file> (Only for SPIx8 device)"
echo
echo "Utility to flash/write bitstreams to CAPI FPGA cards."
echo "Please ensure that you are using the right bitstream data."
Expand Down Expand Up @@ -132,7 +135,7 @@ done
printf "\n${bold}Current date:${normal}\n$(date)\n\n"

# print table header
printf "${bold}%-7s %-30s %-29s %-20s %s${normal}\n" "#" "Card" "Flashed" "by" "Image"
printf "${bold}%-7s %-30s %-29s %-20s %s${normal}\n" "#" "Card" "Flashed" "by" "Last Image"

# print card information and flash history
i=0;
Expand All @@ -150,6 +153,8 @@ while read d; do
fpga_type[$i]=${parse_info[2]}
flash_partition[$i]=${parse_info[3]}
flash_block[$i]=${parse_info[4]}
flash_interface[$i]=${parse_info[5]}
flash_secondary[$i]=${parse_info[6]}
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"
Expand Down Expand Up @@ -209,27 +214,66 @@ fi
if [ -z "$flash_block_size" ]; then
flash_block_size=${flash_block[$c]}
fi
if [ -z "$flash_type" ]; then
flash_type=${flash_interface[$c]}
fi
if [ -z "$flash_type" ]; then
flash_type="BPIx16" #If it is not listed in psl-device file, use default value
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"
usage
exit 1
fi
#Check the second file
if [[ ! -e $2 ]]; then
printf "${bold}ERROR:${normal} $2 not found\n"
usage
exit 1
fi
#Assign secondary address
flash_address2=${flash_secondary[$c]}
if [ -z "$flash_address2" ]; then
printf "${bold}ERROR:${normal} The second address must be assigned in file psl-device\n"
exit 1
fi
fi


# card is set via parameter since it is positive
if (($force != 1)); then
# prompt to confirm
while true; do
read -p "Do you want to continue to flash ${bold}$1${normal} to ${bold}card$c${normal}? [y/n] " yn
printf "Will flash ${bold}card$c${normal} with ${bold}$1${normal}"
if [ $flash_type == "SPIx8" ]; then
printf "and ${bold}$2${normal}"
fi
read -p ". Do you want to continue? [y/n] " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) printf "${bold}ERROR:${normal} Please answer with y or n\n";;
esac
done
else
printf "Continue to flash ${bold}$1${normal} to ${bold}card$c${normal}\n"
printf "Continue to flash ${bold}$1${normal} ";
if [ $flash_type == "SPIx8" ]; then
printf "and ${bold}$2${normal} "
fi
printf "to ${bold}card$c${normal}\n"
fi

printf "\n"

# update flash history file
printf "%-29s %-20s %s\n" "$(date)" "$(logname)" $1 > /var/cxl/card$c

if [ $flash_type == "SPIx8" ]; then
printf "%-29s %-20s %s %s\n" "$(date)" "$(logname)" $1 $2 > /var/cxl/card$c
else
printf "%-29s %-20s %s\n" "$(date)" "$(logname)" $1 > /var/cxl/card$c
fi
# Check if lowlevel flash utility is existing and executable
if [ ! -x $package_root/capi-flash ]; then
printf "${bold}ERROR:${normal} Utility capi-flash not found!\n"
Expand All @@ -243,20 +287,19 @@ fi

trap 'kill -TERM $PID; perst_factory $c' TERM INT
# flash card with corresponding binary
$package_root/capi-flash --file $1 --card $c --address $flash_address --blocksize $flash_block_size &
if [ $flash_type == "SPIx8" ]; then
# SPIx8 needs two file inputs (primary/secondary)
$package_root/capi-flash --type $flash_type --file $1 --file2 $2 --card $c --address $flash_address --address2 $flash_address2 --blocksize $flash_block_size &
else
$package_root/capi-flash --type $flash_type --file $1 --card $c --address $flash_address --blocksize $flash_block_size &
fi

PID=$!
wait $PID
trap - TERM INT
wait $PID
RC=$?
if [ $RC -eq 0 ]; then
# reset card only if Flashing was good
reset_card $c user
# reset card only if Flashing was good
reset_card $c user
fi

# remind afu to use in host application
# Y.Lu: This is not needed for SNAP. The DEVICE may not be in dedicated mode. Comment off.

# printf "\nMake sure to use ${bold}/dev/cxl/afu$c.0d${normal} in your host application;\n\n"
# printf "#define DEVICE \"/dev/cxl/afu$c.0d\"\n"
# printf "struct cxl_afu_h *afu = cxl_afu_open_dev ((char*) (DEVICE));\n\n"
15 changes: 11 additions & 4 deletions include/capi_flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#define FLASH_PROG_STATUS (1 << 14)
#define FLASH_READ_STATUS (1 << 13)
#define FLASH_PORT_READY (1 << 12)
#define FLASH_RDATA_VALID (1 << 11)
#define FLASH_DATA_OFFSET 0x5C
#define FLASH_CHECK_BIT(X,Y,Z) (((X) & (Y)) == (Z))
// Flash error codes
Expand All @@ -77,9 +78,15 @@
#define FLASH_ERR_CFG_WRITE 100
#define FLASH_ERR_CFG_READ 200

#define FLASH_READ_SIZE 0x200 /* 512 Words */
#define DEFAULT_USER_FLASH_ADDRESS 0x02000000
#define DEFAULT_BLOCK_SIZE 256
#define DEFAULT_CAPI_CARD 0
#define FLASH_READ_SIZE 0x200 /* 512 Words */
#define DEFAULT_USER_FLASH_ADDRESS 0x02000000

#define DEFAULT_FACTORY_FLASH_ADDRESS_PRI 0x0
#define DEFAULT_FACTORY_FLASH_ADDRESS_SEC 0x02000000
#define DEFAULT_USER_FLASH_ADDRESS_PRI 0x01000000
#define DEFAULT_USER_FLASH_ADDRESS_SEC 0x03000000

#define DEFAULT_BLOCK_SIZE 256
#define DEFAULT_CAPI_CARD 0

#endif
3 changes: 3 additions & 0 deletions psl-devices
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
0x0605 AlphaDataKU60 Xilinx 0x2000000 256
0x0606 SemptianNSA121A Xilinx
0x0607 SemptianNSA121B Xilinx 0x4000000 256
0x0664 SemptianNSA121B 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
0x0661 FlysliceVU9P Xilinx 0x4000000 64 SPIx4
Loading

0 comments on commit 8293833

Please sign in to comment.