-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
makeNIOS_CompProject.py
1376 lines (1149 loc) · 67.1 KB
/
makeNIOS_CompProject.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3.7
#
# ######## ###### ## ## ####### ###### ######## #######
# ## ## ## ## ## ## ## ## ## ## ## ## ##
# ## ## ## #### ## ## ## ## ## ##
# ######## ###### ## ## ## ## ## ## ##
# ## ## ## ## ## ## ## ## ## ##
# ## ## ## ## ## ## ## ## ## ## ## ##
# ## ## ###### ## ####### ###### ## #######
#
#
#
# Robin Sebastian (https://github.com/robseb)
#
#
# Python Script to automatically generate an Intel NIOS II Eclipse Project with FreeRTOS,
# the Intel hwlib for the SoC-FPGAs and more
#
# (2020-05-10) Vers.1.0
# first Version
#
# (2020-06-05) Vers.1.01
# Fixed Linux Support with PythonGit
#
# (2020-06-06) Vers.1.02
# Windows 10 Quartus 19.1 with WSL support
#
# (2020-08-28) Vers.1.03
# socfpgaHAL support for accessing Hard-IP with the NIOS II
#
# (2020-09-13) Vers.1.04
# Adding socfpgaHAL Demo project
#
# (2021-05-06) Vers.1.05
# Bug fix to re-enable function with script
# GIT Repo Branch of FreeRTOS changed
# GitPython will be used for Linux and Windows
#
# (2021-05-07) Vers.1.051
# Fixing a Bug with the wrong XML template file generation
#
version = "1.051"
import os
import sys
import time
from datetime import datetime
import io
# Import a Python Pip Package to allow to clone git repos
try:
from git import RemoteProgress
from git import Git,Repo
except ImportError as ex:
print('Msg: '+str(ex))
print('This Python Application requirers "git"')
print('Use following pip command to install it:')
if sys.platform =='linux':
print('==>$ pip3 install GitPython')
else:
print('==>$ pip install GitPython==3.0.4 gitdb2==2.0.6')
sys.exit()
import subprocess
import shutil
from subprocess import Popen, PIPE
import stat
import distutils.dir_util
import distutils.file_util
# @brief to show process bar during github clone
# feature only for Linux supported
#
class CloneProgress(RemoteProgress):
def update(self, op_code, cur_count, max_count=None, message=''):
if message:
sys.stdout.write("\033[F")
print(" "+message)
#
#
#
############################################ Const ###########################################
#
#
#
GITNAME = "NIOSII_EclipseCompProject"
GIT_SCRIPT_URL = "https://github.com/robseb/NIOSII_EclipseCompProject"
GIT_FREERTOS_URL = "https://github.com/FreeRTOS/FreeRTOS-Kernel.git"
GIT_HWLIB_URL = "https://github.com/robseb/hwlib.git"
GIT_SOCFPGAHAL_URL = "https://github.com/robseb/socfpgaHAL.git"
QURTUS_DEF_FOLDER = "intelFPGA"
QURTUS_DEF_FOLDER_LITE = "intelFPGA_lite"
SPLM = ['/','\\'] # Linux, Windows
SPno = 0
NIOS_CMD_SHEL = ['nios2_command_shell.sh','Nios II Command Shell.bat']
DEMO_NAME_FREERTOSC = 'freertos_c1'
DEMO_NAME_SOCFPGAHALC = 'freertos_socfpgaHAL_c1'
#
#
#
############################################ Global ###########################################
#
#
#
#
# @brief Global Variable for adding the include paths to the TCL script
#
#
class glob:
TCL_Header_include_path_list = []
hwlib_selection =0 # 1: add hwlib, 2: do not add
socfpgaHAL_selection =0
customFolderName = []
selectedTragedDevice= 0 # 1: CY5/A5, 2: A10
#
#
#
############################################ Github clone function ###########################################
#
#
#
# @brief Copy cloned Github repository over a local temp folder to a final
# destination to remove write restricted files
#
def copy_git_windows_friendly(source,temp, fileTemp,dest):
try:
if(os.path.isdir(fileTemp)):
shutil.rmtree(fileTemp, ignore_errors=False)
except Exception as ex:
raise Exception('ERROR: Failed to remove old local folder! Msg: '+str(ex))
if sys.platform =='linux':
os.makedirs(fileTemp, mode=0o777, exist_ok=False)
else:
os.mkdir(fileTemp)
os.chmod(fileTemp, stat.S_IWRITE)
try:
for name in os.listdir(source):
if os.path.abspath(name):
if(not name == ".git") and (not name == ".github") and (not name == ".gitignore"):
print(' '+name)
if(os.path.isdir(source+SPLM[SPno]+name)):
distutils.dir_util.copy_tree(source+SPLM[SPno]+name,temp+SPLM[SPno]+name)
else:
shutil.copy2(source+SPLM[SPno]+name,fileTemp)
except Exception as ex:
raise Exception('ERROR: Failed to copy github project files to local folder! Msg:'+str(ex))
try:
distutils.dir_util.copy_tree(fileTemp,temp+SPLM[SPno]+'source')
distutils.dir_util.copy_tree(temp,dest)
except Exception as ex:
raise Exception('ERROR: Failed to copy Folder to the Quartus Project! Msg:'+str(ex))
try:
if(os.path.isdir(temp)):
shutil.rmtree(temp, ignore_errors=False)
if(os.path.isdir(fileTemp)):
shutil.rmtree(fileTemp, ignore_errors=False)
except Exception as ex:
raise Exception('ERROR: Failed to remove the local temp folder! Msg: '+str(ex))
#
#
#
############################################ TCL File generation ###########################################
#
#
#
#
# @brief Generate TCL script header for Software Components
#
#
def generate_tcl_file_header_package(FileName,PackageName,VersionNo,BspSubdir):
return '# \n'+ \
'# '+FileName+'\n'+ \
'# \n'+ \
'# Auto generated TCL Script by "'+GITNAME+'.py" in Vers: '+str(version)+'\n'+ \
'# Date: '+str(datetime.now())+ '\n'+ \
'# designed by Robin Sebastian (https://github.com/robseb) \n'+ \
'# \n'+ \
'# Script for adding the Software package "'+PackageName+'" in Version '+VersionNo+'\n'+ \
'# \n'+ \
' \n'+ \
'# Create new software package named "'+PackageName+'" \n'+ \
'create_sw_package '+PackageName+' \n'+ \
' \n'+ \
'# The version Number of this software \n'+ \
'set_sw_property version '+VersionNo+' \n'+ \
' \n'+ \
'# Location to copy the source code to it \n'+ \
'set_sw_property bsp_subdirectory '+BspSubdir+' \n'+ \
' \n'+ \
' \n'
#
# @brief Generate TCL script header for Operating Systems Components
#
#
def generate_tcl_file_header_os(FileName,OSName,DisplayName,VersionNo,BspSubdir):
return '# \n'+ \
'# '+FileName+'\n'+ \
'# \n'+ \
'# Auto generated TCL Script by "'+GITNAME+'.py" \n'+ \
'# Date: '+str(datetime.now())+ '\n'+ \
'# designed by Robin Sebastian (https://github.com/robseb) \n'+ \
'# \n'+ \
'# Script for generating a new operating system: "'+OSName+'" in Version '+VersionNo+'\n'+ \
'# \n'+ \
' \n'+ \
'# Create new OS called "'+OSName+'" \n'+ \
'create_os '+OSName+' \n'+ \
' \n'+ \
'# Chosen UI Display Name: "'+DisplayName+'" \n'+ \
'set_sw_property display_name '+DisplayName+' \n'+ \
' \n'+ \
'# The OS should extends the HAL BSP \n'+ \
'set_sw_property extends_bsp_type HAL \n'+ \
' \n'+ \
'# The version Number of this software \n'+ \
'set_sw_property version '+VersionNo+' \n'+ \
' \n'+ \
'# Location in generated BSP that above sources will be copied into \n'+ \
'set_sw_property bsp_subdirectory '+ OSName+' \n' + \
' \n'+ \
'# Enable preemtion Interupt support for the OS \n'+ \
'set_sw_property isr_preemption_supported true \n'+ \
' \n'+ \
' \n'
#
# @brief Check the in the "generate_tcl_file_sources" founded files and write
# them to the TCL script file
#
def add_files_to_list(fileName,pathRel,MainFolder):
pathRel = pathRel.replace('\\','/')
folderPath = pathRel[1:]
locFilePath = folderPath+'/'+fileName
tcl_str = ''
if fileName.endswith('.c'):
tcl_str= tcl_str+'add_sw_property c_source '+locFilePath+' \n'
elif fileName.endswith('.h'):
tcl_str= tcl_str+'add_sw_property include_source '+locFilePath+' \n'
if not folderPath in glob.TCL_Header_include_path_list:
glob.TCL_Header_include_path_list.append(folderPath)
elif fileName.endswith('.S'):
tcl_str= tcl_str+'add_sw_property asm_source '+locFilePath+' \n'
return tcl_str
#
# @brief Add the path of every available file inside a folder structure to the
# TCL script file
#
def generate_tcl_file_sources(folderSourceAbs,MainFolder):
tcl_str ='\n###### \n'+ \
'# Source file listing \n'+ \
'###### \n'+'\n'
print('--> Progress every file in folder structure "'+MainFolder+'"\n')
# Find every file in every folders
try:
depthList = []
depthListAbs = []
depthPath =[]
listOfProgressedFolders =[]
listOfProgressedFiles =[]
pathsuffix= ''
pathsuffix_old =''
MultiJump =False
while True:
folderList =[]
for file in os.listdir(folderSourceAbs+pathsuffix):
if(os.path.isfile(folderSourceAbs+pathsuffix+SPLM[SPno]+file)):
# Progress File
if( (not folderSourceAbs+pathsuffix+SPLM[SPno]+file in listOfProgressedFiles)):
print(' File: '+file)
tcl_str = tcl_str+ add_files_to_list(file,pathsuffix,MainFolder)
listOfProgressedFiles.append(folderSourceAbs+pathsuffix+SPLM[SPno]+file)
elif ( not folderSourceAbs+pathsuffix+SPLM[SPno]+file in listOfProgressedFolders):
# Add folder to the list
print(' Folder: '+file)
folderList.append(file)
# Some folders in current level found
if not (len(folderList) ==0):
tcl_str=tcl_str+'\n'
curFolder = folderList[-1]
# Save absolute folder path for depth tracking
folderListAbs =[]
for obj in folderList:
folderListAbs.append(folderSourceAbs+pathsuffix+SPLM[SPno]+obj)
depthListAbs.append(folderListAbs)
listOfProgressedFolders.append(folderSourceAbs+pathsuffix+SPLM[SPno]+curFolder)
pathsuffix_old = SPLM[SPno]+curFolder
pathsuffix = pathsuffix+ pathsuffix_old
print(' --> '+ pathsuffix)
# Add folders to depth list
depthList.append(folderList)
MultiJump = False
elif (not len(depthList) == 0):
pathsuffix=pathsuffix.replace(pathsuffix_old,'')
print(' <-- '+ pathsuffix)
tcl_str=tcl_str+'\n'
# Multi Jump to an other path required
if(MultiJump):
#Find a folder that is not progressed jet
tempC =0
len2goBack =0
Folder2find = ''
for deep in depthListAbs[:]:
tempC = tempC+1
for l in deep:
if not l in listOfProgressedFolders:
len2goBack = tempC
Folder2find = l
break
if not Folder2find=='':
break
if(Folder2find == ''):
break
Folder2find = Folder2find.replace(folderSourceAbs,'')
pathsuffix = Folder2find
# listOfProgressedFolders.append(pathsuffix)
listOfProgressedFolders.append(folderSourceAbs+pathsuffix)
print(' <<<<---- '+pathsuffix)
# Go a single level back
del depthList[-1]
MultiJump = True
else:
break
except Exception as ex:
raise Exception('ERROR: Failed to read ! Msg:'+str(ex))
print(' ==== File processing done ====\n')
print('--> Generate include folders for "'+MainFolder+'"')
tcl_str=tcl_str+'\n\n'+ \
'# \n'+ \
'## Include paths \n'+ \
'# \n'
'''
if not 'include' in glob.TCL_Header_include_path_list:
glob.TCL_Header_include_path_list.append('include')
'''
for incl in glob.TCL_Header_include_path_list:
print(' Add include path: '+incl)
tcl_str = tcl_str+ 'add_sw_property include_directory '+ incl+ '\n'
glob.TCL_Header_include_path_list = []
return tcl_str
#
# @brief Add the path of every available file inside a folder structure to the
# TCL script file
#
def generate_tcl_file_add_constBool(SysName,ValueName,Value,Description):
return 'add_sw_setting boolean system_h_define '+SysName+' '+ValueName+' '+str(Value)+' "'+Description+'"\n'
#
#
#
############################################ XML Template File generation ###########################################
#
#
#
#
# @brief Generate the XML Template File for the Demo project
# TCL script file
#
def generate_xml_template_file(DemoName,AppName,BSPname,TypeName,DemoDesc):
details =' --- rsyocto build system--- \\n \n' + \
' AUTOMATIC GENERATED ECLIPSE FOR NIOS II PROJECT \\n \n' + \
'('+GIT_SCRIPT_URL+')\\n \n' + \
' \\n \n' + \
' ------------------------------------------------------------ \\n \n' + \
' by Robin Sebastian (https://github.com/robseb) \\n \n' + \
' Contact: git@robseb.de\\n \n' + \
' Vers.: '+version+' Generation: '+str(datetime.now())+' \\n \n' + \
' \\n \n' + \
' ------------------------------------------------------------\\n \n' + \
' Added Components: \\n \n' + \
' - FreeRTOS -latest \\n \n'
if(glob.hwlib_selection==1):
details=details+' - hwlib -18.1 \\n \n'
if(glob.socfpgaHAL_selection==1):
details=details+' - socfpgaHAL \\n \n'
if len(glob.customFolderName)>0:
for FolderName in glob.customFolderName:
details=details+' - '+FolderName+' \\n \n'
details=details+' ------------------------------------------------------------\\n \n' + \
' Supported Device: \\n \n'
if(glob.selectedTragedDevice==1):
details=details+' - Intel Cyclone V or Arria V SoC-FPGA \\n \n'
elif(glob.selectedTragedDevice==2):
details=details+' - Intel Arria 10 SoC-FPGA \\n \n'
else:
details=details+' - universal Intel FPGA Family\\n \n'
xml_str = '<?xml version="1.0" encoding="UTF-8"?> \n' +\
'<template_settings> \n' +\
' <template \n' +\
' name="'+DemoName+'" \n' +\
' description="'+DemoDesc+'" \n' +\
' file_to_open="main.c" \n' +\
' details="'+details+'"> \n'+\
' </template> \n'+\
' <stf> \n'+\
' <os_spec name="FreeRTOS"> \n'
if(glob.hwlib_selection==1):
xml_str=xml_str+' <sw_component name="Intel hwlib" id="hwlib"/> \n'
if(glob.socfpgaHAL_selection==1):
xml_str=xml_str+' <sw_component name="robseb socfpgaHAL" id="socfpgaHAL"/> \n'
if len(glob.customFolderName)>0:
for FolderName in glob.customFolderName:
xml_str=xml_str+' <sw_component name="'+FolderName+'" id="'+FolderName+'"/> \n'
xml_str=xml_str+' </os_spec> \n'+\
' </stf> \n'+\
' <create-this> \n'+\
' <app name="'+AppName+'" \n'+\
' nios2-app-generate-makefile-args=" --set OBJDUMP_INCLUDE_SOURCE 1 --src-files main.c "\n'+\
' bsp="'+BSPname+'"> \n'+\
' </app> \n'+\
' <bsp name="'+BSPname+'" \n'
# add only FreeRTOS
if len(glob.customFolderName)==0 and glob.hwlib_selection==2:
xml_str=xml_str+' type="'+TypeName+'"> \n'
else:
xml_str=xml_str+' type="'+TypeName+'"> \n'
# add FreeRTOS + hwlib
if(glob.hwlib_selection==1) and len(glob.customFolderName)==0:
xml_str=xml_str+' nios2-bsp-args="--cmd enable_sw_package hwlib"> \n'
if(glob.socfpgaHAL_selection==1) and len(glob.customFolderName)==0:
xml_str=xml_str+' nios2-bsp-args="--cmd enable_sw_package socfpgaHAL"> \n'
# add FreeRTOS + user components
if len(glob.customFolderName)>0:
if(glob.socfpgaHAL_selection==1):
xml_str=xml_str+' nios2-bsp-args="--cmd enable_sw_package socfpgaHAL"> \n'
if(glob.hwlib_selection==1):
xml_str=xml_str+' nios2-bsp-args="--cmd enable_sw_package hwlib'
if(glob.hwlib_selection!=1) and (glob.socfpgaHAL_selection!=1):
xml_str=xml_str+' nios2-bsp-args="'
for FolderName in glob.customFolderName:
xml_str=xml_str+' --cmd enable_sw_package '+FolderName
xml_str=xml_str+' ">\n'
xml_str=xml_str+' </bsp> \n'+\
' </create-this> \n'+\
'</template_settings> \n'
return xml_str
#
#
#
############################################ Selection Menu ###########################################
#
#
#
def selection_menu(header1,header2, setitem1, setitem2 ):
print('\n##############################################################################')
print('# -> '+header1+' <- #')
print('# -> '+header2+' <- #')
print('# 1: '+setitem1)
print('# 2: '+setitem2)
print('------------------------------------------------------------------------------')
print('Q,C = abort execution ')
while True:
nb = input('--> Please choose with 1 or 2 = ')
if(nb == '1'):
print('---->'+setitem1+'\n')
return 0
elif(nb == '2'):
print('---->'+setitem2+'\n')
return 1
elif ((nb == 'C') or (nb == 'c') or (nb == 'Q') or (nb == 'q')):
print('----> Abort execution of the script')
sys.exit()
print('! The input was invalid !')
############################################ ############################################
############################################ MAIN ############################################
############################################ ############################################
if __name__ == '__main__':
print('\n#############################################################################')
print('# #')
print('# ######## ###### ## ## ####### ###### ######## ####### #')
print('# ## ## ## ## ## ## ## ## ## ## ## ## ## #')
print('# ## ## ## #### ## ## ## ## ## ## #')
print('# ######## ###### ## ## ## ## ## ## ## #')
print('# ## ## ## ## ## ## ## ## ## ## #')
print('# ## ## ## ## ## ## ## ## ## ## ## ## #')
print('# ## ## ###### ## ####### ###### ## ####### #')
print('# #')
print("# AUTOMATIC SCRIPT FOR GENERATING AN ECLIPSE FOR NIOS II PROJECT #")
print("# WITH CUSTOM COMPONENTS,OS AND HAL,... #")
print('# #')
print("# by Robin Sebastian (https://github.com/robseb) #")
print('# Contact: git@robseb.de #')
print("# Vers.: "+version+" #")
print('# #')
print('##############################################################################\n\n')
############################################ Runtime environment check ###########################################
# Runtime environment check
if sys.version_info[0] < 3:
print("Use Python 3 for this script!")
sys.exit()
############################################ Find Quartus Installation Path #######################################
print('--> Find the System Platform')
if sys.platform =='linux':
Quartus_Folder_def_suf_dir = os.path.join(os.path.join(os.path.expanduser('~'))) + '/'
SPno = 0
else:
Quartus_Folder_def_suf_dir = 'C:\\'
SPno = 1
QURTUS_NIOSSHELL_DIR = SPLM[SPno]+"nios2eds"+SPLM[SPno]+NIOS_CMD_SHEL[SPno]
# 1.Step: Find the Quartus installation path
print('--> Try to find the default Quartus installation path')
quartus_standard_ver = False
# Loop to detect the case that the free Version of EDS (EDS Standard [Folder:intelFPGA]) and
# the free Version of Quartus Prime (Quartus Lite [Folder:intelFPGA_lite]) are installed together
while(True):
if (os.path.exists(Quartus_Folder_def_suf_dir+QURTUS_DEF_FOLDER)) and (not quartus_standard_ver):
Quartus_Folder=Quartus_Folder_def_suf_dir+QURTUS_DEF_FOLDER
quartus_standard_ver = True
elif(os.path.exists(Quartus_Folder_def_suf_dir+QURTUS_DEF_FOLDER_LITE)):
Quartus_Folder=Quartus_Folder_def_suf_dir+QURTUS_DEF_FOLDER_LITE
quartus_standard_ver = False
else:
print('ERROR: No Intel Quartus Installation Folder was found!')
sys.exit()
# 2.Step: Find the latest Quartus Version No.
avlVer = []
for name in os.listdir(Quartus_Folder):
if os.path.abspath(name):
try:
avlVer.append(float(name))
except Exception:
pass
if (len(avlVer)==0):
print('ERROR: No valid Quartus Version was found')
sys.exit()
avlVer.sort(reverse = True)
highestVer = avlVer[0]
Quartus_Folder = Quartus_Folder + SPLM[SPno]+ str(highestVer)
if (not(os.path.realpath(Quartus_Folder))):
print('ERROR: No Quartus Installation Folder was found!')
sys.exit()
# Check if the NIOS II Command Shell is available
if((not(os.path.isfile(Quartus_Folder+QURTUS_NIOSSHELL_DIR)) )):
if( not quartus_standard_ver):
print('ERROR: Intel NIOS II Command Shell was not found!')
sys.exit()
else:
break
print(' Following Quartus Installation Folder was found:')
print(' '+Quartus_Folder)
############################### Check that the script runs inside the Github folder ###############################
print('\n--> Check that the script runs inside the Github folder')
excpath = os.getcwd()
try:
if(len(excpath)<len(GITNAME)):
raise Exception()
# Find the last slash in the execution path
slashpos =0
for str_ in excpath:
slashpos_pos=excpath.find(SPLM[SPno],slashpos)
if(slashpos_pos == -1):
break
slashpos= slashpos_pos+len(SPLM[SPno])
if(not excpath[slashpos:] == GITNAME):
raise Exception()
if(not os.path.isdir(os.getcwd()+SPLM[SPno]+'Demos')):
raise Exception()
except Exception:
print('ERROR: The script was not executed inside the cloned Github folder')
print(' Please clone this script from Github and execute the script')
print(' directly inside the cloned folder!')
print('URL: '+GIT_SCRIPT_URL)
sys.exit()
############################################ Inputs and user selection ############################################
projectName= "working_folder"
print('\n--> Working Folder Name: %s \n' % (projectName))
'''
# hwlib required ?
glob.hwlib_selection = selection_menu('Intel hwlib for using the peripheral HPS components ','of the Cyclone and Arria SoC-FPGA with the NIOS II',\
'Install the hwlib','Do not pre-install the hwlib') +1
glob.selectedTragedDevice= 0# 1: CY5/A5, 2: A10
if(glob.hwlib_selection ==1):
# Select the target device
glob.selectedTragedDevice = selection_menu('Select the Intel SoC-FPGA Family',\
'','Intel Cyclone V- or Arria V SoC-FPGA','Intel Arria 10 SoC-FPGA') +1
'''
# socfpgaHAL required ?
glob.socfpgaHAL_selection = selection_menu('Install the socfpgaHAL for accessing the peripheral hard-IP HPS components ',\
'of a Cyclone SoC-FPGA with the NIOS II Core?','Install the socfpgaHAL','Do not pre-install the socfpgaHAL') +1
glob.selectedTragedDevice= 0# 1: CY5/A5, 2: A10
if(glob.socfpgaHAL_selection ==1):
# Select the target device
glob.selectedTragedDevice = selection_menu('Select the Intel SoC-FPGA Family','','Intel Cyclone V- or Arria V SoC-FPGA','Intel Arria 10 SoC-FPGA') +1
if glob.selectedTragedDevice ==2:
print('Error: The selected device is in this version not supported!')
sys.exit()
print('=====================>>> Starting the generation... <<<==================== \n')
################################################ Create Project Folder ###########################################
if( not (os.path.isdir(projectName))):
os.mkdir(projectName)
print('--> Create a new project folder')
################################################ Clone the latest FreeRTOS Version ###############################
if(os.path.isdir(projectName+SPLM[SPno]+"FreeRTOS-Kernel")):
print('--> FreeRTOS Version is already available')
print(' Pull it from Github')
g = Git(os.getcwd()+SPLM[SPno]+ projectName+SPLM[SPno]+'FreeRTOS-Kernel')
g.pull()
else:
print('--> Cloning the latest FreeRTOS Kernel Version ('+GIT_FREERTOS_URL+')')
print(' please wait...')
try:
Repo.clone_from(GIT_FREERTOS_URL,os.getcwd()+SPLM[SPno]+ projectName+SPLM[SPno]+'FreeRTOS-Kernel',
branch='main', progress=CloneProgress())
except Exception as ex:
print('ERROR: The cloning failed! Error Msg.:'+str(ex))
sys.exit()
if(os.path.isdir(os.getcwd()+SPLM[SPno]+ projectName+SPLM[SPno]+'FreeRTOS-Kernel-master')):
os.rename(os.getcwd()+SPLM[SPno]+ projectName+SPLM[SPno]+'FreeRTOS-Kernel-master',os.getcwd()+SPLM[SPno]+ projectName+SPLM[SPno]+'FreeRTOS-Kernel')
########################################### Check if the FreeRTOS format is okay ################################
print('--> Check if the FreeRTOS folders looks okay')
if(not (os.path.isdir(projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+"portable")) and (os.path.isdir(projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+"include"))
and (os.path.isdir(projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+"portable"+SPLM[SPno]+"GCC"))and (os.path.isdir(projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+"portable"+SPLM[SPno]+"GCC"+SPLM[SPno]+"NiosII"))):
print('ERROR: The downloaded FreeRTOS Folder is not in a valid format!')
sys.exit()
else:
print(' looks okay')
########################################### Remove BSP driver for other Platforms ###############################
# 1. Step: Remove support for other compilers (Only the GCC complier should be supported)
print('--> Remove support of different compilers as GCC')
# Allow only the folder "GCC" and "MemMang" inside /FreeRTOS-Kernel/portable
print('--> Allow only the folder "GCC" and "MemMang" inside /FreeRTOS-Kernel/portable')
for name in os.listdir(projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+"portable"):
if os.path.abspath(name):
if (not (name == 'GCC')):
if (not (name == 'MemMang')):
if (os.path.isdir(projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+"portable"+SPLM[SPno]+name)):
try:
shutil.rmtree(projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+"portable"+SPLM[SPno]+name)
except Exception as ex:
print('Msg: '+str(ex))
print('Warning: Failed to delate folder: /FreeRTOS-Kernel/portable/'+name)
# 2. Step: Remove support for other platform
print('--> Remove support of different Platform as Intel NIOS II')
# Allow only the NIOS II folder inside /FreeRTOS-Kernel/portable/GCCs
for name in os.listdir(projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+"portable"+SPLM[SPno]+"GCC"):
if os.path.abspath(name):
if (not (name == 'NiosII')):
if (os.path.isdir(projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+"portable"+SPLM[SPno]+"GCC"+SPLM[SPno]+name)):
try:
shutil.rmtree(projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+"portable"+SPLM[SPno]+"GCC"+SPLM[SPno]+name)
except Exception as ex:
print('Msg: '+str(ex))
print('Warning: Failed to delate folder: /FreeRTOS-Kernel/portable/GCC/'+name)
# 3. Step: Remove vintage FreeRTOS Memory Management
if(os.path.isdir(projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+"portable"+SPLM[SPno]+"MemMang")):
print('--> Remove vintage Memory Management')
try:
if (os.path.isfile(projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+"portable"+SPLM[SPno]+"MemMang"+SPLM[SPno]+"heap_1.c")):
os.remove(projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+"portable"+SPLM[SPno]+"MemMang"+SPLM[SPno]+"heap_1.c")
if (os.path.isfile(projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+"portable"+SPLM[SPno]+"MemMang"+SPLM[SPno]+"heap_2.c")):
os.remove(projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+"portable"+SPLM[SPno]+"MemMang"+SPLM[SPno]+"heap_2.c")
except Exception as ex:
print('Msg: '+str(ex))
print('Warning: Failed to delate vintage memory management files')
################################################ Clone the latest hwlib Version ###############################
if glob.hwlib_selection == 1:
if(os.path.isdir(projectName+SPLM[SPno]+"hwlib")):
print('--> hwlib Version is already available')
print(' Pull it from Github')
g = Git(os.getcwd()+SPLM[SPno]+ projectName+SPLM[SPno]+'hwlib')
g.pull()
else:
print('--> Cloning the latest hwlib Version ('+GIT_HWLIB_URL+')\n')
print(' please wait...')
try:
Repo.clone_from(GIT_HWLIB_URL,os.getcwd()+SPLM[SPno]+ projectName+SPLM[SPno]+'hwlib',
branch='master', progress=CloneProgress())
except Exception as ex:
print('ERROR: The cloning failed! Error Msg.:'+str(ex))
sys.exit()
if(os.path.isdir(os.getcwd()+SPLM[SPno]+ projectName+SPLM[SPno]+'hwlib-master')):
os.rename(os.getcwd()+SPLM[SPno]+ projectName+SPLM[SPno]+'hwlib-master',os.getcwd()+SPLM[SPno]+ projectName+SPLM[SPno]+'hwlib')
########################################### Check if the hwlib format is okay ################################
if glob.hwlib_selection == 1:
print('--> Check if the folders inside hwlib look okay')
if(not (os.path.isdir(projectName+SPLM[SPno]+"hwlib"))):
print('ERROR: The downloaded hwlib Folder is not in a valid format!')
sys.exit()
else:
print(' looks okay')
################################################ Clone the latest socfpgaHAL Version ###############################
if glob.socfpgaHAL_selection == 1:
if(os.path.isdir(projectName+SPLM[SPno]+"socfpgaHAL")):
print('--> socfpgaHAL Version is already available')
print(' Pull it from Github')
g = Git(os.getcwd()+SPLM[SPno]+ projectName+SPLM[SPno]+'socfpgaHAL')
g.pull()
else:
print('--> Cloning the latest socfpgaHAL Version ('+GIT_SOCFPGAHAL_URL+')\n')
print(' please wait...')
try:
Repo.clone_from(GIT_SOCFPGAHAL_URL,os.getcwd()+SPLM[SPno]+ projectName+SPLM[SPno]+'socfpgaHAL',
branch='master', progress=CloneProgress())
except Exception as ex:
print('ERROR: The cloning failed! Error Msg.:'+str(ex))
sys.exit()
if(os.path.isdir(os.getcwd()+SPLM[SPno]+ projectName+SPLM[SPno]+'socfpgaHAL-master')):
os.rename(os.getcwd()+SPLM[SPno]+ projectName+SPLM[SPno]+'socfpgaHAL-master',os.getcwd()+SPLM[SPno]+ projectName+SPLM[SPno]+'socfpgaHAL')
########################################### Check if the socfpgaHAL format is okay ################################
if glob.hwlib_selection == 1:
print('--> Check if the folders inside socfpgaHAL look okay')
if(not (os.path.isdir(projectName+SPLM[SPno]+"socfpgaHAL"))):
print('ERROR: The downloaded socfpgaHAL Folder is not in a valid format!')
sys.exit()
else:
print(' looks okay')
############################# Allow the user to add custom code to the project ###############################
print('\n###############################################################################')
print('# #')
print('# OPTIONAL: ADD CUSTOM COMPONENTS TO THE PROJECT #')
print('# #')
print('# At this point it is possible to generate for custom code a NIOS II Eclipse #')
print('# component to add the code to the final NIOS II Eclipse HAL project #')
print('# #')
print('# Copy a folder with the code to the working folder #')
print('# for every folder will be a NIOS II Eclipse component be generated and #')
print('# it will be added to the final Demo project #')
print('# #')
print('# Note: The folder name will be used as component name #')
print('------------------------------------------------------------------------------')
print('# The working folder: #')
print(' '+os.getcwd()+SPLM[SPno]+ projectName+SPLM[SPno])
print('------------------------------------------------------------------------------')
_wait_ = input('Type anything to continue ... ')
######################################## Detect added custom folders ##########################################
print('\n--> Detect added custom folders')
for comFolders in os.listdir(os.getcwd()+SPLM[SPno]+ projectName+SPLM[SPno]):
if(not(comFolders == 'hwlib') and (not(comFolders == 'FreeRTOS-Kernel')) \
and (not(comFolders == 'socfpgaHAL'))):
print(' Folder: '+comFolders)
glob.customFolderName.append(comFolders)
if len(glob.customFolderName) <=0:
print(' No Folders detect')
################################################ Set Quartus Folder Directories ###############################
print('------------------------------------------------------------------------------')
Quartus_componet_folder = Quartus_Folder+SPLM[SPno]+'nios2eds'+SPLM[SPno]+'components'
Quartus_example_folder = Quartus_Folder+SPLM[SPno]+'nios2eds'+SPLM[SPno]+'examples'+SPLM[SPno]+'software'
############################## Copy the additional files to the FreeRTOS folder ###############################
if(not (os.path.isdir("Additional"+SPLM[SPno]+'FreeRTOS'))):
print('NOTE: No additional files for FreeRTOS available!')
else:
print('--> Copy additional files to the FreeRTOS folder')
# Copy Source files to the main folder
if(os.path.isdir("Additional"+SPLM[SPno]+'FreeRTOS'+SPLM[SPno]+'src')):
print(' Copy source files')
try:
distutils.dir_util.copy_tree(os.getcwd()+SPLM[SPno]+"Additional"+SPLM[SPno]+'FreeRTOS'+SPLM[SPno]+'src',
os.getcwd()+SPLM[SPno]+projectName+SPLM[SPno]+"FreeRTOS-Kernel")
except Exception as ex:
print('Msg: '+str(ex))
print('Error: Failed to copy additional source files to FreeRTOS-Kernel')
sys.exit()
# Replace the port.c file with additional/port.c file
if(os.path.isfile("Additional"+SPLM[SPno]+'FreeRTOS'+SPLM[SPno]+'portable'+SPLM[SPno]+'port.c')
and os.path.isfile(os.getcwd()+SPLM[SPno]+projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+'portable'+SPLM[SPno]+'GCC'+SPLM[SPno]+'NiosII'+SPLM[SPno]+'port.c')):
print('--> Replace the port.c file with additional/port.c file')
try:
os.remove(os.getcwd()+SPLM[SPno]+projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+'portable'+SPLM[SPno]+'GCC'+SPLM[SPno]+'NiosII'+SPLM[SPno]+'port.c')
shutil.copy2(os.getcwd()+SPLM[SPno]+"Additional"+SPLM[SPno]+'FreeRTOS'+SPLM[SPno]+'portable'+SPLM[SPno]+'port.c',
os.getcwd()+SPLM[SPno]+projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+'portable'+SPLM[SPno]+'GCC'+SPLM[SPno]+'NiosII'+SPLM[SPno]+'port.c')
except Exception as ex:
print('Msg: '+str(ex))
print('Error: Failed to copy additional source files to FreeRTOS-Kernel')
sys.exit()
# Copy everything else to the FreeRTOS/portable/NIOS_RTOS_HAL folder
if(os.path.isdir("Additional"+SPLM[SPno]+'FreeRTOS'+SPLM[SPno]+'NIOS_RTOS_HAL')):
print('--> Copy everything else to the FreeRTOS/portable/NIOS_RTOS_HAL folder')
if(os.path.isdir(os.getcwd()+SPLM[SPno]+projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+'portable'+SPLM[SPno]+'NIOS_RTOS_HAL')):
try:
shutil.rmtree(os.getcwd()+SPLM[SPno]+projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+'portable'+SPLM[SPno]+'NIOS_RTOS_HAL', ignore_errors=False)
except Exception as ex:
print('Msg: '+str(ex))
print('Error: Failed to delate the FreeRTOS-Kernel/portable/NIOS_RTOS_HAL folder')
sys.exit()
os.mkdir(os.getcwd()+SPLM[SPno]+projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+'portable'+SPLM[SPno]+'NIOS_RTOS_HAL')
try:
distutils.dir_util.copy_tree(os.getcwd()+SPLM[SPno]+"Additional"+SPLM[SPno]+'FreeRTOS'+SPLM[SPno]+'NIOS_RTOS_HAL',
os.getcwd()+SPLM[SPno]+projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+'portable'+SPLM[SPno]+'NIOS_RTOS_HAL')
except Exception as ex:
print('Msg: '+str(ex))
print('Error: Failed to copy additional source files to FreeRTOS-Kernel/portable folder')
sys.exit()
# Copy Include files to the main folder
if(os.path.isdir("Additional"+SPLM[SPno]+'FreeRTOS'+SPLM[SPno]+'inc')):
print(' Copy include files')
try:
distutils.dir_util.copy_tree(os.getcwd()+SPLM[SPno]+"Additional"+SPLM[SPno]+'FreeRTOS'+SPLM[SPno]+'inc',
os.getcwd()+SPLM[SPno]+projectName+SPLM[SPno]+"FreeRTOS-Kernel"+SPLM[SPno]+'include')
except Exception as ex:
print('Msg: '+str(ex))
print('Error: Failed to copy additional include files to FreeRTOS-Kernel')
sys.exit()
######################################### Copy to the Quartus component folder ################################
# 1. Step: Copy the FreeRTOS Kernel to the component folder
if(os.path.isdir(Quartus_componet_folder+SPLM[SPno]+'FreeRTOS')):
print('\n--> Remove old component folder: FreeRTOS')
try:
shutil.rmtree(Quartus_componet_folder+SPLM[SPno]+'FreeRTOS', ignore_errors=False)
except Exception as ex:
print('ERROR: Failed to remove the old FreeRTOS Quartus Component folder!')
print('Msg: '+str(ex))
sys.exit()
print('--> Generate FreeRTOS Kernel code file structure and')
print(' Copy the FreeRTOS Kernel to the Quartus Component folder')
try:
copy_git_windows_friendly(os.getcwd()+SPLM[SPno]+projectName+SPLM[SPno]+'FreeRTOS-Kernel',os.getcwd()+SPLM[SPno]+projectName+SPLM[SPno]+'FreeRTOS'+SPLM[SPno],
os.getcwd()+SPLM[SPno]+projectName+SPLM[SPno]+'source',Quartus_componet_folder+SPLM[SPno]+'FreeRTOS')
except Exception as ex:
print('Error during FreeRTOS-Kernel data processing')
print(str(ex))
sys.exit()
if glob.hwlib_selection == 1:
# 2. Step: Copy the hwlib to the component folder
if(os.path.isdir(Quartus_componet_folder+SPLM[SPno]+'hwlib')):
print('--> Remove old component folder: hwlib')
try:
shutil.rmtree(Quartus_componet_folder+SPLM[SPno]+'hwlib')
except Exception as ex:
print('ERROR: Failed to remove the old hwlib Quartus Component folder!')
print('Msg: '+str(ex))
sys.exit()
print('--> Generate hwlib code file structure and')
print(' Copy the hwlib to the Quartus Component folder')
try:
copy_git_windows_friendly(os.getcwd()+SPLM[SPno]+projectName+SPLM[SPno]+'hwlib',os.getcwd()+SPLM[SPno]+projectName+SPLM[SPno]+'hwlibNIOS'+SPLM[SPno],
os.getcwd()+SPLM[SPno]+projectName+SPLM[SPno]+'top'+SPLM[SPno],Quartus_componet_folder+SPLM[SPno]+'hwlib')
except Exception as ex:
print('Error during hwlib data processing')
print(str(ex))
sys.exit()
if glob.socfpgaHAL_selection == 1:
# 2. Step: Copy the socfpgaHAL to the component folder
if(os.path.isdir(Quartus_componet_folder+SPLM[SPno]+'socfpgaHAL')):
print('--> Remove old component folder: socfpgaHAL')
try:
shutil.rmtree(Quartus_componet_folder+SPLM[SPno]+'socfpgaHAL')
except Exception as ex:
print('ERROR: Failed to remove the old socfpgaHAL Quartus Component folder!')
print('Msg: '+str(ex))
sys.exit()
print('--> Generate socfpgaHAL code file structure and')
print(' Copy the socfpgaHAL to the Quartus Component folder')
try:
copy_git_windows_friendly(os.getcwd()+SPLM[SPno]+projectName+SPLM[SPno]+'socfpgaHAL',os.getcwd()+SPLM[SPno]+projectName+SPLM[SPno]+'socfpgaHALNIOS'+SPLM[SPno],
os.getcwd()+SPLM[SPno]+projectName+SPLM[SPno]+'top'+SPLM[SPno],Quartus_componet_folder+SPLM[SPno]+'socfpgaHAL')
except Exception as ex:
print('Error during hwlib data processing')
print(str(ex))
sys.exit()
# 3. Step: Copy the custom user folders
if len(glob.customFolderName)>0:
print('\n--> Generate component TCL script for custom user files')
for FolderName in glob.customFolderName:
if(os.path.isdir(Quartus_componet_folder+SPLM[SPno]+FolderName)):
print('--> Remove old custom user component folder: '+FolderName)
try:
shutil.rmtree(Quartus_componet_folder+SPLM[SPno]+FolderName)