-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsocfpgaPlatformGenerator.py
2273 lines (1953 loc) · 114 KB
/
socfpgaPlatformGenerator.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)
# Contact: [email protected]
# Repository: https://github.com/robseb/meta-intelfpga
#
# Python Script to automatically generate the u-boot bootloader
# for Intel SoC-FPGAs
# (2020-07-23) Vers.1.0
# first Version
#
# (2020-09-02) Vers. 1.01
# Generation of a FPGA configuration file that can be written by the HPS
#
# (2020-09-08) Vers. 1.02
# Fixing a issue with non licence IP inside Quartus Prime projects
#
# (2020-09-09) Vers. 1.03
# Arria 10 SX support
#
# (2020-12-06) Vers. 1.04
# Arria 10 SX bug fix
#
# (2020-12-07) Vers. 1.05
# Adding SoC-EDS DeviceTree Generator Execution
#
# (2020-12-09) Vers. 1.06
# Arria 10 SX bug fix
#
# (2021-01-08) Vers. 1.07
# Bug Fix with Github folder detection
# Altera "u-boot-socfpga" git pull error detection
#
# (2021-02-10) Vers. 1.10
# * Bug Fix with FPGA configuration generation with unlicensed IP projects
# * New selection interfaces
# * Support for pre-build bootloader for Arria 10 SX
# * Bug fix with using a Yocto Project Linux distribution
# * Interface to allow to use a own Linux Devicetree with a Yocto Project Distribution
# * Bug fix with the partition size calculation and unzip of archive files
# * Spell fix with the name "linaro"
#
# (2021-02-17) Vers. 1.11
# Small bug fix for CentOS
#
# (2021-10-26) Vers. 1.12
# Setting u-boot-socfpga branch to "rel_socfpga_v2020.10_21.06.02_pr"
#
# (2021-10-27) Vers. 1.13
# Support for FPPx32 FPGA Configuration Files
#
version = "1.13"
#
#
#
############################################ Const ###########################################
#
#
#
DELAY_MS = 1 # Delay after critical tasks in milliseconds
QURTUS_DEF_FOLDER = "intelFPGA"
QURTUS_DEF_FOLDER_LITE = "intelFPGA_lite"
EDS_EMBSHELL_DIR = "/embedded/embedded_command_shell.sh"
BOOTLOADER_FILE_NAME = 'u-boot-with-spl.sfp'
# Arria 10 only
U_BOOT_IMAGE_FILE_NAME ='u-boot.img'
SFP_OUTPUT_FILE_NAME ='spl_w_dtb-mkpimage.bin'
SFP_INPUT_FILE_NAME ='u-boot-spl-dtb.bin'
FIT_FPGA_FILE_NAME ='fit_spl_fpga.itb'
YOCTO_BASE_FOLDER = 'poky'
IMAGE_FOLDER_NAME = 'Image_partitions'
GITNAME = "socfpgaplatformgenerator"
GIT_SCRIPT_URL = "https://github.com/robseb/socfpgaPlatformGenerator.git"
GIT_U_BOOT_SOCFPGA_URL = "https://github.com/altera-opensource/u-boot-socfpga"
GIT_U_BOOT_SOCFPGA_BRANCH = "rel_socfpga_v2020.10_21.06.02_pr" # "socfpga_v2021.04" # default: master --> Arria 10 SX and Cyclone working: "socfpga_v2020.04"
GIT_LINUXBOOTIMAGEGEN_URL = "https://github.com/robseb/LinuxBootImageFileGenerator.git"
# The Linux devicetree names required for bootloader generation
DEVICETREE_OUTPUT_NAME = ['socfpga_cyclone5_socdk.dts','', \
'socfpga_arria10_socdk_sdmmc.dts']
#
# @brief default XML Blueprint file
#
INTELSOCFPGA_BLUEPRINT_XML_FILE ='<?xml version="1.0" encoding = "UTF-8" ?>\n'+\
'<!-- Linux Distribution Blueprint XML file -->\n'+\
'<!-- Used by the Python script "LinuxDistro2Image.py -->\n'+\
'<!-- to create a custom Linux boot image file -->\n'+\
'<!-- Description: -->\n'+\
'<!-- item "partition" describes a partition on the final image file-->\n'+\
'<!-- L "id" => Partition number on the final image (1 is the lowest number) -->\n'+\
'<!-- L "type" => Filesystem type of partition -->\n'+\
'<!-- L => ext[2-4], Linux, xfs, vfat, fat, none, raw, swap -->\n'+\
'<!-- L "size" => Partition size -->\n'+\
'<!-- L => <no>: Byte, <no>K: Kilobyte, <no>M: Megabyte or <no>G: Gigabyte -->\n'+\
'<!-- L => "*" dynamic file size => Size of the files2copy + offset -->\n'+\
'<!-- L "offset" => in case a dynamic size is used the offset value is added to file size-->\n'+\
'<!-- L "devicetree"=> compile the Linux Device (.dts) inside the partition if available (Top folder only)-->\n'+\
'<!-- L => Yes: Y or No: N -->\n'+\
'<!-- L "unzip" => Unzip a compressed file if available (Top folder only) -->\n'+\
'<!-- L => Yes: Y or No: N -->\n'+\
'<LinuxDistroBlueprint>\n'+\
'<partition id="1" type="vfat" size="*" offset="500M" devicetree="Y" unzip="N" ubootscript="arm" />\n'+\
'<partition id="2" type="ext3" size="*" offset="1M" devicetree="N" unzip="Y" ubootscript="" />\n'+\
'<partition id="3" type="RAW" size="*" offset="20M" devicetree="N" unzip="N" ubootscript="" />\n'+\
'</LinuxDistroBlueprint>\n'
#
# Run the bootloader filter script (Cyclone V)
#
# Cyclone V | Arria V | Arria 10
run_filter_script =[True, True, True]
qts_filter_script_name = ['qts-filter.sh','','qts-filter-a10.sh']
u_boot_bsp_qts_dir_list = ['/board/altera/cyclone5-socdk/qts/', '/board/altera/arria5-socdk/qts/', \
' ']
# SFP BootROM File for the RAW partition
sfp_inputflile_suffix = ['.sfp','','.bin']
#
# Name of the DeviceTree used by the primary bootloader (only Arria 10 SX)
#
preloader_deviceTree_name = ['','','socfpga_arria10_socdk_sdmmc.dtb']
#
# Generate the bootable SFP image file
# For the Intel Arria 10 SX is a ".img" file required
#
# Cyclone V | Arria V | Arria 10
generate_sfp_image_file = [True,True,False]
#
# "u-boot-socfpga deconfig" file name for make (u-boot-socfpga/configs/)
# Cyclone V | Arria V | Arria 10
u_boot_defconfig_list = ['socfpga_cyclone5_defconfig', 'socfpga_arria5_defconfig', \
'socfpga_arria10_defconfig']
# Cyclone V | Arria V | Arria 10
linaro_version_list = ['gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf','gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf',\
'gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf']
linaro_url_list = ['https://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/arm-linux-gnueabihf/'\
'gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz', \
'https://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/arm-linux-gnueabihf/'\
'gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz', \
'https://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/arm-linux-gnueabihf/'\
'gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz']
# Cyclone V | Arria V | Arria 10
gcc_toolchain_path_list= ['gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/:$PATH', \
'gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/:$PATH', \
'gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/:$PATH']
#
#
#
#
#
#
############################################ Github clone function ###########################################
#
#
#
import sys
if sys.platform =='linux':
try:
import git
from git import RemoteProgress
import wget
except ImportError as ex:
print('Msg: '+str(ex))
print('This Python Application requirers "git"')
print('Use following pip command to install it:')
print('$ pip3 install GitPython wget')
sys.exit()
if sys.platform =='linux':
# @brief to show process bar during github clone
#
#
class CloneProgress(RemoteProgress):
def update(self, op_code, cur_count, max_count=None, message=''):
if message:
sys.stdout.write("\033[F")
print(" "+message)
import os
import time
import io
import re
import shutil
import subprocess
import xml.etree.ElementTree as ET
from typing import NamedTuple
import math
import glob
from pathlib import Path
from datetime import datetime
from datetime import timedelta
import mmap
try:
from LinuxBootImageFileGenerator.LinuxBootImageGenerator import Partition,BootImageCreator
except ModuleNotFoundError as ex:
print('--> Cloning "LinuxBootImageFileGenerator" from GitHub')
print(' please wait...')
try:
git.Repo.clone_from(GIT_LINUXBOOTIMAGEGEN_URL, os.getcwd()+'/LinuxBootImageFileGenerator', branch='master', progress=CloneProgress())
except Exception as ex:
print('ERROR: The cloning failed! Error Msg.:'+str(ex))
sys.exit()
if not os.path.isabs(os.getcwd()+'/LinuxBootImageFileGenerator'):
print('ERROR: Failed to clone "LinuxBootImageFileGenerator"')
print(' Check your network connection and try it again')
sys.exit()
from LinuxBootImageFileGenerator.LinuxBootImageGenerator import Partition,BootImageCreator
#
# @brief Print a selection table that allows user to choose a item
# @param headline: Main headline that will be displayed in the top of the box
# @param headline_table: Headline of the table (column names)
# @param raw1: List of raw items of the column 1
# @param raw1: List of raw items of the column 2 (optional)
# @param selectionMode: Allow the user to select a item
# @param line_offset: Offset of a raw line
# @return Selected item by the user (0 = Error)
#
def printSelectionTable(headline=[], headline_table=[], raw1=[], raw2=[],
selectionMode=False,line_offset=10):
singleRaw = True
if len(raw1)==0 or len(headline_table)==0:
return 0
if raw2=='':
singleRaw = True
elif not len(raw2)==0:
singleRaw = False
if not singleRaw and len(headline_table)<1:
return 0
# Find longest sting in raws
max_raw_len =0
for raw1_it in raw1:
loc = len(raw1_it)
if loc > max_raw_len:
max_raw_len=loc
for head_it in headline_table:
loc = len(head_it)
if loc > max_raw_len:
max_raw_len=loc
if not singleRaw:
for raw2_it in raw2:
loc = len(raw2_it)
if loc > max_raw_len:
max_raw_len=loc
max_raw_len+=line_offset
### Print the top of the box
total_raw_len = max_raw_len
if not singleRaw:
total_raw_len *=2
total_raw_len+=10
filling='#'
print(' ')
for i in range(total_raw_len):
sys.stdout.write('#')
for i in range(total_raw_len-2):
filling+=' '
filling+='#'
line_sep = filling.replace(' ','-')
print('')
### Print the headline
if len(headline)>0:
for lin in headline:
lin2 =''
lin1 =''
if(len(lin)>total_raw_len-5):
lin1=lin[:total_raw_len-5]
lin2 = lin[total_raw_len-5:]
else:
lin1 = lin
print('# '+lin1.center(total_raw_len-3)+'#')
if lin2!='':
print('# '+lin2.center(total_raw_len-3)+'#')
print(filling)
print(line_sep)
### Print the table headline
sys.stdout.write('# '+' No. '+' '.center(3)+'|')
sys.stdout.write(headline_table[0].center(max_raw_len-(3 if singleRaw else 2)))
if not singleRaw:
sys.stdout.write('|'+headline_table[1].center(max_raw_len-2)+'#')
else:
sys.stdout.write('#')
print('')
# Print a line seperator
line_sep = filling.replace(' ','-')
print(line_sep)
### Print the content to the raws
# Find the number of iteams
no_it = len(raw1)
if not singleRaw and len(raw2) > no_it:
no_it = len(raw2)
# for loop for every raw
for i in range(no_it):
sys.stdout.write('# '+str(i+1).center(9)+'|')
if len(raw1)>=i:
item_len = len(raw1[i])+(3 if not singleRaw else 4)
sys.stdout.write(' '+raw1[i]+''.center(max_raw_len-item_len))
sys.stdout.write('|' if not singleRaw else '#')
else:
sys.stdout.write(''.center(max_raw_len-2)+'|')
if not singleRaw:
if len(raw2)>=i:
item_len = len(raw2[i])+3
sys.stdout.write(' '+raw2[i]+' '.center(max_raw_len-item_len)+'#')
else:
sys.stdout.write(''.center(max_raw_len-2)+'#')
print('')
print(line_sep)
# Print the selection interface
inp_val =0
if selectionMode:
st = '# Select a item by typing a number (1-'+str(no_it)+') [q=Abort]'
sys.stdout.write(st+' '.center(total_raw_len-len(st)-1)+'#')
print('')
while True:
inp = input('# Please input a number: $')
try:
inp_val = int(inp)
except Exception:
pass
if inp=='Q' or inp=='q':
print(' Aborting...')
sys.exit()
elif inp_val>0 and inp_val <(no_it+1):
st='# Your Selection: '+str(inp_val)
if len(raw1)>=inp_val-1:
st='# Your Selection: '+str(inp_val)+'" : "'+raw1[inp_val-1]+'"'
elif len(raw2)>=inp_val-1:
st='# Your Selection: '+str(inp_val)+'" : "'+raw2[inp_val-1]+'"'
sys.stdout.write(st+' '.center(total_raw_len-len(st)-1)+'#')
print('')
break
else:
st='# Wrong Input! Please try it agin!'
sys.stdout.write(st+' '.center(total_raw_len-len(st)-1)+'#')
print('')
### Print the bottom of the box
print(filling)
for i in range(total_raw_len):
sys.stdout.write('#')
print('\n')
if selectionMode:
return inp_val
return 1
#
#
# @brief Class for automatisation the entry bootable Linux Distribution generation
# for Intel SoC-FPGAs
#
class SocfpgaPlatformGenerator:
EDS_Folder_dir : str # Directory of the Intel EDS folder
Quartus_proj_top_dir : str # Directory of the Quartus Project folder
Qpf_file_name : str # Name of the Quartus Project ".qpf"-file
Sof_file_name : str # Name of the Quartus Project ".sof"-file
sopcinfo_file_name : str # Name of the Quartus Project ".sopcinfo"-file
Qsys_file_name : str # Name of the Quartus Project ".qsys"-file
Handoff_folder_name : str # Name of the Quartus Project Hand-off folder
UbootSFP_default_preBuild_dir : str # Directory of the pre-build u-boot for the device
Quartus_bootloder_dir : str # Directory of the Quartus Project "/software/bootloader"-folder
Sof_folder : str # Name of the Quartus Project folder containing the ".sof"-file
U_boot_socfpga_dir : str # Directory of u-boot SoC-FPGA folder
Uboot_default_file_dir : str # Directory of the pre-build default u-boot file
unlicensed_ip_found : bool# Quartus project contains an unlicensed IP (e.g. NIOS II Core)
Device_id : int # SocFPGA ID (0: Cyclone V; 1: Arria V;2: Arria 10)
PartitionList : Partition # Partition List for boot image generation
Raw_folder_dir : str # Directory of the RAW Partition folder (u-boot)
Vfat_folder_dir : str # Directory of the VFAT Partition folder
Ext_folder_dir : str # Directory of the EXT3 Partition folder (rootfs)
Socfpga_devices_list = ['cyclone5', 'arria5', 'arria10' ]
Socfpga_arch_list = ['arm', 'arm', 'arm']
OutputZipFileName : str # Name of the output ".zip" compressed image file
ImageFileName : str # Name of the output ".img" image file
Bootloader_available : bool # Is a bootloader executable available
BootImageCreator : BootImageCreator # The boot Image generator object
def __init__(self):
######################################### Find the Intel EDS Installation Path ####################################
print('--> Find the System Platform')
EDS_Folder_def_suf_dir = os.path.join(os.path.join(os.path.expanduser('~'))) + '/'
# 1.Step: Find the EDS installation path
print('--> Try to find the default Intel EDS 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(EDS_Folder_def_suf_dir+QURTUS_DEF_FOLDER)) and (not quartus_standard_ver):
self.EDS_Folder=EDS_Folder_def_suf_dir+QURTUS_DEF_FOLDER
quartus_standard_ver = True
elif(os.path.exists(EDS_Folder_def_suf_dir+QURTUS_DEF_FOLDER_LITE)):
self.EDS_Folder=EDS_Folder_def_suf_dir+QURTUS_DEF_FOLDER_LITE
quartus_standard_ver = False
else:
print('ERROR: No Intel EDS Installation Folder was found!')
sys.exit()
# 2.Step: Find the latest Intel EDS Version No.
avlVer = []
for name in os.listdir(self.EDS_Folder):
if os.path.abspath(name):
try:
avlVer.append(float(name))
except Exception:
pass
if (len(avlVer)==0):
print('ERROR: No valid Intel EDS Version was found')
sys.exit()
avlVer.sort(reverse = True)
highestVer = avlVer[0]
self.EDS_Folder = self.EDS_Folder +'/'+ str(highestVer)
if (not(os.path.realpath(self.EDS_Folder))):
print('ERROR: No valid Intel EDS Installation Folder was found!')
sys.exit()
if(highestVer < 19):
print('ERROR: This script is designed for Intel EDS Version 19+ (19.1, 20.1, ...) ')
print(' You using Version '+str(highestVer)+' please update Intel EDS!')
sys.exit()
elif(highestVer > 20.1):
print('WARNING: This script was designed for Intel EDS Version 19.1 and 20.1')
print(' Your version is newer. Errors may occur!')
# Check if the NIOS II Command Shell is available
if((not(os.path.isfile(self.EDS_Folder+EDS_EMBSHELL_DIR)) )):
if( not quartus_standard_ver):
print('ERROR: Intel EDS Embedded Command Shell was not found!')
sys.exit()
else:
break
print(' Following EDS Installation Folder was found:')
print(' '+self.EDS_Folder)
############################### Check that the script runs inside the Github folder ###############################
print('--> Check that the script runs inside the Github folder')
self.Quartus_proj_top_dir =''
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('/',slashpos)
if(slashpos_pos == -1):
break
slashpos= slashpos_pos+len('/')
if(not excpath[slashpos:].upper() == GITNAME.upper()):
raise Exception()
self.Quartus_proj_top_dir = excpath[:slashpos-1]
self.UbootSFP_default_preBuild_dir=''
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()
if not os.path.isdir(excpath+'/ubootScripts'):
print('ERROR: The u-boot default script folder "ubootScripts" is not available')
############################### Check that the script runs inside the Quartus project ###############################
print('--> Check that the script runs inside the Quartus Prime project folder')
# Find the Quartus project (.qpf) file
self.Qpf_file_name = ''
for file in os.listdir(self.Quartus_proj_top_dir):
if ".qpf" in file:
self.Qpf_file_name =file
break
self.sopcinfo_file_name = ''
for file in os.listdir(self.Quartus_proj_top_dir):
if ".sopcinfo" in file:
self.sopcinfo_file_name =file
break
# Find the Quartus (.sof) (SRAM Object) file
self.Sof_file_name = ''
self.Sof_folder = ''
# Looking in the top folder for the sof file
for file in os.listdir(self.Quartus_proj_top_dir):
if ".sof" in file:
self.Sof_file_name =file
break
if self.Sof_file_name == '':
# Looking inside the "output_files" and "output" folders
if os.path.isdir(self.Quartus_proj_top_dir+'/output_files'):
self.Sof_folder = '/output_files'
if os.path.isdir(self.Quartus_proj_top_dir+'/output'):
self.Sof_folder = '/output'
for file in os.listdir(self.Quartus_proj_top_dir+self.Sof_folder):
if ".sof" in file:
self.Sof_file_name =file
break
# Find the Platform Designer (.qsys) file
self.Qsys_file_name = ''
for file in os.listdir(self.Quartus_proj_top_dir):
if ".qsys" in file and not ".qsys_edit" in file:
self.Qsys_file_name =file
print(self.Qsys_file_name)
break
print(' Founded files: ')
print(' QPF: "'+self.Qpf_file_name+'"')
print(' SOF: "'+self.Sof_file_name+'"')
print(' QSYS: "'+self.Qsys_file_name+'"')
print(' SOPCINFO: "'+self.sopcinfo_file_name+'"')
# Does the SOF file contains an IP with a test licence, such as a NIOS II Core?
self.unlicensed_ip_found=False
if self.Sof_file_name.find("_time_limited")!=-1:
print('********************************************************************************')
print('* Unlicensed IP inside the project found! *')
print('* Generation of ".rbf" file is not possible! *')
print('********************************************************************************\n')
self.unlicensed_ip_found=True
# Find the Platform Designer folder
if self.Qsys_file_name=='' or self.Qpf_file_name=='' or self.Sof_file_name=='':
print('\nERROR: The script was not executed inside the cloned Github- and Quartus Prime project folder!')
print(' Please clone this script with its folder from Github,')
print(' copy it to the top folder of your Quartus project and execute the script')
print(' directly inside the cloned folder!')
print(' NOTE: Be sure that the QPF,SOF and QSYS folder was found!')
print(' These files must be in the top project folder')
print(' The SOF file can also be inside a sub folder with the name "output_files" and "output"')
print(' URL: '+GIT_SCRIPT_URL+'\n')
print(' --- Required folder structure ---')
print(' YOUR_QURTUS_PROJECT_FOLDER ')
print(' | L-- PLATFORM_DESIGNER_FOLDER')
print(' | L-- platform_designer.qsys')
print(' | L-- _handoff')
print(' | L-- quartus_project.qpf')
print(' | L-- socfpgaPlatformGenerator <<<----')
print(' | L-- socfpgaPlatformGenerator.py')
print(' Note: File names can be chosen freely\n')
print('NOTE: It is necessary to build the Prime Quartus Project for the bootloader generation!')
sys.exit()
# Find the handoff folder
print('--> Find the Quartus handoff folder')
self.Handoff_folder_name = ''
handoff_folder_start_name =''
for file in os.listdir(self.Quartus_proj_top_dir):
if "_handoff" in file:
handoff_folder_start_name =file
break
folder_found = False
for folder in os.listdir(self.Quartus_proj_top_dir+'/'+handoff_folder_start_name):
if os.path.isdir(self.Quartus_proj_top_dir+'/'+handoff_folder_start_name+'/'+folder):
self.Handoff_folder_name = folder
if folder_found:
print('ERROR: More than one folder inside the Quartus handoff folder "'+self.Handoff_folder_name+'" found! Please delete one!')
print('NOTE: It is necessary to build the Prime Quartus Project for the bootloader generation!')
sys.exit()
folder_found = True
self.Handoff_folder_name = handoff_folder_start_name+'/'+self.Handoff_folder_name
print(' Handoff folder:" '+self.Handoff_folder_name+'"')
# Find the "hps.xml"-file inside the handoff folder
print('--> Find the "hps.xml" file ')
handoff_xml_found =False
for file in os.listdir(self.Quartus_proj_top_dir+'/'+self.Handoff_folder_name):
if "hps.xml" == file:
handoff_xml_found =True
break
if not handoff_xml_found:
print('ERROR: The "hps.xml" file inside the handoff folder was not found!')
print('NOTE: It is necessary to build the Prime Quartus Project for the bootloader generation!')
sys.exit()
# Load the "hps.xml" file to read the device name
print('--> Read the "hps.xml"-file to decode the device name')
try:
tree = ET.parse(self.Quartus_proj_top_dir+'/'+self.Handoff_folder_name+'/'+'hps.xml')
root = tree.getroot()
except Exception as ex:
print(' ERROR: Failed to parse "hps.xml" file!')
print(' Msg.: '+str(ex))
sys.exit()
device_name_temp =''
for it in root.iter('config'):
name = str(it.get('name'))
if name == 'DEVICE_FAMILY':
device_name_temp = str(it.get('value'))
break
if device_name_temp == '':
print('ERROR: Failed to decode the device name inside "hps.xml"')
# Convert Device name
if device_name_temp == 'Cyclone V':
self.Device_id = 0
'''
elif device_name_temp == 'Arria V':
self.Device_id = 1
'''
elif device_name_temp == 'Arria 10':
self.Device_id = 2
## NOTE: ADD ARRIA V/ SUPPORT HERE
else:
print('Error: Your Device ('+device_name_temp+') is not supported right now!')
print(' I am working on it...')
sys.exit()
print(' Device Name:"'+device_name_temp+'"')
# For Arria 10 SX: The early I/O release must be enabled inside Quartus Prime!
early_io_mode =-1
if self.Device_id == 2:
for it in root.iter('config'):
name = str(it.get('name'))
if name == 'chosen.early-release-fpga-config':
early_io_mode = int(it.get('value'))
break
if not early_io_mode==1:
print('ERROR: This build system supports only the Arria 10 SX SoC-FPGA')
print(' with the Early I/O release feature enabled!')
print(' Please enable Early I/O inside the Quartus Prime project settings')
print(' and rebuild the project again')
print('Setting: "Enables the HPS early release of HPS IO" inside the general settings')
print('Note: Do not forget to enable it for the EMIF')
sys.exit()
else:
print('--> HPS early release of HPS IO is enabled')
self.Uboot_default_file_dir =''
# Find the depending default u-boot script file
for name in os.listdir(excpath+'/ubootScripts'):
if os.path.isfile(excpath+'/ubootScripts/'+name) and \
(name.find(self.Socfpga_devices_list[self.Device_id])!=-1):
self.Uboot_default_file_dir=excpath+'/ubootScripts/'+name
if self.Uboot_default_file_dir =='':
print('NOTE: No depending default u-boot script file is available for this device!')
# Find the depending default pre-build u-boot or SFP file
self.UbootIMG_default_preBuild_dir =''
# For the Cyclone V, Arria V and the Arria 10 SX
for name in os.listdir(excpath+'/ubootDefaultSFP'):
# Find the default u-boot ".spl" executable for the Cyclone V
if os.path.isfile(excpath+'/ubootDefaultSFP/'+name) and \
name.find(self.Socfpga_devices_list[self.Device_id])!=-1:
if name.endswith(sfp_inputflile_suffix[self.Device_id]):
self.UbootSFP_default_preBuild_dir=excpath+'/ubootDefaultSFP/'+name
if self.UbootSFP_default_preBuild_dir =='':
print('NOTE: No depending default SFP u-boot pre-build file is available for this device!')
if not generate_sfp_image_file[self.Device_id]:
# Only for the Arria 10 SX:
for name in os.listdir(excpath+'/ubootDefaultIMG'):
# Find the u-boot .img executable for other devices
if os.path.isfile(excpath+'/ubootDefaultIMG/'+name) and \
(name.find(self.Socfpga_devices_list[self.Device_id])!=-1):
self.UbootIMG_default_preBuild_dir=excpath+'/ubootDefaultIMG/'+name
if self.UbootIMG_default_preBuild_dir =='':
print('NOTE: No depending default u-boot.img Image pre-build file is available for this device!')
##################################### Update "LinuxBootImageFileGenerator" ####################################################
print('-> Pull the latest "LinuxBootImageFileGenerator" Version from GitHub!')
g = git.cmd.Git(os.getcwd()+'/LinuxBootImageFileGenerator')
g.pull()
############################### Create "software/bootloader" folder inside Quartus project ###################################
if not os.path.isdir(self.Quartus_proj_top_dir+'/'+'software'):
print('--> Create the folder software')
try:
os.mkdir(self.Quartus_proj_top_dir+'/'+'software')
except Exception as ex:
print('ERROR: Failed to create the software folder MSG:'+str(ex))
self.Quartus_bootloder_dir = self.Quartus_proj_top_dir+'/'+'software'+'/'+'bootloader'
self.Bootloader_available =False
if not os.path.isdir(self.Quartus_bootloder_dir):
print('--> Create the folder bootloader')
try:
os.mkdir(self.Quartus_bootloder_dir)
except Exception as ex:
print('ERROR: Failed to create the bootloader folder MSG:'+str(ex))
else:
self.Bootloader_available = True
self.U_boot_socfpga_dir = self.Quartus_bootloder_dir+'/'+'u-boot-socfpga'
############################################### Create SD-CARD folder ##############################################
# Create the partition blueprint xml file
if os.path.exists('SocFPGABlueprint.xml'):
# Check that the SocFPGABlueprint XML file looks valid
print('---> The Linux Distribution blueprint XML file exists')
else:
print(' ---> Creating a new Linux Distribution blueprint XML file')
with open('SocFPGABlueprint.xml',"w") as f:
f.write(INTELSOCFPGA_BLUEPRINT_XML_FILE)
#
#
#
# @brief Create the partition table for Intel SoC-FPGAs by reading the "SocFPGABlueprint" XML-file
# @return success
#
def GeneratePartitionTable(self):
############################################ Read the XML Blueprint file ###########################################
####################################### & Process the settings of a partition ####################################
print('---> Read the XML blueprint file ')
try:
tree = ET.parse('SocFPGABlueprint.xml')
root = tree.getroot()
except Exception as ex:
print(' ERROR: Failed to parse SocFPGABlueprint.xml file!')
print(' Msg.: '+str(ex))
return False
# Load the partition table of XML script
print('---> Load the items of XML file ')
self.PartitionList= []
for part in root.iter('partition'):
try:
id = str(part.get('id'))
type = str(part.get('type'))
size = str(part.get('size'))
offset = str(part.get('offset'))
devicetree = str(part.get('devicetree'))
unzip_str = str(part.get('unzip'))
comp_ubootscr = str(part.get('ubootscript'))
except Exception as ex:
print(' ERROR: XML File decoding failed!')
print(' Msg.: '+str(ex))
return False
comp_devicetree =False
if devicetree == 'Y' or devicetree == 'y':
comp_devicetree = True
unzip =False
if unzip_str == 'Y' or unzip_str == 'y':
unzip = True
try:
self.PartitionList.append(Partition(True,id,type,size,offset,comp_devicetree,unzip,comp_ubootscr))
except Exception as ex:
print(' ERROR: Partition data import failed!')
print(' Msg.: '+str(ex))
return False
####################################### Check if the partition folders are already available #######################################
# Generate working folder names for every partition
working_folder_pat = []
for part in self.PartitionList:
working_folder_pat.append(part.giveWorkingFolderName(True))
create_new_folders = True
# Check if the primary partition folder exists
if os.path.isdir(IMAGE_FOLDER_NAME):
if not len(os.listdir(IMAGE_FOLDER_NAME)) == 0:
# Check that all partition folders exist
for file in os.listdir(IMAGE_FOLDER_NAME):
if not file in working_folder_pat:
print('ERROR: The existing "'+IMAGE_FOLDER_NAME+'" Folder is not compatible with this configuration!')
print(' Please delete or rename the folder "'+IMAGE_FOLDER_NAME+'" to allow the script')
print(' to generate a matching folder structure for your configuration')
return False
create_new_folders = False
else:
try:
os.makedirs(IMAGE_FOLDER_NAME)
except Exception as ex:
print(' ERROR: Failed to create the image import folder on this directory!')
print(' Msg.: '+str(ex))
return False
###################################### Create new import folders for every partition #######################################
if create_new_folders:
for folder in working_folder_pat:
try:
os.makedirs(IMAGE_FOLDER_NAME+'/'+folder)
except Exception as ex:
print(' ERROR: Failed to create the partition import folder on this directory!')
print(' Msg.: '+str(ex))
return False
################################### Check that all required Partitions are available ####################################
self.Raw_folder_dir =''
self.Vfat_folder_dir=''
self.Ext_folder_dir=''
excpath = os.getcwd()
for part in self.PartitionList:
if part.type_hex=='a2':
self.Raw_folder_dir=excpath+'/'+IMAGE_FOLDER_NAME+'/'+part.giveWorkingFolderName(False)
elif part.type_hex=='b': # FAT
self.Vfat_folder_dir=excpath+'/'+IMAGE_FOLDER_NAME+'/'+part.giveWorkingFolderName(False)
if not part.comp_devicetree:
print('NOTE: The devicetree compilation is for the VFAT/FAT partition not enabled!')
print(' The script may not work properly!')
if not part.comp_ubootscript == self.Socfpga_arch_list[self.Device_id]:
print('NOTE: Compilation of the u-boot script is for the ext3/LINUX partition\n'+ \
' is not enabled or the wrong architecture is selected!\n'+ \
' Use: ubootscript="'+self.Socfpga_arch_list[self.Device_id]+'"')
print(' The script may not work properly!')
elif part.type_hex=='83': # LINUX
self.Ext_folder_dir=excpath+'/'+IMAGE_FOLDER_NAME+'/'+part.giveWorkingFolderName(False)
if not part.unzip_file:
print('NOTE: Unzip is for the ext3/LINUX partition not enabled!')
print(' The script may not work properly!')
# All folders there ?
if self.Raw_folder_dir =='':
print('ERROR: The chosen partition table has now RAW/NONE-partition.')
print(' That is necessary for the bootloader')
return False
if self.Vfat_folder_dir =='':
print('ERROR: The chosen partition table has now VFAT-partition.')
print(' That is necessary for the Kernel image')
return False
if self.Ext_folder_dir =='':
print('ERROR: The chosen partition table has now EXT-partition.')
print(' That is necessary for the rootfs')
return False
return True
#
#
#
# @brief Build the bootloader for the chosen Intel SoC-FPGA
# and copy the output files to the depending partition folders
# @param generation_mode 0: The User can chose how the bootloader should be build
# 1: Allways build or re-build the entire bootloader
# 2: Build the entire bootloader in case it was not done
# 3: Use the default pre-build bootloader for the device
# @return success
#
def BuildBootloader(self, generation_mode= 0):
#################################### Setup u-boot with the Quartus Prime Settings ################################################
bootloader_build_required =True
use_default_bootloader = False
excpath = os.getcwd()
if (self.Bootloader_available and os.path.isfile(self.Raw_folder_dir+'/'+BOOTLOADER_FILE_NAME)\
and generate_sfp_image_file[self.Device_id]):
bootloader_build_required = False
# Check that the SFP output file is avalibile
if (not os.path.isfile(self.U_boot_socfpga_dir+'/spl/'+SFP_OUTPUT_FILE_NAME)) and \
generate_sfp_image_file[self.Device_id]:
bootloader_build_required = False
if generation_mode==1:
# Allways build or re-build the entire bootloader
bootloader_build_required=True
elif generation_mode==2:
# Use the default pre-build bootloader for the device
bootloader_build_required =False
use_default_bootloader = True
elif generation_mode==0:
#The User can chose how the bootloader should be build
headline = ['Bootloader Generation Selection']
headline_table=['Task']
headline_content=[]
if (not self.UbootIMG_default_preBuild_dir =='' and self.Device_id==2) or \
(not self.UbootSFP_default_preBuild_dir=='' and self.Device_id==0):
headline_content.append('Use the pre-build default bootloader')
headline_content.append('Build/Rebuild the bootloader')
if not bootloader_build_required:
headline_content.append('Continue without rebuilding the bootloader')
BootSelchoose = printSelectionTable(headline,headline_table,headline_content,[],True,20)
bootloader_build_required = True
use_default_bootloader =False
if BootSelchoose==1 and \
(not self.UbootIMG_default_preBuild_dir =='' or not self.UbootSFP_default_preBuild_dir ==''):
use_default_bootloader = True
bootloader_build_required=False
# Find the RAW Partition and
self.Raw_folder_dir =''
for part in self.PartitionList:
if part.type_hex=='a2':
self.Raw_folder_dir=excpath+'/'+IMAGE_FOLDER_NAME+'/'+part.giveWorkingFolderName(False)
if part.type_hex=='b':
self.Vfat_folder_dir=excpath+'/'+IMAGE_FOLDER_NAME+'/'+part.giveWorkingFolderName(False)
if self.Raw_folder_dir =='':
print('ERROR: The chosen partition table has no RAW/NONE-partition.')
print(' That is necessary for the bootloader')
return False
if self.Vfat_folder_dir =='' and generate_sfp_image_file[self.Device_id]:
print('ERROR: The chosen partition table no VFAT/FAT32 partition.')
print(' That is necessary for the bootloader')
return False
############################################ Use the default pre-build bootloader ################################################
if use_default_bootloader:
print('--> Use the default pre-build bootloader')
if not os.path.isdir(excpath+'/ubootDefaultSFP'):
print('ERROR: The u-boot default pre-build folder "ubootDefaultSFP" is not available')
return False
if not os.path.isdir(excpath+'/ubootDefaultIMG') and self.Device_id==2:
print('ERROR: The u-boot default pre-build folder "ubootDefaultIMG" is not available')
return False
if self.UbootSFP_default_preBuild_dir =='':
print('ERROR: It was no ".sft" or ".bin" bootloader file found inside the "ubootDefaultSFP" folder!')
return False
try:
# Only for the Arria 10 SX:
if not generate_sfp_image_file[self.Device_id]:
# Copy the SFP BootROM File to the RAW
shutil.copy2(self.UbootSFP_default_preBuild_dir,
self.Raw_folder_dir+'/'+SFP_OUTPUT_FILE_NAME)
# Copy the u-boot image to the VFAT partition
shutil.copy2(self.UbootIMG_default_preBuild_dir,
self.Vfat_folder_dir+'/'+U_BOOT_IMAGE_FILE_NAME)
else:
# For other devices: Copy the u-boot exe