xbflash.qspi: Add tool from Xilinx to flash cards (it is a nightmare to...
This commit is contained in:
+34
-38
@@ -2,8 +2,8 @@
|
||||
|
||||
To deploy Jungfraujoch, one needs to follow four steps:
|
||||
|
||||
1. Flash the U55C FPGA card with a proper image and install Linux kernel driver
|
||||
2. Install main Jungfraujoch code and frontend web interface
|
||||
1. Install main Jungfraujoch code and frontend web interface
|
||||
2. Flash the U55C FPGA card with a proper image and install Linux kernel driver
|
||||
3. Install Jungfraujoch writer
|
||||
4. Install Python OpenAPI client
|
||||
|
||||
@@ -11,21 +11,38 @@ Installation procedure depend a lot on the operating system. For RedHat Enterpri
|
||||
installation can be done with prebuilt RPMs and is relatively straightforward. For other systems one needs to build
|
||||
software from source. Both ways will be presented.
|
||||
|
||||
## Install main Jungfraujoch code and frontend web interface
|
||||
|
||||
On RHEL 8 systems there is a `jfjoch-<version>-1.el8.x86_64.rpm` that needs to be installed and contains all the necessary software and web interface.
|
||||
|
||||
On other OSes one needs to compile Jungfraujoch from source (from the repo directory):
|
||||
```
|
||||
$ mkdir build
|
||||
$ cd build
|
||||
$ cmake .. -DCMAKE_INSTALL_PREFIX=<directory to install>
|
||||
$ make
|
||||
$ sudo make install
|
||||
```
|
||||
For manual installation, we recommend to use non-standard directory (like `/opt/jfjoch`), to facilitate upgrades and removal.
|
||||
|
||||
Frontend web user interface has to be built separately with:
|
||||
```
|
||||
$ cd build
|
||||
$ make frontend
|
||||
```
|
||||
Frontend files (.html and .js) will be placed in `frontend/dist` (outside of `build/` directory!) and has to be copied to a general location, e.g. `/usr/local/jfjoch/frontend` or `/opt/jfjoch/frotend`.
|
||||
|
||||
## Flash the U55C FPGA card with a proper image and install Linux kernel driver.
|
||||
|
||||
|
||||
### Firmware flashing
|
||||
1. Install the `xbflash2` tool from Xilinx, which allows to flash the firmware through PCIe connector.
|
||||
|
||||
It can be downloaded as RPM/DEB file from [Alveo product page](https://www.xilinx.com/products/boards-and-kits/alveo/u55c.html#xbflash2). For RHEL9 this needs to built from source - [Xilinx/XRT github repository](https://github.com/Xilinx/XRT).
|
||||
|
||||
2. Check that the card is detected by OS with "lspci |grep Xilinx" and check the PCIe slot number (`11:00.0` in this case):
|
||||
1. Check that the card is detected by OS with "lspci |grep Xilinx" and check the PCIe bus/device/function (BDF) number, `11:00.0` in this case:
|
||||
```
|
||||
$ lspci |grep Xilinx
|
||||
23:00.0 Processing accelerators: Xilinx Corporation Device 3450 (rev 58)
|
||||
23:00.0 Processing accelerators: Xilinx Corporation Device 3450 (rev 2)
|
||||
```
|
||||
Note the device number `3450` that identifies Jungfraujoch device (Jungfraujoch pass is 3450 m above sea level) and `rev 58` identifying release of the firmware.
|
||||
3. Check the speed of the card, that it is detected as PCIe Gen4x8 device (needs to be done as root, otherwise configuration details are not given):
|
||||
Note the device number `3450` that identifies Jungfraujoch device (Jungfraujoch pass is 3450 m above sea level) and `rev 2` identifying release of the firmware.
|
||||
|
||||
2. Check the speed of the card, that it is detected as PCIe Gen4x8 device (needs to be done as root, otherwise configuration details are not given):
|
||||
```
|
||||
$ sudo lspci -vv -s <PCIe slot number>
|
||||
23:00.0 Processing accelerators: Xilinx Corporation Device 3450
|
||||
@@ -34,20 +51,20 @@ LnkSta: Speed 16GT/s (ok), Width x8 (ok)
|
||||
(...)
|
||||
```
|
||||
|
||||
4. Download the MCS image from release files or build it using Vivado (WARNING! building time can be about 8 hours and doesn't allways reach correct timing).
|
||||
5. Flash the card with xbflash2. For fresh card use:
|
||||
3. Download the MCS image from release files or build it using Vivado (WARNING! building time can be about 8 hours and doesn't allways reach correct timing).
|
||||
4. Flash the card with `xbflash.qspi` tool (part of Jungfraujoch). For fresh card use:
|
||||
```
|
||||
sudo xbflash2 program --spi --image <path to MCS file> --bar-offset 0x1f06000 -d <PCIe slot from above>
|
||||
sudo xbflash.qspi --primary <path to MCS file> --card <PCIe slot from above> --bar-offset 0x1f06000
|
||||
```
|
||||
For card that was already flashed with Jungfraujoch images:
|
||||
|
||||
```
|
||||
sudo xbflash2 program --spi --image <path to MCS file> -d <PCIe slot from above>
|
||||
sudo xbflash.qspi --primary <path to MCS file> --card <PCIe slot from above>
|
||||
```
|
||||
It is necessary to confirm the operation by pressing `Y` key.
|
||||
It is necessary to confirm the operation by pressing `Y` key or one can add `--force` option to avoid confirmation.
|
||||
It is safe to run multiple flashing processes in parallel for different cards, for example in separate screen sessions.
|
||||
|
||||
6. Cold reboot:
|
||||
5. Cold reboot:
|
||||
```
|
||||
sudo ipmitool chassis power cycle
|
||||
```
|
||||
@@ -82,27 +99,6 @@ $ sudo dracut -f
|
||||
Configure switch according to [FPGA network guide](fpga/NETWORK.md) - specifically set manual speed and turn off auto-negotiation
|
||||
for the port used to connect U55C card and connect card to switch.
|
||||
|
||||
## Install main Jungfraujoch code and frontend web interface
|
||||
|
||||
On RHEL 8 systems there is a `jfjoch-<version>-1.el8.x86_64.rpm` that needs to be installed and contains all the necessary software and web interface.
|
||||
|
||||
On other OSes one needs to compile Jungfraujoch from source (from the repo directory):
|
||||
```
|
||||
$ mkdir build
|
||||
$ cd build
|
||||
$ cmake .. -DCMAKE_INSTALL_PREFIX=<directory to install>
|
||||
$ make
|
||||
$ sudo make install
|
||||
```
|
||||
For manual installation, we recommend to use non-standard directory (like `/opt/jfjoch`), to facilitate upgrades and removal.
|
||||
|
||||
Frontend web user interface has to be built separately with:
|
||||
```
|
||||
$ cd build
|
||||
$ make frontend
|
||||
```
|
||||
Frontend files (.html and .js) will be placed in `frontend/dist` (outside of `build/` directory!) and has to be copied to a general location, e.g. `/usr/local/jfjoch/frontend` or `/opt/jfjoch/frotend`.
|
||||
|
||||
### Running Jungfraujoch software
|
||||
Main Jungfraujoch service is called `jfjoch_broker`. It is responsible for handling data from FPGAs, doing processing, analysis, compression and sending images on ZeroMQ output.
|
||||
It is recommended to run the service as `systemd` service.
|
||||
|
||||
@@ -8,11 +8,12 @@ INSTALL(TARGETS jfjoch_pcie_status RUNTIME COMPONENT jfjoch)
|
||||
|
||||
ADD_EXECUTABLE(jfjoch_pcie_net_cfg jfjoch_pcie_net_cfg.cpp)
|
||||
TARGET_LINK_LIBRARIES(jfjoch_pcie_net_cfg JFJochDevice )
|
||||
INSTALL(TARGETS jfjoch_pcie_net_cfg RUNTIME)
|
||||
INSTALL(TARGETS jfjoch_pcie_net_cfg RUNTIME COMPONENT jfjoch )
|
||||
|
||||
ADD_EXECUTABLE(jfjoch_pcie_clear_net_counters jfjoch_pcie_clear_net_counters.cpp)
|
||||
TARGET_LINK_LIBRARIES(jfjoch_pcie_clear_net_counters JFJochDevice )
|
||||
INSTALL(TARGETS jfjoch_pcie_clear_net_counters RUNTIME)
|
||||
INSTALL(TARGETS jfjoch_pcie_clear_net_counters RUNTIME COMPONENT jfjoch )
|
||||
|
||||
# Clock cfg test is not too important to be installed as part of Jungfraujoch
|
||||
ADD_EXECUTABLE(jfjoch_pcie_clock_cfg_test jfjoch_pcie_clock_cfg_test.cpp)
|
||||
TARGET_LINK_LIBRARIES(jfjoch_pcie_clock_cfg_test JFJochDevice )
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#
|
||||
|
||||
export PACKAGE_VERSION_SEM=`head -n1 VERSION`
|
||||
export FPGA_VERSION="1.0.0-rc.14"
|
||||
export FPGA_VERSION="1.0.0-rc.16"
|
||||
export PACKAGE_VERSION=${PACKAGE_VERSION_SEM//-/_}
|
||||
export PACKAGE_VERSION_PYTHON=${PACKAGE_VERSION_SEM//-rc./rc}
|
||||
export PACKAGE_VERSION_PYTHON=${PACKAGE_VERSION_PYTHON//-alpha./a}
|
||||
@@ -23,12 +23,12 @@ curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file jfjoch_frontend.tar.gz "$
|
||||
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file jfjoch-client-${PACKAGE_VERSION_PYTHON}.tar.gz "${PACKAGE_REGISTRY_URL}/jfjoch-client-${PACKAGE_VERSION_PYTHON}.tar.gz"
|
||||
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file jfjoch_client-${PACKAGE_VERSION_PYTHON}-py3-none-any.whl "${PACKAGE_REGISTRY_URL}/jfjoch_client-${PACKAGE_VERSION_PYTHON}-py3-none-any.whl"
|
||||
|
||||
release-cli create --name "Release $PACKAGE_VERSION_SEM" --tag-name $PACKAGE_VERSION_SEM
|
||||
--assets-link "{\"name\":\"jfjoch_frontend.tar.gz\",\"url\":\"${PACKAGE_REGISTRY_URL}/jfjoch_frontend.tar.gz\"}"
|
||||
--assets-link "{\"name\":\"jfjoch_fpga_pcie_8x10g.mcs\",\"url\":\"${FPGA_REGISTRY_URL}/jfjoch_fpga_pcie_8x10g.mcs\"}"
|
||||
--assets-link "{\"name\":\"jfjoch_fpga_pcie_100g.mcs\",\"url\":\"${FPGA_REGISTRY_URL}/jfjoch_fpga_pcie_100g.mcs\"}"
|
||||
--assets-link "{\"name\":\"jfjoch-${PACKAGE_VERSION}-1.el8.x86_64.rpm\",\"url\":\"${PACKAGE_REGISTRY_URL}/jfjoch-${PACKAGE_VERSION}-1.el8.x86_64.rpm\",\"link_type\":\"package\"}"
|
||||
--assets-link "{\"name\":\"jfjoch-writer-${PACKAGE_VERSION}-1.el8.x86_64.rpm\",\"url\":\"${PACKAGE_REGISTRY_URL}/jfjoch-writer-${PACKAGE_VERSION}-1.el8.x86_64.rpm\",\"link_type\":\"package\"}"
|
||||
--assets-link "{\"name\":\"jfjoch-driver-dkms-${PACKAGE_VERSION}-1.el8.noarch.rpm\",\"url\":\"${PACKAGE_REGISTRY_URL}/jfjoch-driver-dkms-${PACKAGE_VERSION}-1.el8.noarch.rpm\",\"link_type\":\"package\"}"
|
||||
--assets-link "{\"name\":\"jfjoch_client-${PACKAGE_VERSION_PYTHON}-py3-none-any.whl\",\"url\":\"${PACKAGE_REGISTRY_URL}/jfjoch_client-${PACKAGE_VERSION_PYTHON}-py3-none-any.whl\",\"link_type\":\"package\"}"
|
||||
release-cli create --name "Release $PACKAGE_VERSION_SEM" --tag-name $PACKAGE_VERSION_SEM \
|
||||
--assets-link "{\"name\":\"jfjoch_frontend.tar.gz\",\"url\":\"${PACKAGE_REGISTRY_URL}/jfjoch_frontend.tar.gz\"}" \
|
||||
--assets-link "{\"name\":\"jfjoch_fpga_pcie_8x10g.mcs\",\"url\":\"${FPGA_REGISTRY_URL}/jfjoch_fpga_pcie_8x10g.mcs\"}" \
|
||||
--assets-link "{\"name\":\"jfjoch_fpga_pcie_100g.mcs\",\"url\":\"${FPGA_REGISTRY_URL}/jfjoch_fpga_pcie_100g.mcs\"}" \
|
||||
--assets-link "{\"name\":\"jfjoch-${PACKAGE_VERSION}-1.el8.x86_64.rpm\",\"url\":\"${PACKAGE_REGISTRY_URL}/jfjoch-${PACKAGE_VERSION}-1.el8.x86_64.rpm\",\"link_type\":\"package\"}" \
|
||||
--assets-link "{\"name\":\"jfjoch-writer-${PACKAGE_VERSION}-1.el8.x86_64.rpm\",\"url\":\"${PACKAGE_REGISTRY_URL}/jfjoch-writer-${PACKAGE_VERSION}-1.el8.x86_64.rpm\",\"link_type\":\"package\"}" \
|
||||
--assets-link "{\"name\":\"jfjoch-driver-dkms-${PACKAGE_VERSION}-1.el8.noarch.rpm\",\"url\":\"${PACKAGE_REGISTRY_URL}/jfjoch-driver-dkms-${PACKAGE_VERSION}-1.el8.noarch.rpm\",\"link_type\":\"package\"}" \
|
||||
--assets-link "{\"name\":\"jfjoch_client-${PACKAGE_VERSION_PYTHON}-py3-none-any.whl\",\"url\":\"${PACKAGE_REGISTRY_URL}/jfjoch_client-${PACKAGE_VERSION_PYTHON}-py3-none-any.whl\",\"link_type\":\"package\"}" \
|
||||
--assets-link "{\"name\":\"jfjoch-client-${PACKAGE_VERSION_PYTHON}.tar.gz\",\"url\":\"${PACKAGE_REGISTRY_URL}/jfjoch-client-${PACKAGE_VERSION_PYTHON}.tar.gz\",\"link_type\":\"package\"}"
|
||||
|
||||
@@ -24,3 +24,5 @@ ADD_EXECUTABLE(AzimIntDataset AzimIntDataset.cpp)
|
||||
TARGET_LINK_LIBRARIES(AzimIntDataset JFJochImageAnalysis JFJochWriter JFJochCommon)
|
||||
|
||||
INSTALL(TARGETS jfjoch_udp_simulator HDF5DatasetWriteTest jfjoch_writer_test AzimIntDataset RUNTIME)
|
||||
|
||||
ADD_SUBDIRECTORY(xbflash.qspi)
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright (C) 2019-2021 Xilinx, Inc. All rights reserved.
|
||||
#
|
||||
|
||||
add_executable(xbflash.qspi
|
||||
firmware_image.cpp
|
||||
firmware_image.h
|
||||
main.cpp
|
||||
pcidev.cpp
|
||||
pcidev.h
|
||||
xqspips.cpp
|
||||
xqspips.h
|
||||
xspi.cpp
|
||||
xspi.h)
|
||||
|
||||
INSTALL(TARGETS xbflash.qspi RUNTIME COMPONENT jfjoch )
|
||||
@@ -0,0 +1,517 @@
|
||||
All userspace code authored by Xilinx or Advanced Micro Devices is
|
||||
released under the following license:
|
||||
|
||||
Copyright (C) 2016-2022 Xilinx, Inc
|
||||
Copyright (C) 2022-2023 Advanced Micro Devices, Inc
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"). You may
|
||||
not use this file except in compliance with the License. A copy of the
|
||||
License is located at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
License for the specific language governing permissions and limitations
|
||||
under the License.
|
||||
|
||||
All Linux kernel driver code included in "xocl" or "xclmgmt" authored by
|
||||
Xilinx is released under the terms of GNU General Public License version 2:
|
||||
|
||||
Copyright (C) 2016-2022 Xilinx, Inc. All rights reserved.
|
||||
Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
This software is licensed under the terms of the GNU General Public
|
||||
License version 2, as published by the Free Software Foundation, and
|
||||
may be copied, distributed, and modified under those terms.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
|
||||
All Linux kernel driver code included in "zocl" authored by Xilinx is
|
||||
released under the terms of either Apache License, Version 2.0,
|
||||
or alternatively under the terms of the GNU General Public License
|
||||
version 2:
|
||||
|
||||
Copyright (C) 2016-2020 Xilinx, Inc. All rights reserved.
|
||||
Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
This software is licensed under the terms of the GNU General Public
|
||||
License version 2, as published by the Free Software Foundation, and
|
||||
may be copied, distributed, and modified under those terms.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You may use the Linux kernel driver code according to either of these
|
||||
licenses as is most appropriate for your project on a case-by-case basis.
|
||||
|
||||
The full text for both licenses is included for reference below.
|
||||
|
||||
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
@@ -0,0 +1,16 @@
|
||||
# xbflash.qspi
|
||||
|
||||
This program allows to flash firmware of Xilinx/AMD FPGA cards via PCIe edge and QSPI core.
|
||||
This tool is taken from the Xilinx/AMD [XRT repository](https://githb.com/Xilinx/XRT) and extracted for convenience, since the original repository has
|
||||
an extreme number of dependencies.
|
||||
|
||||
Note: Xilinx has two tools `xbflash.qspi` and `xbflash2`.
|
||||
The latter is only repackaging of the original code with extra Boost libraries for nice options parsing.
|
||||
Thus, we decided not to only take the original program, to not increase number of dependencies of the code.
|
||||
|
||||
## Usage
|
||||
`xbflash.qspi` has to be run as root.
|
||||
|
||||
```
|
||||
xbflash.qspi --primary <name of image> --card <PCIe id of the card>
|
||||
```
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (C) 2020-2021 Xilinx, Inc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"). You may
|
||||
* not use this file except in compliance with the License. A copy of the
|
||||
* License is located at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <fstream>
|
||||
#include "firmware_image.h"
|
||||
|
||||
firmwareImage::firmwareImage(const char *file) :
|
||||
mBuf(nullptr)
|
||||
{
|
||||
std::ifstream in(file, std::ios::binary | std::ios::ate);
|
||||
if (!in.is_open())
|
||||
{
|
||||
this->setstate(failbit);
|
||||
std::cout << "Can't open " << file << std::endl;
|
||||
return;
|
||||
}
|
||||
auto bufsize = in.tellg();
|
||||
in.seekg(0);
|
||||
|
||||
// For non-dsabin file, the entire file is the image.
|
||||
mBuf = new char[bufsize];
|
||||
in.seekg(0);
|
||||
in.read(mBuf, bufsize);
|
||||
this->rdbuf()->pubsetbuf(mBuf, bufsize);
|
||||
}
|
||||
|
||||
firmwareImage::~firmwareImage()
|
||||
{
|
||||
delete[] mBuf;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (C) 2018 Xilinx, Inc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"). You may
|
||||
* not use this file except in compliance with the License. A copy of the
|
||||
* License is located at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Contains definitions for all firmware (DSA/BMC) related classes
|
||||
*/
|
||||
|
||||
#ifndef _FIRMWARE_IMAGE_H_
|
||||
#define _FIRMWARE_IMAGE_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
class firmwareImage : public std::istringstream
|
||||
{
|
||||
public:
|
||||
firmwareImage(const char *file);
|
||||
~firmwareImage();
|
||||
|
||||
private:
|
||||
char *mBuf;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,565 @@
|
||||
/**
|
||||
* Copyright (C) 2020 Xilinx, Inc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"). You may
|
||||
* not use this file except in compliance with the License. A copy of the
|
||||
* License is located at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
//
|
||||
// This utility is implemented by porting flash code from xbmgmt. Since that
|
||||
// it's used only by non-XRT users, we do not expect to maintain and enhance
|
||||
// this code a lot in the future. Hence, no cleanup effort is ever attempted
|
||||
// while porting the code from xbmgmt at this point.
|
||||
// If it works, don't change it.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <sys/types.h>
|
||||
#include <getopt.h>
|
||||
#include <libgen.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "pcidev.h"
|
||||
#include "xspi.h"
|
||||
#include "xqspips.h"
|
||||
#include "firmware_image.h"
|
||||
|
||||
const option flash_opts[] = {
|
||||
// Key option to identify flash operation, must be 0
|
||||
{ "primary", required_argument, nullptr, '0' },
|
||||
|
||||
{ "force", no_argument, nullptr, '1' },
|
||||
{ "card", required_argument, nullptr, '2' },
|
||||
{ "secondary", required_argument, nullptr, '3' },
|
||||
{ "bar", required_argument, nullptr, '4' },
|
||||
{ "bar-offset", required_argument, nullptr, '5' },
|
||||
{ nullptr, 0, nullptr, 0 },
|
||||
};
|
||||
|
||||
const option reset_opts[] = {
|
||||
// Key option to identify reset operation, must be 0
|
||||
{ "factory-reset", no_argument, nullptr, '0' },
|
||||
|
||||
{ "force", no_argument, nullptr, '1' },
|
||||
{ "card", required_argument, nullptr, '2' },
|
||||
{ "dual-flash", no_argument, nullptr, '3' },
|
||||
{ "bar", required_argument, nullptr, '4' },
|
||||
{ "bar-offset", required_argument, nullptr, '5' },
|
||||
{ nullptr, 0, nullptr, 0 },
|
||||
};
|
||||
|
||||
const option qspips_erase_opts[] = {
|
||||
// Key option to identify flash operation, must be 0
|
||||
{ "qspips-erase", no_argument, nullptr, '0' },
|
||||
|
||||
{ "card", required_argument, nullptr, '1' },
|
||||
{ "offset", required_argument, nullptr, '2' },
|
||||
{ "length", required_argument, nullptr, '3' },
|
||||
{ "flash-type", required_argument, nullptr, '4' },
|
||||
{ "bar", required_argument, nullptr, '5' },
|
||||
{ "bar-offset", required_argument, nullptr, '6' },
|
||||
{ "force", no_argument, nullptr, '7' },
|
||||
{ nullptr, 0, nullptr, 0 },
|
||||
};
|
||||
|
||||
const option qspips_flash_opts[] = {
|
||||
// Key option to identify flash operation, must be 0
|
||||
{ "qspips-flash", no_argument, nullptr, '0' },
|
||||
|
||||
{ "card", required_argument, nullptr, '1' },
|
||||
{ "input", required_argument, nullptr, '2' },
|
||||
{ "offset", required_argument, nullptr, '3' },
|
||||
{ "flash-type", required_argument, nullptr, '4' },
|
||||
{ "bar", required_argument, nullptr, '5' },
|
||||
{ "bar-offset", required_argument, nullptr, '6' },
|
||||
{ "force", no_argument, nullptr, '7' },
|
||||
{ nullptr, 0, nullptr, 0 },
|
||||
};
|
||||
|
||||
const option qspips_readback_opts[] = {
|
||||
// Key option to identify flash operation, must be 0
|
||||
{ "qspips-read", no_argument, nullptr, '0' },
|
||||
|
||||
{ "card", required_argument, nullptr, '1' },
|
||||
{ "output", required_argument, nullptr, '2' },
|
||||
{ "offset", required_argument, nullptr, '3' },
|
||||
{ "length", required_argument, nullptr, '4' },
|
||||
{ "flash-type", required_argument, nullptr, '5' },
|
||||
{ "bar", required_argument, nullptr, '6' },
|
||||
{ "bar-offset", required_argument, nullptr, '7' },
|
||||
{ nullptr, 0, nullptr, 0 },
|
||||
};
|
||||
|
||||
static const char *option_key(const option *opts)
|
||||
{
|
||||
while (opts->name != nullptr) {
|
||||
if (opts->val == '0')
|
||||
return opts->name;
|
||||
opts++;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static bool is_op(const option *opts, int argc, char *argv[])
|
||||
{
|
||||
const char *key = option_key(opts);
|
||||
std::string optkey = "--";
|
||||
|
||||
if (key == nullptr)
|
||||
return false;
|
||||
|
||||
optkey += key;
|
||||
for (int i = 0; i < argc; i++) {
|
||||
if (optkey.compare(argv[i]) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void sudoOrDie()
|
||||
{
|
||||
const char* SudoMessage = "ERROR: root privileges required.";
|
||||
if ((getuid() == 0) || (geteuid() == 0))
|
||||
return;
|
||||
std::cout << SudoMessage << std::endl;
|
||||
exit(-EPERM);
|
||||
}
|
||||
|
||||
static bool canProceed()
|
||||
{
|
||||
std::string input;
|
||||
bool answered = false;
|
||||
bool proceed = false;
|
||||
|
||||
while (!answered) {
|
||||
std::cout << "Are you sure you wish to proceed? [y/n]: ";
|
||||
std::cin >> input;
|
||||
answered = (input.compare("y") == 0 || input.compare("n") == 0);
|
||||
}
|
||||
|
||||
proceed = (input.compare("y") == 0);
|
||||
if (!proceed)
|
||||
std::cout << "Action canceled." << std::endl;
|
||||
return proceed;
|
||||
}
|
||||
|
||||
static void printHelp(const char *fname)
|
||||
{
|
||||
auto tmp = std::unique_ptr<char, decltype(std::free)*>{strdup(fname), std::free};
|
||||
|
||||
std::cout << "Usage: " << std::endl;
|
||||
|
||||
std::cout << basename(tmp.get()) << " [options]" << std::endl;
|
||||
std::cout << "\nOptions:" << std::endl;
|
||||
|
||||
std::cout << "\n\"SPI flash\"\n";
|
||||
std::cout << " --primary, <MCS-path>, must be 1st option\n";
|
||||
std::cout << " [--secondary <MCS-path>], default is empty\n";
|
||||
std::cout << " --card <BDF>\n";
|
||||
std::cout << " [--force, yes for prompt]\n";
|
||||
std::cout << " [--bar <BAR-index-for-QSPI>], default is 0\n";
|
||||
std::cout << " [--bar-offset <BAR-offset-for-QSPI>], default is 0x40000\n";
|
||||
|
||||
std::cout << "\n\"SPI factory-reset\"\n";
|
||||
std::cout << " --factory-reset, must be 1st option\n";
|
||||
std::cout << " [--dual-flash]\n";
|
||||
std::cout << " --card <BDF>\n";
|
||||
std::cout << " [--force, yes for prompt]\n";
|
||||
std::cout << " [--bar <BAR-index-for-QSPI>], default is 0\n";
|
||||
std::cout << " [--bar-offset <BAR-offset-for-QSPI>], default is 0x40000\n";
|
||||
|
||||
std::cout << "\n\"QSPIPS erase\"\n";
|
||||
std::cout << " --qspips-erase, must be 1st option\n";
|
||||
std::cout << " --card <BDF>\n";
|
||||
std::cout << " [--offset <offset-on-flash-to-start-with>], default is 0\n";
|
||||
std::cout << " [--length <length-to-read>], default is 96MB\n";
|
||||
std::cout << " [--flash-type <qspips-flash-type>], default is qspi_ps_x2_single\n";
|
||||
std::cout << " [--bar <BAR-index-for-QSPIPS>], default is 0\n";
|
||||
std::cout << " [--bar-offset <BAR-offset-for-QSPIPS>], default is 0x40000\n";
|
||||
std::cout << " [--force, yes for prompt]\n";
|
||||
|
||||
std::cout << "\n\"QSPIPS flash\"\n";
|
||||
std::cout << " --qspips-flash, must be 1st option\n";
|
||||
std::cout << " --input <path-to-qspips-BOOT-BIN-file>\n";
|
||||
std::cout << " --card <BDF>\n";
|
||||
std::cout << " [--offset <offset-on-flash-to-start-with>], default is 0\n";
|
||||
std::cout << " [--flash-type <qspips-flash-type>], default is qspi_ps_x2_single\n";
|
||||
std::cout << " [--bar <BAR-index-for-QSPIPS>], default is 0\n";
|
||||
std::cout << " [--bar-offset <BAR-offset-for-QSPIPS>], default is 0x40000\n";
|
||||
std::cout << " [--force, yes for prompt]\n";
|
||||
|
||||
std::cout << "\n\"QSPIPS read back\"\n";
|
||||
std::cout << " --qspips-read, must be 1st option\n";
|
||||
std::cout << " --output <output-file-to-save-read-contents>\n";
|
||||
std::cout << " --card <BDF>\n";
|
||||
std::cout << " [--offset <offset-on-flash-to-start-with>], default is 0\n";
|
||||
std::cout << " [--length <length-to-read>], default is 128MB\n";
|
||||
std::cout << " [--flash-type <qspips-flash-type>], default is qspi_ps_x2_single\n";
|
||||
std::cout << " [--bar <BAR-index-for-QSPIPS>], default is 0\n";
|
||||
std::cout << " [--bar-offset <BAR-offset-for-QSPIPS>], default is 0x40000\n";
|
||||
}
|
||||
|
||||
int reset(int argc, char *argv[])
|
||||
{
|
||||
bool force = false;
|
||||
std::string bdf;
|
||||
const char *fname = argv[0];
|
||||
int bar = 0;
|
||||
size_t baroff = INVALID_OFFSET;
|
||||
bool dualflash = false;
|
||||
|
||||
sudoOrDie();
|
||||
|
||||
while (true) {
|
||||
const auto opt = getopt_long(argc, argv, "", reset_opts, nullptr);
|
||||
if (opt == -1)
|
||||
break;
|
||||
|
||||
switch (opt) {
|
||||
case '2':
|
||||
bdf = std::string(optarg);
|
||||
break;
|
||||
case '1':
|
||||
force = true;
|
||||
break;
|
||||
case '0':
|
||||
break;
|
||||
case '3':
|
||||
dualflash = true;
|
||||
break;
|
||||
case '4':
|
||||
bar = std::stoi(optarg, nullptr, 0);
|
||||
break;
|
||||
case '5':
|
||||
baroff = std::stoi(optarg, nullptr, 0);
|
||||
break;
|
||||
default:
|
||||
printHelp(fname);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
if (bdf.empty()) {
|
||||
printHelp(fname);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
std::cout
|
||||
<< "About to revert to golden image for card " << bdf << std::endl;
|
||||
|
||||
if (!force && !canProceed())
|
||||
return -ECANCELED;
|
||||
|
||||
pcidev::pci_device dev(bdf, bar, baroff);
|
||||
XSPI_Flasher xspi(&dev, dualflash);
|
||||
return xspi.revertToMFG();
|
||||
}
|
||||
|
||||
int flash(int argc, char *argv[])
|
||||
{
|
||||
int ret = 0;
|
||||
bool force = false;
|
||||
std::string primary_file;
|
||||
std::string secondary_file;
|
||||
std::string bdf;
|
||||
const char *fname = argv[0];
|
||||
int bar = 0;
|
||||
size_t baroff = INVALID_OFFSET;
|
||||
|
||||
sudoOrDie();
|
||||
|
||||
while (true) {
|
||||
const auto opt = getopt_long(argc, argv, "", flash_opts, nullptr);
|
||||
if (opt == -1)
|
||||
break;
|
||||
|
||||
switch (opt) {
|
||||
case '2':
|
||||
bdf = std::string(optarg);
|
||||
break;
|
||||
case '1':
|
||||
force = true;
|
||||
break;
|
||||
case '0':
|
||||
primary_file = std::string(optarg);
|
||||
break;
|
||||
case '3':
|
||||
secondary_file = std::string(optarg);
|
||||
break;
|
||||
case '4':
|
||||
bar = std::stoi(optarg);
|
||||
break;
|
||||
case '5':
|
||||
baroff = std::stoi(optarg, nullptr, 0);
|
||||
break;
|
||||
default:
|
||||
printHelp(fname);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
if (bdf.empty() || primary_file.empty()) {
|
||||
printHelp(fname);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
std::cout
|
||||
<< "About to flash below MCS bitstream onto card "
|
||||
<< bdf << ":" << std::endl;
|
||||
std::cout << primary_file << std::endl;
|
||||
if (!secondary_file.empty())
|
||||
std::cout << secondary_file << std::endl;
|
||||
|
||||
if (!force && !canProceed())
|
||||
return -ECANCELED;
|
||||
|
||||
pcidev::pci_device dev(bdf, bar, baroff);
|
||||
XSPI_Flasher xspi(&dev, !secondary_file.empty());
|
||||
|
||||
if (secondary_file.empty()) {
|
||||
firmwareImage pri(primary_file.c_str());
|
||||
if (pri.fail())
|
||||
return -EINVAL;
|
||||
ret = xspi.xclUpgradeFirmware1(pri);
|
||||
} else {
|
||||
firmwareImage pri(primary_file.c_str());
|
||||
firmwareImage sec(secondary_file.c_str());
|
||||
if (pri.fail() || sec.fail())
|
||||
return -EINVAL;
|
||||
ret = xspi.xclUpgradeFirmware2(pri, sec);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int qspips_erase(int argc, char *argv[])
|
||||
{
|
||||
std::string bdf;
|
||||
const char *fname = argv[0];
|
||||
int bar = 0;
|
||||
size_t baroff = INVALID_OFFSET;
|
||||
std::string flash_type;
|
||||
size_t offset = 0, len = GOLDEN_BASE;
|
||||
bool force = false;
|
||||
|
||||
sudoOrDie();
|
||||
|
||||
while (true) {
|
||||
const auto opt = getopt_long(argc, argv, "", qspips_erase_opts, nullptr);
|
||||
if (opt == -1)
|
||||
break;
|
||||
|
||||
switch (opt) {
|
||||
case '0':
|
||||
break;
|
||||
case '1':
|
||||
bdf = std::string(optarg);
|
||||
break;
|
||||
case '2':
|
||||
offset = std::stoi(optarg, nullptr, 0);
|
||||
break;
|
||||
case '3':
|
||||
len = std::stoi(optarg, nullptr, 0);
|
||||
break;
|
||||
case '4':
|
||||
flash_type = std::string(optarg);
|
||||
break;
|
||||
case '5':
|
||||
bar = std::stoi(optarg);
|
||||
break;
|
||||
case '6':
|
||||
baroff = std::stoi(optarg, nullptr, 0);
|
||||
break;
|
||||
case '7':
|
||||
force = true;
|
||||
break;
|
||||
default:
|
||||
printHelp(fname);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
if (bdf.empty()) {
|
||||
printHelp(fname);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
std::cout << "About to erase flash"
|
||||
<< " [0x" << std::hex << offset << ",0x" << offset+len
|
||||
<< "] on card " << bdf << std::endl;
|
||||
|
||||
if (offset + len > GOLDEN_BASE)
|
||||
std::cout << "\nThis might erase golden image if there is !!\n" << std::endl;
|
||||
|
||||
if (!force && !canProceed())
|
||||
return -ECANCELED;
|
||||
|
||||
pcidev::pci_device dev(bdf, bar, baroff, flash_type);
|
||||
XQSPIPS_Flasher qspips(&dev);
|
||||
|
||||
return qspips.xclErase(offset, len);
|
||||
}
|
||||
|
||||
int qspips_flash(int argc, char *argv[])
|
||||
{
|
||||
std::string bdf;
|
||||
const char *fname = argv[0];
|
||||
int bar = 0;
|
||||
size_t baroff = INVALID_OFFSET;
|
||||
size_t offset = 0;
|
||||
std::string flash_type;
|
||||
std::string bin_file;
|
||||
bool force = false;
|
||||
|
||||
sudoOrDie();
|
||||
|
||||
while (true) {
|
||||
const auto opt = getopt_long(argc, argv, "", qspips_flash_opts, nullptr);
|
||||
if (opt == -1)
|
||||
break;
|
||||
|
||||
switch (opt) {
|
||||
case '0':
|
||||
break;
|
||||
case '1':
|
||||
bdf = std::string(optarg);
|
||||
break;
|
||||
case '2':
|
||||
bin_file = std::string(optarg);
|
||||
break;
|
||||
case '3':
|
||||
offset = std::stoi(optarg, nullptr, 0);
|
||||
break;
|
||||
case '4':
|
||||
flash_type = std::string(optarg);
|
||||
break;
|
||||
case '5':
|
||||
bar = std::stoi(optarg);
|
||||
break;
|
||||
case '6':
|
||||
baroff = std::stoi(optarg, nullptr, 0);
|
||||
break;
|
||||
case '7':
|
||||
force = true;
|
||||
break;
|
||||
default:
|
||||
printHelp(fname);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
if (bdf.empty() || bin_file.empty()) {
|
||||
printHelp(fname);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
firmwareImage bin(bin_file.c_str());
|
||||
if (bin.fail())
|
||||
return -EINVAL;
|
||||
std::cout
|
||||
<< "About to program flash on card " << bdf << " at offset 0x" << std::hex << offset << std::dec << std::endl;
|
||||
|
||||
if (!force && !canProceed())
|
||||
return -ECANCELED;
|
||||
|
||||
pcidev::pci_device dev(bdf, bar, baroff, flash_type);
|
||||
XQSPIPS_Flasher qspips(&dev);
|
||||
|
||||
return qspips.xclUpgradeFirmware(bin, offset);
|
||||
}
|
||||
|
||||
int qspips_readback(int argc, char *argv[])
|
||||
{
|
||||
std::string bdf;
|
||||
const char *fname = argv[0];
|
||||
int bar = 0;
|
||||
size_t baroff = INVALID_OFFSET;
|
||||
size_t offset = 0, len = FLASH_SIZE;
|
||||
std::string flash_type;
|
||||
std::string output;
|
||||
|
||||
sudoOrDie();
|
||||
|
||||
while (true) {
|
||||
const auto opt = getopt_long(argc, argv, "", qspips_readback_opts, nullptr);
|
||||
if (opt == -1)
|
||||
break;
|
||||
|
||||
switch (opt) {
|
||||
case '0':
|
||||
break;
|
||||
case '1':
|
||||
bdf = std::string(optarg);
|
||||
break;
|
||||
case '2':
|
||||
output = std::string(optarg);
|
||||
break;
|
||||
case '3':
|
||||
offset = std::stoi(optarg, nullptr, 0);
|
||||
break;
|
||||
case '4':
|
||||
len = std::stoi(optarg, nullptr, 0);
|
||||
break;
|
||||
case '5':
|
||||
flash_type = std::string(optarg);
|
||||
break;
|
||||
case '6':
|
||||
bar = std::stoi(optarg);
|
||||
break;
|
||||
case '7':
|
||||
baroff = std::stoi(optarg, nullptr, 0);
|
||||
break;
|
||||
default:
|
||||
printHelp(fname);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
if (bdf.empty() || output.empty()) {
|
||||
printHelp(fname);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
std::cout << "Read out flash"
|
||||
<< " [0x" << std::hex << offset << ",0x" << offset+len
|
||||
<< "] on card " << bdf << " to " << output << std::dec << std::endl;
|
||||
|
||||
pcidev::pci_device dev(bdf, bar, baroff, flash_type);
|
||||
XQSPIPS_Flasher qspips(&dev);
|
||||
|
||||
return qspips.xclReadBack(output, offset, len);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
try {
|
||||
if (is_op(reset_opts, argc, argv))
|
||||
return reset(argc, argv);
|
||||
|
||||
if (is_op(flash_opts, argc, argv))
|
||||
return flash(argc, argv);
|
||||
|
||||
if (is_op(qspips_erase_opts, argc, argv))
|
||||
return qspips_erase(argc, argv);
|
||||
|
||||
if (is_op(qspips_flash_opts, argc, argv))
|
||||
return qspips_flash(argc, argv);
|
||||
|
||||
if (is_op(qspips_readback_opts, argc, argv))
|
||||
return qspips_readback(argc, argv);
|
||||
|
||||
} catch (const std::exception& ex) {
|
||||
std::cout << "Failed to flash: " << ex.what() << std::endl;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
printHelp(argv[0]);
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
/**
|
||||
* Copyright (C) 2020 Xilinx, Inc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"). You may
|
||||
* not use this file except in compliance with the License. A copy of the
|
||||
* License is located at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
#include <mutex>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/file.h>
|
||||
#include <linux/pci.h>
|
||||
#include "pcidev.h"
|
||||
|
||||
namespace pcidev {
|
||||
|
||||
/*
|
||||
* wordcopy()
|
||||
*
|
||||
* Copy bytes word (32bit) by word.
|
||||
* Neither memcpy, nor std::copy work as they become byte copying
|
||||
* on some platforms.
|
||||
*/
|
||||
inline void*
|
||||
wordcopy(void *dst, const void* src, size_t bytes)
|
||||
{
|
||||
// assert dest is 4 byte aligned
|
||||
assert((reinterpret_cast<intptr_t>(dst) % 4) == 0);
|
||||
|
||||
using word = uint32_t;
|
||||
volatile auto d = reinterpret_cast<word*>(dst);
|
||||
auto s = reinterpret_cast<const word*>(src);
|
||||
auto w = bytes/sizeof(word);
|
||||
|
||||
for (size_t i=0; i<w; ++i)
|
||||
d[i] = s[i];
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
int
|
||||
pci_device::
|
||||
open(const std::string& subdev, int flag)
|
||||
{
|
||||
int fd = -1;
|
||||
|
||||
// Open legacy subdevice node
|
||||
std::string file("/dev/xfpga/");
|
||||
file += subdev;
|
||||
file += ".m";
|
||||
file += std::to_string((uint32_t)(domain<<16) + (bus<<8) + (dev<<3) + func);
|
||||
file += "." + std::to_string(0);
|
||||
fd = ::open(file.c_str(), flag);
|
||||
if (fd >= 0) {
|
||||
std::cout << "Successfully opened " << file << std::endl;
|
||||
return fd;
|
||||
}
|
||||
|
||||
// Open xoclv2 subdevice node
|
||||
char bdf[20];
|
||||
std::snprintf(bdf, sizeof(bdf), "%04x:%02x:%02x.%x", domain, bus, dev, func);
|
||||
file = "/dev/xfpga/";
|
||||
file += subdev;
|
||||
file += ".";
|
||||
file += bdf;
|
||||
fd = ::open(file.c_str(), flag);
|
||||
if (fd >= 0) {
|
||||
std::cout << "Successfully opened " << file << std::endl;
|
||||
return fd;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
pci_device::
|
||||
pci_device(const std::string& sysfs, int ubar, size_t flash_off, std::string flash_type)
|
||||
: user_bar_index(ubar), flash_offset(flash_off), flash_type_str(flash_type)
|
||||
{
|
||||
|
||||
uint32_t pcmd = 0;
|
||||
char sysfsname[20] = {0};
|
||||
uint16_t dom = 0, b, d, f;
|
||||
if (sscanf(sysfs.c_str(), "%hx:%hx.%hx", &b, &d, &f) < 3 &&
|
||||
sscanf(sysfs.c_str(), "%hx:%hx:%hx.%hx", &dom, &b, &d, &f) < 4)
|
||||
throw std::runtime_error("Couldn't parse entry name " + sysfs);
|
||||
|
||||
domain = dom;
|
||||
bus = b;
|
||||
dev = d;
|
||||
func = f;
|
||||
user_bar_size = 0;
|
||||
|
||||
std::snprintf(sysfsname, sizeof(sysfsname), "%04x:%02x:%02x.%x",
|
||||
domain, bus, dev, func);
|
||||
std::string conffile("/sys/bus/pci/devices/");
|
||||
conffile += sysfsname;
|
||||
conffile += "/config";
|
||||
|
||||
int conf_handle = ::open(conffile.c_str(), O_RDWR | O_SYNC);
|
||||
if (conf_handle < 0) {
|
||||
throw std::runtime_error("Failed to open " + conffile);
|
||||
}
|
||||
|
||||
if(lseek(conf_handle, 4, SEEK_SET) != 4)
|
||||
throw std::runtime_error("Failed to set file pointer for " + conffile);
|
||||
|
||||
if(::read(conf_handle, &pcmd, 4) < 0)
|
||||
throw std::runtime_error("Failed to read " + conffile);
|
||||
|
||||
pcmd = pcmd | PCI_COMMAND_MEMORY;
|
||||
|
||||
if(lseek(conf_handle, 4, SEEK_SET) != 4)
|
||||
throw std::runtime_error("Failed to set file pointer for " + conffile);
|
||||
|
||||
if(::write(conf_handle, &pcmd, 4) < 0)
|
||||
throw std::runtime_error("Failed to write " + conffile);
|
||||
|
||||
close(conf_handle);
|
||||
}
|
||||
|
||||
pci_device::
|
||||
~pci_device()
|
||||
{
|
||||
if (user_bar_map != MAP_FAILED)
|
||||
::munmap(user_bar_map, user_bar_size);
|
||||
}
|
||||
|
||||
int
|
||||
pci_device::
|
||||
map_usr_bar()
|
||||
{
|
||||
std::lock_guard<std::mutex> l(lock);
|
||||
|
||||
if (user_bar_map != MAP_FAILED)
|
||||
return 0;
|
||||
|
||||
char sysfsname[20];
|
||||
std::snprintf(sysfsname, sizeof(sysfsname), "%04x:%02x:%02x.%x",
|
||||
domain, bus, dev, func);
|
||||
std::string resfile("/sys/bus/pci/devices/");
|
||||
resfile += sysfsname;
|
||||
resfile += "/resource";
|
||||
resfile += std::to_string(user_bar_index);
|
||||
int dev_handle = ::open(resfile.c_str(), O_RDWR | O_SYNC);
|
||||
if (dev_handle < 0) {
|
||||
int err = errno;
|
||||
std::cout << "Failed to open " << resfile << " : "
|
||||
<< strerror(err) << std::endl;
|
||||
return -err;
|
||||
}
|
||||
|
||||
struct stat sb;
|
||||
if (fstat(dev_handle, &sb) == -1) { // To obtain file size
|
||||
int err = errno;
|
||||
std::cout << "Failed to stat " << resfile << ": "
|
||||
<< strerror(err) << std::endl;
|
||||
(void) close(dev_handle);
|
||||
return -err;
|
||||
}
|
||||
user_bar_size = sb.st_size;
|
||||
|
||||
user_bar_map = (char *)::mmap(0, user_bar_size, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED, dev_handle, 0);
|
||||
|
||||
// Mapping should stay valid after handle is closed
|
||||
// (according to man page)
|
||||
(void)close(dev_handle);
|
||||
|
||||
if (user_bar_map == MAP_FAILED) {
|
||||
int err = errno;
|
||||
std::cout << "Failed to map " << resfile << ": "
|
||||
<< strerror(err) << std::endl;
|
||||
return -err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
pci_device::
|
||||
close(int dev_handle)
|
||||
{
|
||||
if (dev_handle != -1)
|
||||
(void)::close(dev_handle);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
pci_device::
|
||||
pcieBarRead(uint64_t offset, void* buf, uint64_t len)
|
||||
{
|
||||
if (user_bar_map == MAP_FAILED) {
|
||||
int ret = map_usr_bar();
|
||||
if (ret) {
|
||||
std::cout << "Failed to map in PCIE BAR. Does the card specified exist?" << std::endl;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
(void) wordcopy(buf, user_bar_map + offset, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pci_device::
|
||||
pcieBarWrite(uint64_t offset, const void* buf, uint64_t len)
|
||||
{
|
||||
if (user_bar_map == MAP_FAILED) {
|
||||
int ret = map_usr_bar();
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
(void) wordcopy(user_bar_map + offset, buf, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace pcidev
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* Copyright (C) 2020 Xilinx, Inc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"). You may
|
||||
* not use this file except in compliance with the License. A copy of the
|
||||
* License is located at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
#ifndef _PCIDEV_H_
|
||||
#define _PCIDEV_H_
|
||||
|
||||
#include <string>
|
||||
#include <sys/mman.h>
|
||||
#include <mutex>
|
||||
|
||||
#define INVALID_ID ((uint16_t)-1)
|
||||
|
||||
namespace pcidev {
|
||||
|
||||
// One PCIE function on FPGA board
|
||||
class pci_device
|
||||
{
|
||||
public:
|
||||
pci_device(const std::string& sysfs, int ubar, size_t flash_off, std::string flash_type = "");
|
||||
~pci_device();
|
||||
int pcieBarRead(uint64_t offset, void *buf, uint64_t len);
|
||||
int pcieBarWrite(uint64_t offset, const void *buf, uint64_t len);
|
||||
int open(const std::string& subdev, int flag);
|
||||
void close(int devhdl);
|
||||
size_t get_flash_offset() { return flash_offset; }
|
||||
int get_flash_bar_index() { return user_bar_index; }
|
||||
std::string get_flash_type() { return flash_type_str; };
|
||||
|
||||
private:
|
||||
uint16_t domain = INVALID_ID;
|
||||
uint16_t bus = INVALID_ID;
|
||||
uint16_t dev = INVALID_ID;
|
||||
uint16_t func = INVALID_ID;
|
||||
|
||||
int map_usr_bar(void);
|
||||
std::mutex lock;
|
||||
char *user_bar_map = reinterpret_cast<char *>(MAP_FAILED);
|
||||
int user_bar_index;
|
||||
size_t user_bar_size;
|
||||
size_t flash_offset;
|
||||
std::string flash_type_str;
|
||||
};
|
||||
|
||||
} // namespace pcidev
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* Copyright (C) 2016-2018 Xilinx, Inc
|
||||
* Author(s) : Min Ma
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"). You may
|
||||
* not use this file except in compliance with the License. A copy of the
|
||||
* License is located at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#ifndef _XQSPIPS_H_
|
||||
#define _XQSPIPS_H_
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include "pcidev.h"
|
||||
|
||||
#define PAGE_SIZE 256
|
||||
#define PAGE_8K 8192
|
||||
#define GOLDEN_BASE 0x06000000
|
||||
#define FLASH_SIZE 0x08000000
|
||||
#define INVALID_OFFSET ((size_t)-1)
|
||||
|
||||
class XQSPIPS_Flasher
|
||||
{
|
||||
struct ELARecord
|
||||
{
|
||||
unsigned mStartAddress;
|
||||
unsigned mEndAddress;
|
||||
unsigned mDataCount;
|
||||
std::streampos mDataPos;
|
||||
ELARecord() : mStartAddress(0), mEndAddress(0), mDataCount(0), mDataPos(0) {}
|
||||
};
|
||||
|
||||
typedef std::list<ELARecord> ELARecordList;
|
||||
ELARecordList mRecordList;
|
||||
|
||||
public:
|
||||
XQSPIPS_Flasher(pcidev::pci_device *dev);
|
||||
~XQSPIPS_Flasher();
|
||||
void program(std::istream& binStream, unsigned base = 0);
|
||||
int verify(std::istream& binStream, unsigned base = 0, bool quiet = false);
|
||||
int revertToMFG(std::istream& binStream);
|
||||
int xclUpgradeFirmware(std::istream& binStream, unsigned offset = 0);
|
||||
int xclErase(unsigned offset = 0, unsigned total_size = GOLDEN_BASE);
|
||||
int xclReadBack(std::string output, unsigned base = 0, unsigned total_size = FLASH_SIZE);
|
||||
|
||||
private:
|
||||
typedef struct {
|
||||
uint8_t *bufPtr;
|
||||
uint32_t byteCount;
|
||||
uint32_t busWidth;
|
||||
uint32_t flags;
|
||||
} xqspips_msg_t;
|
||||
|
||||
pcidev::pci_device *mDev;
|
||||
uint8_t mWriteBuffer[PAGE_8K];
|
||||
uint8_t mReadBuffer[PAGE_8K];
|
||||
uint32_t mTxBytes;
|
||||
uint32_t mRxBytes;
|
||||
uint64_t flash_base;
|
||||
|
||||
/* QSPI configure */
|
||||
uint32_t mConnectMode; //Single, Stacked and Parallel mode
|
||||
uint32_t mBusWidth; // x1, x2, x4
|
||||
|
||||
void clearReadBuffer(unsigned size);
|
||||
void clearWriteBuffer(unsigned size);
|
||||
void clearBuffers(unsigned size);
|
||||
|
||||
/* Flash functions */
|
||||
int xclTestXQSpiPS(int device_index);
|
||||
bool getFlashID();
|
||||
bool isFlashReady();
|
||||
bool readFlashReg(unsigned commandCode, unsigned bytes);
|
||||
bool writeFlashReg(unsigned commandCode, unsigned value, unsigned bytes);
|
||||
bool eraseSector(unsigned addr, uint32_t byteCount, uint8_t eraseCmd = 0xff);
|
||||
bool eraseBulk();
|
||||
bool readFlash(unsigned addr, uint32_t byteCount, uint8_t readCmd = 0xff);
|
||||
bool writeFlash(unsigned addr, uint32_t byteCount, uint8_t writeCmd = 0xff);
|
||||
|
||||
/* PS QSPI functions */
|
||||
void initQSpiPS();
|
||||
void abortQSpiPS();
|
||||
void resetQSpiPS();
|
||||
bool waitGenFifoEmpty();
|
||||
bool waitTxEmpty();
|
||||
int writeReg(unsigned regOffset, unsigned value);
|
||||
bool enterOrExitFourBytesMode(uint32_t enable);
|
||||
uint32_t readReg(unsigned RegOffset);
|
||||
uint32_t selectSpiMode(uint8_t SpiMode);
|
||||
bool setWriteEnable();
|
||||
void readRxFifo(xqspips_msg_t *msg, int32_t Size);
|
||||
void fillTxFifo(xqspips_msg_t *msg, int32_t Size);
|
||||
void setupTXRX(xqspips_msg_t *msg, uint32_t *GenFifoEntry);
|
||||
void sendGenFifoEntryCSAssert();
|
||||
void sendGenFifoEntryData(xqspips_msg_t *msg);
|
||||
void sendGenFifoEntryCSDeAssert();
|
||||
bool finalTransfer(xqspips_msg_t *msg, uint32_t numMsg);
|
||||
};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Copyright (C) 2020 Xilinx, Inc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"). You may
|
||||
* not use this file except in compliance with the License. A copy of the
|
||||
* License is located at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
#ifndef _XSPI_H_
|
||||
#define _XSPI_H_
|
||||
|
||||
#include <list>
|
||||
#include "pcidev.h"
|
||||
|
||||
#define INVALID_OFFSET ((size_t)-1)
|
||||
|
||||
class XSPI_Flasher
|
||||
{
|
||||
struct ELARecord
|
||||
{
|
||||
unsigned mStartAddress;
|
||||
unsigned mEndAddress;
|
||||
unsigned mDataCount;
|
||||
std::streampos mDataPos;
|
||||
ELARecord() : mStartAddress(0), mEndAddress(0), mDataCount(0), mDataPos(0) {}
|
||||
};
|
||||
|
||||
typedef std::list<ELARecord> ELARecordList;
|
||||
ELARecordList recordList;
|
||||
|
||||
public:
|
||||
XSPI_Flasher(pcidev::pci_device *dev, bool dualQSPI);
|
||||
~XSPI_Flasher();
|
||||
int xclUpgradeFirmware1(std::istream& mcsStream1);
|
||||
int xclUpgradeFirmware2(std::istream& mcsStream1, std::istream& mcsStream2);
|
||||
int revertToMFG(void);
|
||||
|
||||
private:
|
||||
pcidev::pci_device *mDev;
|
||||
std::FILE *mFlashDev = nullptr;
|
||||
bool mDualQSPI;
|
||||
|
||||
int parseMCS(std::istream& mcsStream);
|
||||
|
||||
size_t flash_base;
|
||||
int xclTestXSpi(int device_index);
|
||||
unsigned readReg(unsigned offset);
|
||||
int writeReg(unsigned regOffset, unsigned value);
|
||||
bool waitTxEmpty();
|
||||
int macronixConfigure();
|
||||
bool isFlashReady();
|
||||
bool sectorErase(unsigned Addr, unsigned erase_cmd);
|
||||
bool writeBitstreamGuard(unsigned Addr);
|
||||
bool clearBitstreamGuard(unsigned Addr);
|
||||
bool bulkErase();
|
||||
bool writeEnable();
|
||||
bool getFlashId();
|
||||
bool finalTransfer(uint8_t *sendBufPtr, uint8_t *recvBufPtr, int byteCount);
|
||||
bool writePage(unsigned addr, uint8_t writeCmd = 0xff);
|
||||
bool readPage(unsigned addr, uint8_t readCmd = 0xff);
|
||||
bool prepareXSpi(uint8_t slave_sel);
|
||||
int programRecord(std::istream& mcsStream, const ELARecord& record);
|
||||
int programXSpi(std::istream& mcsStream, uint32_t bitstream_shift_addr);
|
||||
bool readRegister(unsigned commandCode, unsigned bytes);
|
||||
bool writeRegister(unsigned commandCode, unsigned value, unsigned bytes);
|
||||
bool setSector(unsigned address);
|
||||
unsigned getSector(unsigned address);
|
||||
|
||||
// Upgrade firmware via driver.
|
||||
int upgradeFirmware1Drv(std::istream& mcsStream1);
|
||||
int upgradeFirmware2Drv(std::istream& mcsStream1, std::istream& mcsStream2);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user