-
Notifications
You must be signed in to change notification settings - Fork 42
/
bif.y
executable file
·743 lines (629 loc) · 47.6 KB
/
bif.y
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
/******************************************************************************
* Copyright 2015-2022 Xilinx, Inc.
* Copyright 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.
* You may obtain a copy of the License 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.
******************************************************************************/
/* BIF (Boot Image Format)
* Use bison to process this file into bif.tab.cpp
*/
%require "2.7"
%skeleton "lalr1.cc"
%defines
%define namespace "BIF"
%define parser_class_name "BisonParser"
%parse-param { BIF::FlexScanner& scanner }
%parse-param { Options& options}
%lex-param { BIF::FlexScanner& scanner }
%locations
%initial-action
{
// Initialize the initial location.
@$.begin.filename = @$.end.filename = &scanner.filename;
};
%code requires {
namespace BIF {
class BisonScanner;
class FlexScanner;
class Parser;
}
#include "bootimage.h"
#include "bifoptions.h"
}
%code {
static int yylex(BIF::BisonParser::semantic_type * yylval, BIF::BisonParser::location_type* loc, BIF::FlexScanner &scanner);
#include "options.h"
}
%{
#include <stdio.h>
#include "bootimage.h"
#include "authentication.h"
#include "encryption.h"
#include "checksum.h"
#include "bifscanner.h"
#include "parsing.h"
#include "imageheadertable-versal.h"
BifOptions* currentBifOptions;
PartitionBifOptions* currentPartitionBifOptions ;
ImageBifOptions* currentImageBifOptions;
%}
%start bif
%union
{
uint32_t token;
uint64_t number;
char *string;
Authentication::Type authvalue_t;
Encryption::Type encrvalue_t;
KeySource::Type encrkeysrc_t;
Core::Type core_t;
BhRsa::Type bhrsa_t;
AuthHash::Type authhash_t;
PufHdLoc::Type pufhdloc_t;
OptKey::Type optkey_t;
AuthOnly::Type authonly_t;
BootDevice::Type bootdevice_t;
DestinationDevice::Type destdevice_t;
DestinationCPU::Type destcpu_t;
Checksum::Type checksumvalue_t;
PartitionOwner::Type powner_t;
PartitionType::Type ptype_t;
ExceptionLevel::Type el_t;
SplitMode::Type splitmode_t;
TrustZone::Type trustzone_t;
BifOptions* bifoptions;
PartitionBifOptions* partitionBifOptions;
DpaCM::Type dpacm_t;
SpkSelect::Type spkselect_t;
}
%token OBRACE EBRACE
%token COMMA EQUAL COLON QUOTE SEMICOLON
%token OBRACKET EBRACKET
%token BOOTLOADER XIP_MODE EARLY_HANDOFF HIVEC LOCKSTEP
%token AUTHENTICATION ENCRYPTION CHECKSUM
%token PARTITION_OWNER PARTITION_TYPE PARTITION_NUM
%token BOOT_DEVICE DEST_DEVICE DEST_CPU ADDRESS
%token EXCEPTION_LEVEL TRUSTZONE
%token ALIGNMENT OFFSET RESERVE_LEGACY RESERVE LOAD STARTUP BIGENDIAN A32_MODE
%token PPK_SELECT SPK_ID SPK_SELECT HEADER_AUTH REVOKE_ID
%token SPLIT_MODE SPLIT_FMT
%token BOOT USER STATIC NOAUTOSTART MULTIBOOT PROTECTED
%token BLOCKS AUTHBLOCKS BOOTVECTORS
%token PRESIGN BIF_SECTION
%token UDF_DATA
%token MCS BIN
%token SLR_NUM CLUSTER_NUM DICE PCR_NUMBER PCR_MEASUREMENT_INDEX IMAGE_STORE
%token PARENT_ID ID_CODE EXT_ID_CODE BYPASS_IDCODE_CHECK A_HWROT S_HWROT UNIQUE_ID PARENT_UNIQUE_ID FUNCTION_ID
%token IMAGE ID NAME DELAY_HANDOFF DELAY_LOAD COPY INCLUDE DELAY_AUTH
%token PARTITION PFILE OPTIONAL_DATA
%token METAHEADER
%token TCM_BOOT TCM_A_REGION TCM_B_REGION TCM_C_REGION
%token <string> WORD HEXWORD
%token <string> FILENAME QFILENAME
%token <number> NONE
%token <number> DECVALUE HEXVALUE
%token <number> KEYSRC_ENCRYPTION FSBL_CONFIG AUTH_PARAMS
%token <number> AUTHJTAG_CONFIG DEVICE_DNA JTAG_TIMEOUT
%token <number> PUF4KMODE PUFROSWAP SHUTTER SPLIT SMAP_WIDTH
%token <number> PUF_HELPER_FILE BH_KEY_FILE BH_KEY_IV
%token <number> BH_KEK_IV BBRAM_KEK_IV EFUSE_KEK_IV EFUSE_USER_KEK0_IV EFUSE_USER_KEK1_IV USER_KEYS
%token <number> PMCDATA BOOTIMAGE UDF_BH INIT PMUFW_IMAGE
%token <number> AES_KEY_FILE FAMILY_KEY
%token <number> PPK_FILE PSK_FILE SPK_FILE SSK_FILE
%token <number> SPK_SIGNATURE_FILE BH_SIGNATURE_FILE HEADER_SIGNATURE_FILE
%token <authvalue_t> AUTHVALUE
%token <encrvalue_t> ENCRVALUE
%token <checksumvalue_t> CHECKSUMVALUE
%token <powner_t> POWNERVALUE
%token <ptype_t> PTYPEVALUE
%token <encrkeysrc_t> KEY_SRC
%token <core_t> CORE
%token <bhrsa_t> BH_RSA
%token <authhash_t> AUTH_HASH
%token <inthash_t> INT_HASH
%token <pufhdloc_t> PUFHD_LOC
%token <optkey_t> OPT_KEY
%token <authonly_t> AUTH_ONLY
%token <bootdevice_t> BOOT_DEVICE_TYPE
%token <destdevice_t> DEST_DEVICE_TYPE
%token <destcpu_t> DEST_CPU_TYPE
%token <el_t> EXCEPTION_LEVEL_TYPE
%token <trustzone_t> TRUSTZONE_TYPE
%token <splitmode_t> SPLITMODE
%token <dpacm_t> DPA_CM
%token <spkselect_t> SPKSELECT
%token OR XOR AND MULT DIVIDE MODULO PLUS MINUS LSHIFT RSHIFT
%left OR XOR AND MULT DIVIDE MODULO PLUS MINUS LSHIFT RSHIFT
%token NEGATION
%right NEGATION
%token LPAREN RPAREN ASTERISK
%right LPAREN
%left RPAREN
%left EQUAL
%type <string> filename
%type <number> number key_file rsa_key_file other_spec other_files other_file_attr
%type <authvalue_t> authvalue
%type <encrvalue_t> encrvalue
%type <checksumvalue_t> checkvalue
%type <powner_t> pownervalue
%type <ptype_t> ptypevalue
%type <encrkeysrc_t> key_src
%type <core_t> core
%type <bhrsa_t> bh_rsa
%type <authhash_t> auth_hash
%type <inthash_t> int_hash
%type <pufhdloc_t> pufhd_loc
%type <optkey_t> opt_key
%type <authonly_t> auth_only
%type <bootdevice_t> boot_device_type
%type <destdevice_t> dest_device_type
%type <destcpu_t> dest_cpu_type
%type <el_t> exception_level_type
%type <splitmode_t> splitmode
%type <spkselect_t> spkselect
%type <number> expression multiplicative_expression unary_expression additive_expression shift_expression
%type <number> and_expression xor_expression
%type <bifoptions> bifoptions
%type <dpacm_t> dpa_cm
%%
bif : group_list;
group_list : /* empty */
| group_list bifoptions
;
bifoptions : INCLUDE COLON filename { options.includeBifOptionsList.push_back($3); }
| WORD { currentBifOptions = new BifOptions(options.GetArchType(),$1); }
COLON
OBRACE file_list EBRACE { options.bifOptions = currentBifOptions;
options.bifOptionsList.push_back(currentBifOptions); }
;
file_list : /* empty */
| file_list file_spec
| file_list other_spec
| file_list image_spec
| file_list metahdr_spec
| file_list new_pdi_spec
| file_list new_file_spec
| file_list partition_spec
;
metahdr_spec : METAHEADER OBRACE { currentPartitionBifOptions = new PartitionBifOptions();
currentPartitionBifOptions->SetArchType(options.GetArchType(), options.IsVersalNetSeries()); }
metahdr_attr_list EBRACE
;
metahdr_attr_list : metahdr_attr
| metahdr_attr COMMA metahdr_attr_list
| metahdr_attr metahdr_attr_list
;
metahdr_attr : /* empty */
| ENCRYPTION EQUAL encrvalue { currentBifOptions->SetMetaHeaderEncryptType($3); }
| KEYSRC_ENCRYPTION EQUAL key_src { currentBifOptions->SetMetaHeaderEncryptionKeySource($3, options.IsVersalNetSeries()); }
| AES_KEY_FILE EQUAL filename { currentBifOptions->SetMetaHeaderEncryptionKeyFile($3); }
| AUTHENTICATION EQUAL authvalue { currentBifOptions->SetMetaHeaderAuthType($3); }
| PPK_FILE EQUAL filename { currentBifOptions->metaHdrAttributes.ppk = $3; }
| PSK_FILE EQUAL filename { currentBifOptions->metaHdrAttributes.psk = $3; }
| SPK_FILE EQUAL filename { currentBifOptions->metaHdrAttributes.spk = $3; }
| SSK_FILE EQUAL filename { currentBifOptions->metaHdrAttributes.ssk = $3; }
| SPK_SIGNATURE_FILE EQUAL filename { currentBifOptions->metaHdrAttributes.spkSignature = $3; }
| PRESIGN EQUAL filename { currentBifOptions->metaHdrAttributes.presign = $3; }
| REVOKE_ID EQUAL expression { currentBifOptions->metaHdrAttributes.revokeId = $3; }
| CHECKSUM EQUAL checkvalue { currentBifOptions->metaHdrAttributes.checksum = $3; }
| DPA_CM { currentBifOptions->metaHdrAttributes.dpaCM = DpaCM::DpaCMEnable; }
| BLOCKS EQUAL metahdr_blk
| PUFHD_LOC { currentBifOptions->metaHdrAttributes.pufHdLoc = PufHdLoc::PUFinBH;
currentBifOptions->SetPufHdinBHFlag();}
;
optional_data : optional_data_attr
| optional_data_attr SEMICOLON optional_data
;
optional_data_attr : filename COMMA ID EQUAL expression { currentBifOptions->metaHdrAttributes.ihtOptionalDataInfo.push_back(std::pair<std::string, uint32_t>($1, $5)); }
|
metahdr_blk : metahdr_blk_attr
| metahdr_blk_attr SEMICOLON metahdr_blk
;
metahdr_blk_attr : expression { currentPartitionBifOptions->SetEncryptionBlocks($1);
currentBifOptions->metaHdrAttributes.encrBlocks = currentPartitionBifOptions->GetEncryptionBlocks(); }
| expression LPAREN expression RPAREN { currentPartitionBifOptions->SetEncryptionBlocks($1, $3);
currentBifOptions->metaHdrAttributes.encrBlocks = currentPartitionBifOptions->GetEncryptionBlocks(); }
| expression LPAREN ASTERISK RPAREN { currentPartitionBifOptions->SetEncryptionBlocks($1, 0);
currentBifOptions->metaHdrAttributes.defEncrBlockSize = $1; }
;
new_pdi_spec : ID EQUAL expression { currentBifOptions->SetPdiId($3); }
| PARENT_ID EQUAL expression { currentBifOptions->SetParentId($3); }
| ID_CODE EQUAL expression { currentBifOptions->SetIdCode($3); }
| EXT_ID_CODE EQUAL expression { currentBifOptions->SetExtendedIdCode($3); }
| other_file_attr EQUAL filename { currentBifOptions->AddFiles($1, $3); }
| KEYSRC_ENCRYPTION EQUAL key_src { currentBifOptions->SetEncryptionKeySource($3); }
| PARTITION_TYPE EQUAL ptypevalue { currentBifOptions->SetPdiType($3); }
| REVOKE_ID EQUAL expression { currentBifOptions->SetRevokeId($3);}
;
image_spec : image_list
| image_spec image_list
;
image_list : IMAGE OBRACE { currentImageBifOptions = new ImageBifOptions(); }
image_content EBRACE { currentBifOptions->imageBifOptionList.push_back(currentImageBifOptions); }
;
image_content : /* empty */
| image_content image_attributes_list
| image_content file_spec
| image_content partition_spec
;
image_attributes_list : image_attributes
| image_attributes COMMA image_attributes_list
| image_attributes image_attributes_list
;
image_attributes : ID EQUAL expression { currentImageBifOptions->SetImageId($3); }
| NAME EQUAL WORD { currentImageBifOptions->SetImageName($3); }
| DELAY_HANDOFF { currentImageBifOptions->SetDelayHandoff(true); }
| DELAY_LOAD { currentImageBifOptions->SetDelayLoad(true); }
| INIT { LOG_ERROR("BIF attribute error !!!\n\t This usage of 'init' is not supported. See 'bootgen -bif_help init' for usage details."); }
| COPY EQUAL expression { LOG_ERROR("Copy to Memory feature with the attribute 'copy' is no more supported.\n\t This can be duplicated with the option 'imagestore'. Please refer UG1283 for more details.");
currentImageBifOptions->SetMemCopyAddress($3); }
| PARTITION_TYPE EQUAL ptypevalue { currentImageBifOptions->SetImageType($3); }
| UNIQUE_ID EQUAL expression { currentImageBifOptions->SetUniqueId($3); }
| PARENT_UNIQUE_ID EQUAL expression { currentImageBifOptions->SetParentUniqueId($3); }
| FUNCTION_ID EQUAL expression { currentImageBifOptions->SetFunctionId($3); }
| PCR_NUMBER EQUAL expression { if(!options.IsVersalNetSeries())
LOG_ERROR("BIF attribute error !!!\n\t 'pcr' is supported only for VERSAL NET architecture");
currentImageBifOptions->SetPcrNumber($3); }
| PCR_MEASUREMENT_INDEX EQUAL expression { if(!options.IsVersalNetSeries())
LOG_ERROR("BIF attribute error !!!\n\t 'pcr_mid' is supported only for VERSAL NET architecture");
currentImageBifOptions->SetPcrMeasurementIndex($3); }
;
partition_spec : PARTITION partition_content
| partition_content
;
partition_content : /* empty */
| partition_content file_spec
| partition_content new_file_spec
;
other_spec : OBRACKET KEYSRC_ENCRYPTION EBRACKET key_src { if(options.GetArchType() == Arch::VERSAL)
LOG_WARNING("BIF attribute error !!! [keysrc_encryption] not supported in VERSAL architecture.\n\t Please see 'bootgen -arch versal -bif_help keysrc'");
currentBifOptions->SetEncryptionKeySource($4); options.SetEncryptedKeySource($4); }
| OBRACKET FSBL_CONFIG { if(options.GetArchType() == Arch::ZYNQ)
LOG_ERROR("BIF attribute error !!!\n\t\t[fsbl_config] not supported in ZYNQ architecture"); }
EBRACKET fsbl_attr_list
| FSBL_CONFIG OBRACE fsbl_attr_list EBRACE
| BOOT_DEVICE OBRACE sec_boot_attr_list EBRACE
| OBRACKET BOOT_DEVICE EBRACKET boot_device_type { if(options.GetArchType() == Arch::ZYNQ)
LOG_ERROR("BIF attribute error !!!\n\t\t[bootdevice] not supported in ZYNQ architecture");
if(options.GetArchType() == Arch::VERSAL)
LOG_ERROR("This usage of boot_device is no more supported.\n\t Please see 'bootgen -arch versal -bif_help boot_device'");
currentBifOptions->SetBootDevice($4); }
| BOOT_DEVICE EQUAL boot_device_type { LOG_ERROR("This usage of boot_device is no more supported.\n\t Please see 'bootgen -arch versal -bif_help boot_device'"); }
| OBRACKET AUTH_PARAMS EBRACKET auth_parameters
| OBRACKET SPLIT EBRACKET split_options
| OBRACKET BOOTVECTORS EBRACKET bootvectors_list
| AUTHJTAG_CONFIG OBRACE authjtag_attr_list EBRACE
| OPTIONAL_DATA OBRACE optional_data EBRACE
;
sec_boot_attr_list : sec_boot_attr
| sec_boot_attr COMMA sec_boot_attr_list
;
sec_boot_attr : boot_device_type { currentBifOptions->SetBootDevice($1); }
| IMAGE_STORE { currentBifOptions->SetBootDevice(BootDevice::IMAGESTORE); }
| ADDRESS EQUAL expression { currentBifOptions->SetBootDeviceAddress($3); }
;
fsbl_attr_list : fsbl_attr
| fsbl_attr COMMA fsbl_attr_list
;
authjtag_attr_list : authjtag_attr
| authjtag_attr COMMA authjtag_attr_list
| authjtag_attr authjtag_attr_list
;
authjtag_attr : REVOKE_ID EQUAL expression { currentBifOptions->SetAuthJtagRevokeID($3); }
| DEVICE_DNA EQUAL HEXWORD { currentBifOptions->SetAuthJtagDeviceDna($3); }
| JTAG_TIMEOUT EQUAL expression { currentBifOptions->SetAuthJtagTimeOut($3); }
;
fsbl_attr : core { currentBifOptions->SetCore($1);
LOG_WARNING("[fsbl_config] a53_x64 | a53_x32 | r5_single | r5_dual is no more supported. Use 'destination_cpu' attribute for bootloader partition"); }
| bh_rsa { if(options.GetArchType() == Arch::VERSAL && options.IsVersalNetSeries())
LOG_ERROR("BIF attribute error !!! 'bh_auth_enable' is not supported with '-arch versalnet'.\n\t Bootheader or eFuse authentication will be chosen based on eFuse bits.");
else
currentBifOptions->SetBhRsa($1);
}
| auth_hash { LOG_ERROR("Authentication using SHA2 is no more supported."); }
| int_hash { LOG_ERROR("[fsbl_config] bi_integrity_sha3 is no more supported. Use 'checksum' attribute of bootloader partition"); }
| pufhd_loc { currentBifOptions->SetPufHdLoc($1); }
| auth_only { currentBifOptions->SetAuthOnly($1); }
| opt_key { currentBifOptions->SetOptKey($1); }
| PUF4KMODE { currentBifOptions->SetPufMode(PufMode::PUF4K); }
| SHUTTER EQUAL expression { currentBifOptions->SetShutterValue($3); }
| dpa_cm { if(options.GetArchType() != Arch::VERSAL)
LOG_ERROR("BIF attribute error !!!\n\t\t'dpacm_enable' is supported only in VERSAL architecture");
if(options.GetArchType() == Arch::VERSAL)
LOG_WARNING("boot_config { dpacm_enable } will be deprecated. 'dpacm_enable' should be specified along with the partition. \n See 'bootgen -bif_help dpacm_enable' for more info.");
currentBifOptions->SetDpaCM($1);
}
| SMAP_WIDTH EQUAL expression { if(($3 != 8) && ($3 !=16) && ($3 != 32) && ($3 != 0))
LOG_ERROR("Invalid smap_width value in BIF. Valid values are 8, 16 and 32");
currentBifOptions->SetSmapWidth($3);
}
| BYPASS_IDCODE_CHECK { currentBifOptions->SetBypassIdcodeFlag(true); }
| A_HWROT { currentBifOptions->SetAHwRoTFlag(true); }
| S_HWROT { currentBifOptions->SetSHwRoTFlag(true); }
| PUFROSWAP EQUAL expression { if(options.GetArchType() == Arch::VERSAL && options.IsVersalNetSeries())
currentBifOptions->SetPufRingOscilltorSwapConfigValue($3);
else
LOG_ERROR("BIF attribute error !!!\n\t 'puf_ro_swap' is supported only in VersalNet architecture");
}
| DICE { if(options.GetArchType() == Arch::VERSAL && options.IsVersalNetSeries())
currentBifOptions->SetDiceEnable();
else
LOG_ERROR("BIF attribute error !!!\n\t 'dice_enable' is supported only in VersalNet architecture");
}
;
file_spec : OBRACKET { currentPartitionBifOptions = new PartitionBifOptions();
currentPartitionBifOptions->SetArchType(options.GetArchType(),options.IsVersalNetSeries()); }
attribute_list EBRACKET
filename { currentPartitionBifOptions->filename = $5;
currentPartitionBifOptions->filelist.push_back($5);
currentBifOptions->Add(currentPartitionBifOptions, currentImageBifOptions);
}
| filename { currentPartitionBifOptions = new PartitionBifOptions();
currentPartitionBifOptions->SetArchType(options.GetArchType(), options.IsVersalNetSeries());
currentPartitionBifOptions->filename = $1;
currentPartitionBifOptions->filelist.push_back($1);
currentBifOptions->Add(currentPartitionBifOptions, currentImageBifOptions);
};
new_file_spec : OBRACE { currentPartitionBifOptions = new PartitionBifOptions();
currentPartitionBifOptions->SetArchType(options.GetArchType(), options.IsVersalNetSeries()); }
new_attribute_list EBRACE
;
new_attribute_list : attribute
| new_attribute
| new_attribute COMMA new_attribute_list
| attribute COMMA new_attribute_list
| new_attribute new_attribute_list
| attribute new_attribute_list
;
new_attribute : PFILE EQUAL filename { currentPartitionBifOptions->filename = $3;
currentPartitionBifOptions->filelist.push_back($3);
currentBifOptions->Add(currentPartitionBifOptions, currentImageBifOptions); }
| ID EQUAL expression { currentPartitionBifOptions->partitionId = $3; }
| IMAGE_STORE EQUAL expression { currentPartitionBifOptions->imageStoreId = $3;
currentPartitionBifOptions->SetPartitionType(PartitionType::IMAGE_STORE_PDI); }
| PARTITION_TYPE EQUAL boolattr
| PARTITION_TYPE EQUAL PMCDATA { currentPartitionBifOptions->fileType = $3; }
| BIF_SECTION EQUAL WORD { currentPartitionBifOptions->bifSection = $3;
currentPartitionBifOptions->filename = currentPartitionBifOptions->GetOutputFileFromBifSection(options.GetOutputFileNames().front(), $3, currentImageBifOptions->GetImageType());
currentBifOptions->Add(currentPartitionBifOptions, currentImageBifOptions); }
;
attribute_list : attribute
| attribute COMMA attribute_list
;
attribute : boolattr
| optattr
| numattr
| fileattr
| blocksattr_list
;
blocksattr_list : BLOCKS EQUAL blocksattr
| AUTHBLOCKS EQUAL authblockattr
;
blocksattr : blockattr
| blockattr SEMICOLON blocksattr
;
bootvectors_list : bootvector
| bootvector COMMA bootvectors_list
;
bootvector : expression { if(options.GetArchType() != Arch::ZYNQMP)
LOG_ERROR("BIF attribute error !!!\n\t\t[bootvectors] only supported in ZYNQMP architecture");
currentBifOptions->SetBootVectorArray($1); }
;
authblockattr : expression { currentPartitionBifOptions->SetAuthBlockAttr($1); }
boolattr : BOOTLOADER { currentPartitionBifOptions->bootloader = true;}
| BOOT { currentPartitionBifOptions->boot = true;}
| USER { currentPartitionBifOptions->user = true;}
| STATIC { currentPartitionBifOptions->Static = true;}
| NOAUTOSTART { currentPartitionBifOptions->noautostart = true;}
| MULTIBOOT { currentPartitionBifOptions->multiboot = true;}
| PROTECTED { currentPartitionBifOptions->Protected = true;}
| EARLY_HANDOFF { currentPartitionBifOptions->SetEarlyHandoff(true); }
| HIVEC { currentPartitionBifOptions->SetHivec(true); }
| XIP_MODE { if(currentPartitionBifOptions->bootloader!=true)
LOG_ERROR("XIP mode can be enabled only for bootloader");
currentBifOptions->SetXipMode(); }
| INIT { currentPartitionBifOptions->fileType = $1; }
| BOOTIMAGE { currentPartitionBifOptions->bootImage = true; }
| key_file { currentPartitionBifOptions->fileType = $1; }
| other_files { currentPartitionBifOptions->fileType = $1; }
| ptypevalue { currentPartitionBifOptions->SetPartitionType($1); }
| LOCKSTEP { currentPartitionBifOptions->SetLockStepFlag();}
;
trustzone_type : TRUSTZONE { currentPartitionBifOptions->SetTrustZone(::TrustZone::Secure); }
| TRUSTZONE EQUAL TRUSTZONE_TYPE { currentPartitionBifOptions->SetTrustZone($3); }
;
blockattr : expression { currentPartitionBifOptions->SetEncryptionBlocks($1); }
| expression LPAREN expression RPAREN { currentPartitionBifOptions->SetEncryptionBlocks($1, $3); }
| expression LPAREN ASTERISK RPAREN { currentPartitionBifOptions->SetEncryptionBlocks($1, 0); }
optattr : AUTHENTICATION EQUAL authvalue { currentPartitionBifOptions->SetAuthType($3); }
| ENCRYPTION EQUAL encrvalue { currentPartitionBifOptions->SetEncryptType($3); }
| CHECKSUM EQUAL checkvalue { currentPartitionBifOptions->SetChecksumType($3); }
| PARTITION_OWNER EQUAL pownervalue { currentPartitionBifOptions->SetOwnerType($3); }
| DEST_CPU EQUAL dest_cpu_type { currentPartitionBifOptions->SetDestCpu($3); }
| DEST_DEVICE EQUAL dest_device_type { currentPartitionBifOptions->SetDestDevice($3); }
| EXCEPTION_LEVEL EQUAL exception_level_type { currentPartitionBifOptions->SetExceptionLevel($3); }
| AES_KEY_FILE EQUAL filename { currentPartitionBifOptions->SetAesKeyFile($3); }
| PPK_FILE EQUAL filename { currentPartitionBifOptions->ppkFile = ($3); }
| PSK_FILE EQUAL filename { currentPartitionBifOptions->pskFile = ($3); }
| SPK_FILE EQUAL filename { currentPartitionBifOptions->spkFile = ($3); }
| SSK_FILE EQUAL filename { currentPartitionBifOptions->sskFile = ($3); }
| SPK_SELECT EQUAL spkselect { currentPartitionBifOptions->spkSelect =($3); currentPartitionBifOptions->spkSelLocal = true; }
| SPK_ID EQUAL expression { currentPartitionBifOptions->SetSpkId($3); }
| SPK_SIGNATURE_FILE EQUAL filename { currentPartitionBifOptions->spkSignatureFile = ($3); }
| trustzone_type
| PARTITION_TYPE EQUAL ptypevalue { currentPartitionBifOptions->SetPartitionType($3); }
| KEYSRC_ENCRYPTION EQUAL key_src { currentPartitionBifOptions->SetEncryptionKeySource($3); }
| REVOKE_ID EQUAL expression { currentPartitionBifOptions->SetRevokeId($3); }
| DPA_CM { currentPartitionBifOptions->SetDpaCM(DpaCM::DpaCMEnable); }
| SLR_NUM EQUAL expression { currentPartitionBifOptions->SetSlrNum($3); }
| CLUSTER_NUM EQUAL expression { currentPartitionBifOptions->SetClusterNum($3); }
| PUFHD_LOC { currentPartitionBifOptions->SetPufHdLocation(PufHdLoc::PUFinBH); }
| DELAY_AUTH { currentPartitionBifOptions->SetDelayAuth(true); }
| TCM_BOOT { currentPartitionBifOptions->SetTcmBootFlag(); }
;
other_file_attr : INIT
| key_file
| BH_KEK_IV
| BBRAM_KEK_IV
| EFUSE_KEK_IV
| EFUSE_USER_KEK0_IV
| EFUSE_USER_KEK1_IV
| USER_KEYS
;
authvalue : NONE { $$ = ::Authentication::None;}
| AUTHVALUE
;
encrvalue : NONE { $$ = ::Encryption::None;}
| ENCRVALUE
;
checkvalue : NONE { $$ = ::Checksum::None;}
| CHECKSUMVALUE
;
pownervalue : POWNERVALUE
;
ptypevalue : PTYPEVALUE
;
key_src : KEY_SRC
;
core : CORE
;
bh_rsa : BH_RSA
;
dpa_cm : DPA_CM
;
auth_hash : AUTH_HASH
;
int_hash : INT_HASH
;
pufhd_loc : PUFHD_LOC
;
opt_key : OPT_KEY
;
auth_only : AUTH_ONLY
;
boot_device_type : BOOT_DEVICE_TYPE
;
dest_cpu_type : DEST_CPU_TYPE
;
dest_device_type : DEST_DEVICE_TYPE
;
exception_level_type : EXCEPTION_LEVEL_TYPE
;
numattr : ALIGNMENT EQUAL expression { currentPartitionBifOptions->alignment = $3; }
| OFFSET EQUAL expression { currentPartitionBifOptions->offset = $3; }
| RESERVE_LEGACY EQUAL expression { currentPartitionBifOptions->SetReserveLength($3, false); }
| RESERVE EQUAL expression { currentPartitionBifOptions->SetReserveLength($3, true); }
| LOAD EQUAL expression { currentPartitionBifOptions->load = $3; }
| STARTUP EQUAL expression { currentPartitionBifOptions->startup = $3; }
| BIGENDIAN { currentPartitionBifOptions->bigEndian = true; }
| A32_MODE { currentPartitionBifOptions->a32Mode = true; }
| PARTITION_NUM EQUAL expression { currentPartitionBifOptions->pid = $3; }
| TCM_A_REGION EQUAL expression { currentPartitionBifOptions->SetTcmARegion($3); }
| TCM_B_REGION EQUAL expression { currentPartitionBifOptions->SetTcmBRegion($3); }
| TCM_C_REGION EQUAL expression { currentPartitionBifOptions->SetTcmCRegion($3); }
;
fileattr : PRESIGN EQUAL filename { currentPartitionBifOptions->presignFile = $3; }
| UDF_DATA EQUAL filename { currentPartitionBifOptions->SetUdfDataFile($3); }
;
key_file : AES_KEY_FILE
| rsa_key_file
| SPK_SIGNATURE_FILE
| BH_SIGNATURE_FILE
| HEADER_SIGNATURE_FILE
| BH_KEY_FILE
| PUF_HELPER_FILE
| BH_KEY_IV
| FAMILY_KEY
;
rsa_key_file : PPK_FILE
| PSK_FILE
| SPK_FILE
| SSK_FILE
;
other_files : PMUFW_IMAGE
| PMCDATA
| UDF_BH
;
auth_parameters : PPK_SELECT EQUAL expression { if(options.GetArchType() != Arch::ZYNQMP)
LOG_ERROR("BIF attribute error !!!\n\t\t[auth_params] is supported only in ZYNQMP architecture");
currentBifOptions->SetPPKSelection($3); }
| SPK_SELECT EQUAL spkselect { if(options.GetArchType() != Arch::ZYNQMP)
LOG_ERROR("BIF attribute error !!!\n\t\t[auth_params] is supported only in ZYNQMP architecture");
currentBifOptions->SetSPKSelection($3); }
| SPK_ID EQUAL expression { if(options.GetArchType() != Arch::ZYNQMP)
LOG_WARNING("BIF attribute error !!!\n\t\t[auth_params] is supported only in ZYNQMP architecture");
currentBifOptions->SetSpkId($3); }
| HEADER_AUTH { if(options.GetArchType() != Arch::ZYNQMP)
LOG_ERROR("BIF attribute error !!!\n\t\t[auth_params] is supported only in ZYNQMP architecture");
currentBifOptions->SetHeaderAuthentication(); }
| auth_parameters SEMICOLON auth_parameters
;
spkselect : SPKSELECT
;
split_options : SPLIT_MODE EQUAL splitmode { if(options.GetArchType() != Arch::ZYNQMP)
LOG_ERROR("BIF attribute error !!!\n\t\t[split] not supported in ZYNQ architecture");
currentBifOptions->SetSplitMode($3); }
| SPLIT_FMT EQUAL splitfmt
| split_options COMMA split_options
;
splitmode : SPLITMODE
;
splitfmt : MCS { if(options.GetArchType() != Arch::ZYNQMP)
LOG_ERROR("BIF attribute error !!!\n\t\t[split] not supported in ZYNQ architecture");
currentBifOptions->SetSplitFmt(File::MCS); }
| BIN { if(options.GetArchType() != Arch::ZYNQMP)
LOG_ERROR("BIF attribute error !!!\n\t\t[split] not supported in ZYNQ architecture");
currentBifOptions->SetSplitFmt(File::BIN); }
;
filename : FILENAME
| QFILENAME
;
number : HEXVALUE
| DECVALUE
| LPAREN expression RPAREN { $$ = $2; };
// highest precendence
unary_expression : number
| PLUS unary_expression {$$ = $2; *options.debugstr << $$ << " + " << $2 << std::endl;}
| NEGATION unary_expression {$$ = ~$2; *options.debugstr << $$ << " ~ " << $2 << std::endl;}
;
multiplicative_expression
: unary_expression
| multiplicative_expression MULT unary_expression {$$ = $1 * $3; *options.debugstr << $$ << " = " << $1 << " + " << $3 << std::endl;}
| multiplicative_expression DIVIDE unary_expression {$$ = $1 / $3; *options.debugstr << $$ << " = " << $1 << " / " << $3 << std::endl;}
| multiplicative_expression MODULO unary_expression {$$ = $1 % $3; *options.debugstr << $$ << " = " << $1 << " % " << $3 << std::endl;}
;
additive_expression : multiplicative_expression
| additive_expression PLUS multiplicative_expression {$$ = $1 + $3;*options.debugstr << $$ << " = " << $1 << " + " << $3 << std::endl;}
| additive_expression MINUS multiplicative_expression {$$ = $1 - $3;*options.debugstr << $$ << " = " << $1 << " - " << $3 << std::endl;}
;
shift_expression : additive_expression
| shift_expression LSHIFT additive_expression {$$ = $1 << $3;*options.debugstr << $$ << " = " << $1 << " << " << $3 << std::endl;}
| shift_expression RSHIFT additive_expression {$$ = $1 >> $3;*options.debugstr << $$ << " = " << $1 << " >> " << $3 << std::endl;}
;
and_expression : shift_expression
| and_expression AND shift_expression {$$ = $1 & $3;*options.debugstr << $$ << " = " << $1 << " & " << $3 << std::endl;}
;
xor_expression : and_expression
| xor_expression XOR and_expression {$$ = $1 ^ $3;*options.debugstr << $$ << " = " << $1 << " ^ " << $3 << std::endl;}
;
// lowest precendence
expression : xor_expression
| expression OR xor_expression {$$ = $1 | $3;*options.debugstr << $$ << " = " << $1 << " | " << $3 << std::endl;}
;
%%
void BIF::BisonParser::error(const BIF::BisonParser::location_type &loc, const std::string &msg) {
Parsing::Error(loc,msg);
}
static int yylex(BIF::BisonParser::semantic_type * yylval, BIF::BisonParser::location_type* loc, BIF::FlexScanner &scanner) {
return scanner.yylex(yylval,loc);
}