forked from Xilinx/PYNQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·243 lines (210 loc) · 9.95 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# Copyright (c) 2016, Xilinx, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
__author__ = "Giuseppe Natale, Yun Rock Qu"
__copyright__ = "Copyright 2016, Xilinx"
__email__ = "[email protected]"
from setuptools import setup, Extension, find_packages
import shutil
import subprocess
import sys
import os
import site
import stat
import warnings
from datetime import datetime
''' Board specific package delivery setup '''
if 'BOARD' not in os.environ:
print("Please set the BOARD environment variable to get any BOARD specific overlays (e.g. Pynq-Z1).")
board = None
board_folder = None
pynq_data_files = None
else:
board = os.environ['BOARD']
board_folder = 'boards/{}/'.format(board)
pynq_data_files = [(os.path.join('{}/pynq/overlays'.format(site.getsitepackages()[0]), root.replace(board_folder, '')),
[os.path.join(root, f) for f in files]) for root, dirs, files in os.walk(board_folder)]
# Pynq Family Constants
ZYNQ_ARCH = "armv7l"
CPU_ARCH = os.uname().machine
CPU_ARCH_IS_SUPPORTED = CPU_ARCH in [ZYNQ_ARCH]
''' Notebook Delivery '''
default_nb_dir = '/home/xilinx/jupyter_notebooks'
if 'PYNQ_JUPYTER_NOTEBOOKS' in os.environ:
notebooks_dir = os.environ['PYNQ_JUPYTER_NOTEBOOKS']
elif os.path.exists(default_nb_dir):
notebooks_dir = default_nb_dir
else:
notebooks_dir = None
if notebooks_dir is not None:
notebooks_getting_started_dir = os.path.join(notebooks_dir, 'getting_started')
notebooks_getting_started_dst_img_dir = os.path.join(notebooks_getting_started_dir, 'images')
notebooks_getting_started_src_dir = os.path.join('docs', 'source')
notebooks_getting_started_src_img_dir = os.path.join(notebooks_getting_started_src_dir, 'images')
else:
notebooks_getting_started_dir = None
notebooks_getting_started_dst_img_dir = None
notebooks_getting_started_src_dir = None
notebooks_getting_started_src_img_dir = None
# Video source files
_video_src = ['pynq/lib/_pynq/_video/_video.c', 'pynq/lib/_pynq/_video/_capture.c',
'pynq/lib/_pynq/_video/_display.c', 'pynq/lib/_pynq/_video/_frame.c',
'pynq/lib/_pynq/_video/_legacy_display.c',
'pynq/lib/_pynq/_video/_legacy_capture.c',
'pynq/lib/_pynq/src/gpio.c', 'pynq/lib/_pynq/src/py_xaxivdma.c',
'pynq/lib/_pynq/src/py_xvtc.c', 'pynq/lib/_pynq/src/utils.c',
'pynq/lib/_pynq/src/py_xgpio.c',
'pynq/lib/_pynq/src/video_capture.c',
'pynq/lib/_pynq/src/video_display.c']
# BSP source files
bsp_axivdma = \
['pynq/lib/_pynq/bsp/ps7_cortexa9_0/libsrc/axivdma_v6_0/src/xaxivdma.c',
'pynq/lib/_pynq/bsp/ps7_cortexa9_0/libsrc/axivdma_v6_0/src/xaxivdma_channel.c',
'pynq/lib/_pynq/bsp/ps7_cortexa9_0/libsrc/axivdma_v6_0/src/xaxivdma_intr.c',
'pynq/lib/_pynq/bsp/ps7_cortexa9_0/libsrc/axivdma_v6_0/src/xaxivdma_selftest.c']
bsp_gpio = \
['pynq/lib/_pynq/bsp/ps7_cortexa9_0/libsrc/gpio_v4_0/src/xgpio.c',
'pynq/lib/_pynq/bsp/ps7_cortexa9_0/libsrc/gpio_v4_0/src/xgpio_extra.c',
'pynq/lib/_pynq/bsp/ps7_cortexa9_0/libsrc/gpio_v4_0/src/xgpio_intr.c',
'pynq/lib/_pynq/bsp/ps7_cortexa9_0/libsrc/gpio_v4_0/src/xgpio_selftest.c']
bsp_vtc = \
['pynq/lib/_pynq/bsp/ps7_cortexa9_0/libsrc/vtc_v7_0/src/xvtc.c',
'pynq/lib/_pynq/bsp/ps7_cortexa9_0/libsrc/vtc_v7_0/src/xvtc_intr.c',
'pynq/lib/_pynq/bsp/ps7_cortexa9_0/libsrc/vtc_v7_0/src/xvtc_selftest.c']
bsp_standalone = \
['pynq/lib/_pynq/bsp/ps7_cortexa9_0/libsrc/standalone_v5_2/src/xplatform_info.c',
'pynq/lib/_pynq/bsp/ps7_cortexa9_0/libsrc/standalone_v5_2/src/xil_assert.c',
'pynq/lib/_pynq/bsp/ps7_cortexa9_0/libsrc/standalone_v5_2/src/xil_io.c',
'pynq/lib/_pynq/bsp/ps7_cortexa9_0/libsrc/standalone_v5_2/src/xil_exception.c']
getting_started_notebooks = \
['jupyter_notebooks.ipynb', 'python_environment.ipynb']
# Merge BSP src to _video src
video = []
video.extend(bsp_standalone)
video.extend(bsp_axivdma)
video.extend(bsp_gpio)
video.extend(bsp_vtc)
video.extend(_video_src)
# Build Package Data files - notebooks, overlays
def fill_notebooks_dir():
if notebooks_dir is None:
return None
# boards/BOARD/OVERLAY/notebooks
overlay_notebook_folders = [(ol, os.path.join(board_folder, ol, 'notebooks/')) for ol in list(os.listdir(board_folder)) + ['.']
if os.path.isdir(os.path.join(board_folder, ol, 'notebooks'))]
# pynq/notebooks/*
pynq_notebook_files = ([(os.path.join(notebooks_dir, root.replace('pynq/notebooks/', '')),
[os.path.join(root, f) for f in files]) for root, dirs, files in
os.walk('pynq/notebooks/')])
# boards/BOARD/OVERLAY_NAME/notebooks/*
for ol, nb_dir in overlay_notebook_folders:
pynq_notebook_files.extend([(os.path.join(notebooks_dir, root.replace(nb_dir, '{}/'.format(ol))),
[os.path.join(root, f) for f in files]) for root, dirs, files in os.walk(nb_dir)])
# docs/source/<subset of notebooks>
pynq_notebook_files.append((notebooks_getting_started_dir,
[os.path.join('docs', 'source', nb) for nb in getting_started_notebooks]))
# docs/source/images/*
pynq_notebook_files.extend([(notebooks_getting_started_dst_img_dir,
[os.path.join(root, f) for f in files])
for root, dirs, files in os.walk(notebooks_getting_started_src_img_dir)])
# copy notebooks into final destination
for dst, files in pynq_notebook_files:
if not os.path.exists(dst):
os.makedirs(dst)
for file in files:
shutil.copy(file, dst)
dst_file = os.path.join(dst, os.path.basename(file))
os.chmod(dst_file, os.stat(dst_file).st_mode | stat.S_IWOTH)
# rename and copy getting started notebooks
for ix, getting_started_nb in enumerate(getting_started_notebooks):
new_nb_name = '{}_{}'.format(ix + 1, getting_started_nb)
src_file = os.path.join(notebooks_getting_started_dir, getting_started_nb)
dst_file = os.path.join(notebooks_getting_started_dir, new_nb_name)
shutil.move(src_file, dst_file)
# Backup Notebooks
def backup_notebooks():
if notebooks_dir is None:
return None
notebooks_dir_backup = '{}_{}'.format(notebooks_dir, datetime.now().strftime("%Y_%m_%d_%H-%M-%S"))
try:
shutil.copytree(notebooks_dir, notebooks_dir_backup)
except Exception as e:
print('Unable to backup notebooks {}'.format(e))
raise e
return notebooks_dir_backup
# Run Makefiles here
def run_make(src_path, dst_path, output_lib):
status = subprocess.check_call(["make", "-C", src_path])
if status is not 0:
print("Error while running make for", output_lib, "Exiting..")
sys.exit(1)
shutil.copyfile(src_path + output_lib, dst_path + output_lib)
if len(sys.argv) > 1 and sys.argv[1] == 'install' and CPU_ARCH_IS_SUPPORTED:
run_make("pynq/lib/_pynq/_apf/", "pynq/lib/", "libdma.so")
run_make("pynq/lib/_pynq/_audio/", "pynq/lib/", "libaudio.so")
backup_notebooks()
fill_notebooks_dir()
elif(not CPU_ARCH_IS_SUPPORTED):
warnings.warn("Pynq does not support the CPU Architecture: {}"
.format(CPU_ARCH), ResourceWarning)
if CPU_ARCH_IS_SUPPORTED:
ext_modules = [
Extension('pynq.lib._video', video,
include_dirs=['pynq/lib/_pynq/inc',
'pynq/lib/_pynq/bsp/ps7_cortexa9_0/include'],
libraries=['sds_lib'],
library_dirs=['/usr/lib'],
),
]
else:
warnings.warn("Pynq does not support the CPU Architecture: {}"
.format(CPU_ARCH), ResourceWarning)
ext_modules = []
setup(name='pynq',
version='2.0',
description='Python for Xilinx package',
author='XilinxPythonProject',
author_email='[email protected]',
url='https://github.com/Xilinx/PYNQ',
packages=find_packages(),
download_url='https://github.com/Xilinx/PYNQ',
package_data={
'': ['tests/*', 'js/*', '*.bin', '*.so', 'bitstream/*', '*.pdm'],
},
entry_points={
'console_scripts' : [
'start_pl_server.py = pynq.pl:_start_server',
'stop_pl_server.py = pynq.pl:_stop_server'
]
},
ext_modules=ext_modules,
data_files=pynq_data_files
)
if board:
print('Restarting PL server')
subprocess.run(['systemctl' ,'restart', 'pl_server'])