-
Notifications
You must be signed in to change notification settings - Fork 86
/
cmd_line_parser.cpp
1523 lines (1416 loc) · 48.2 KB
/
cmd_line_parser.cpp
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
/*
*
* cmd_line_parser.cpp - FLash INTerface
*
* Copyright (c) 2013-2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the
* OpenIB.org BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Version: $Id$
*
*/
#include <iostream>
#include <stdio.h>
#include <errno.h>
// Flint includes
#include "flint.h"
#include <common/tools_version.h>
#include "mlxfwops/lib/flint_io.h"
#ifndef FLINT_NAME
#ifdef __GNUC__
#define FLINT_NAME "flint"
#else
#define FLINT_NAME "flint"
#endif
#endif
using namespace std;
/******************************
* Data structures containing
* Meta data about subcommands
* and flags
******************************/
class SubCmdMetaData
{
private:
class SubCmd
{
public:
SubCmd(string s, string l, sub_cmd_t n) : shortf(s), longf(l), cmdNum(n) {}
~SubCmd() {}
string shortf;
string longf;
sub_cmd_t cmdNum;
};
vector<class SubCmd*> _sCmds;
public:
SubCmdMetaData();
~SubCmdMetaData();
sub_cmd_t getCmdNum(string flag);
};
SubCmdMetaData::SubCmdMetaData()
{
_sCmds.push_back(new SubCmd("b", "burn", SC_Burn));
_sCmds.push_back(new SubCmd("q", "query", SC_Query));
_sCmds.push_back(new SubCmd("v", "verify", SC_Verify));
_sCmds.push_back(new SubCmd("", "swreset", SC_Swreset));
_sCmds.push_back(new SubCmd("", "reset_cfg", SC_ResetCfg));
_sCmds.push_back(new SubCmd("", "brom", SC_Brom));
_sCmds.push_back(new SubCmd("", "drom", SC_Drom));
_sCmds.push_back(new SubCmd("", "rrom", SC_Rrom));
_sCmds.push_back(new SubCmd("", "qrom", SC_Qrom));
_sCmds.push_back(new SubCmd("", "bb", SC_Bb));
_sCmds.push_back(new SubCmd("", "sg", SC_Sg));
#ifndef EXTERNAL
_sCmds.push_back(new SubCmd("", "smg", SC_Smg));
_sCmds.push_back(new SubCmd("", "set_vpd", SC_Set_Vpd));
_sCmds.push_back(new SubCmd("", "set_attestation_cert_chain", SC_Set_Cert_Chain));
#endif
_sCmds.push_back(new SubCmd("", "sv", SC_Sv));
_sCmds.push_back(new SubCmd("", "ri", SC_Ri));
_sCmds.push_back(new SubCmd("", "dc", SC_Dc));
_sCmds.push_back(new SubCmd("", "dh", SC_Dh));
_sCmds.push_back(new SubCmd("", "set_key", SC_Set_Key));
_sCmds.push_back(new SubCmd("", "hw_access", SC_Hw_Access));
_sCmds.push_back(new SubCmd("", "hw", SC_Hw));
_sCmds.push_back(new SubCmd("e", "erase", SC_Erase));
_sCmds.push_back(new SubCmd("", "rw", SC_Rw));
_sCmds.push_back(new SubCmd("", "ww", SC_Ww));
_sCmds.push_back(new SubCmd("", "wwne", SC_Wwne));
_sCmds.push_back(new SubCmd("", "wbne", SC_Wbne));
_sCmds.push_back(new SubCmd("", "wb", SC_Wb));
_sCmds.push_back(new SubCmd("", "rb", SC_Rb));
_sCmds.push_back(new SubCmd("", "clear_semaphore", SC_Clear_Sem));
_sCmds.push_back(new SubCmd("", "fi", SC_Fix_Img));
_sCmds.push_back(new SubCmd("cs", "checksum", SC_Check_Sum));
_sCmds.push_back(new SubCmd("ts", "timestamp", SC_Time_Stamp));
_sCmds.push_back(new SubCmd("ci", "cache_image", SC_Cache_Image));
_sCmds.push_back(new SubCmd("", "sign", SC_Sign));
_sCmds.push_back(new SubCmd("", "sign_with_hmac", SC_Add_Hmac));
_sCmds.push_back(new SubCmd("", "extract_fw_data", SC_Extract_4MB_Image));
_sCmds.push_back(new SubCmd("", "set_public_keys", SC_Set_Public_Keys));
_sCmds.push_back(new SubCmd("", "set_forbidden_versions", SC_Set_Forbidden_Versions));
_sCmds.push_back(new SubCmd("ir", "image_reactivation", SC_Image_Reactivation));
_sCmds.push_back(new SubCmd("bc", "binary_compare", SC_Binary_Compare));
_sCmds.push_back(new SubCmd("", "rsa_sign", SC_RSA_Sign));
_sCmds.push_back(new SubCmd("", "export_public_key", SC_Export_Public_Key));
_sCmds.push_back(new SubCmd("qc", "query_components", SC_Query_Components));
}
SubCmdMetaData::~SubCmdMetaData()
{
for (vector<class SubCmd*>::iterator it = _sCmds.begin(); it != _sCmds.end(); ++it)
{
delete *it;
}
}
sub_cmd_t SubCmdMetaData::getCmdNum(string flag)
{
for (vector<class SubCmd*>::iterator it = _sCmds.begin(); it != _sCmds.end(); ++it)
{
if (((*it)->shortf == flag) || ((*it)->longf == flag))
{
return (*it)->cmdNum;
}
}
return SC_No_Cmd;
}
class FlagMetaData
{
private:
class Flag
{
public:
Flag(string s, string l, int n) : shortf(s), longf(l), argNum(n) {}
~Flag() {}
string shortf;
string longf;
int argNum;
};
vector<class Flag*> _flags;
public:
FlagMetaData();
~FlagMetaData();
int getNumOfArgs(string flag);
};
FlagMetaData::FlagMetaData()
{
_flags.push_back(new Flag("d", "device", 1));
_flags.push_back(new Flag("", "guid", 1));
_flags.push_back(new Flag("", "guids", GUIDS));
_flags.push_back(new Flag("", "mac", 1));
_flags.push_back(new Flag("", "macs", MACS));
_flags.push_back(new Flag("", "uid", 1));
_flags.push_back(new Flag("", "blank_guids", 0));
_flags.push_back(new Flag("", "clear_semaphore", 0));
_flags.push_back(new Flag("h", "help", 0));
_flags.push_back(new Flag("", "hh", 0));
_flags.push_back(new Flag("i", "image", 1));
_flags.push_back(new Flag("", "qq", 0));
_flags.push_back(new Flag("", "low_cpu", 0));
_flags.push_back(new Flag("", "next_boot_fw_ver", 0));
_flags.push_back(new Flag("", "flashed_version", 0));
_flags.push_back(new Flag("", "nofs", 0));
_flags.push_back(new Flag("", "allow_psid_change", 0));
_flags.push_back(new Flag("", "apc", 0));
_flags.push_back(new Flag("", "allow_rom_change", 0));
_flags.push_back(new Flag("", "override_cache_replacement", 0));
_flags.push_back(new Flag("", "ocr", 0));
_flags.push_back(new Flag("", "no_flash_verify", 0));
_flags.push_back(new Flag("s", "silent", 0));
_flags.push_back(new Flag("y", "yes", 0));
_flags.push_back(new Flag("", "no", 0));
_flags.push_back(new Flag("", "vsd", 1));
_flags.push_back(new Flag("", "use_image_ps", 0));
_flags.push_back(new Flag("", "use_image_guids", 0));
_flags.push_back(new Flag("", "use_image_rom", 0));
_flags.push_back(new Flag("", "ignore_dev_data", 0));
_flags.push_back(new Flag("", "dual_image", 0));
_flags.push_back(new Flag("", "striped_image", 0));
_flags.push_back(new Flag("", "banks", 1));
_flags.push_back(new Flag("", "log", 1));
_flags.push_back(new Flag("", "flash_params", 1)); // its actually 3 but separated by comma so we refer to them as
// one
_flags.push_back(new Flag("v", "version", 0));
_flags.push_back(new Flag("", "no_devid_check", 0));
_flags.push_back(new Flag("", "use_fw", 0));
_flags.push_back(new Flag("", "use_dev_img_info", 0));
_flags.push_back(new Flag("", "ignore_crc_check", 0));
_flags.push_back(new Flag("", "hexdump_format", 0));
_flags.push_back(new Flag("", "skip_ci_req", 0));
_flags.push_back(new Flag("", "use_dev_rom", 0));
_flags.push_back(new Flag("", "private_key", 1));
_flags.push_back(new Flag("", "public_key", 1));
_flags.push_back(new Flag("", "key_uuid", 1));
_flags.push_back(new Flag("", "private_key2", 1));
_flags.push_back(new Flag("", "hmac_key", 1));
_flags.push_back(new Flag("", "key_uuid2", 1));
_flags.push_back(new Flag("", "no_fw_ctrl", 0));
_flags.push_back(new Flag("", "ir", 0));
_flags.push_back(new Flag("", "latest_fw", 0));
_flags.push_back(new Flag("", "psid", 1));
_flags.push_back(new Flag("", "cc", 1));
_flags.push_back(new Flag("", "linkx", 0));
_flags.push_back(new Flag("", "downstream_device_id_start_index", 1));
_flags.push_back(new Flag("", "num_of_downstream_devices", 1));
_flags.push_back(new Flag("", "linkx_auto_update", 0));
_flags.push_back(new Flag("", "activate", 0));
_flags.push_back(new Flag("", "activate_delay_sec", 1));
_flags.push_back(new Flag("", "downstream_device_ids", 1));
_flags.push_back(new Flag("", "download_transfer", 0));
_flags.push_back(new Flag("", "openssl_engine", 1));
_flags.push_back(new Flag("", "openssl_key_id", 1));
#ifdef __WIN__
_flags.push_back(new Flag("", "cpu_util", 1));
#endif
_flags.push_back(new Flag("", "output_file", 1));
_flags.push_back(new Flag("", "user_password", 1));
_flags.push_back(new Flag("", "cert_chain_index", 1));
_flags.push_back(new Flag("", "component_type", 1));
}
FlagMetaData::~FlagMetaData()
{
for (vector<class Flag*>::iterator it = _flags.begin(); it != _flags.end(); ++it)
{
delete *it;
}
}
int FlagMetaData::getNumOfArgs(string flag)
{
for (vector<class Flag*>::iterator it = _flags.begin(); it != _flags.end(); ++it)
{
if (((*it)->shortf == flag) || ((*it)->longf == flag))
{
return (*it)->argNum;
}
}
return -1;
}
/********************
* Helper Functions:
*******************/
// NOTE : number of parameters extracted in the container should be checked.
static void splitByDelimiters(std::vector<string>& container, string str, const char* delimiters)
{
if (str.size() == 0)
{
return;
}
char* cStr = strcpy(new char[str.size() + 1], str.c_str());
char* ptr;
ptr = strtok(cStr, delimiters);
while (ptr != NULL)
{
container.push_back(ptr);
ptr = strtok(NULL, delimiters);
}
delete[] cStr;
return;
}
char* stripFlag(char* flag)
{
char* strippedFlagStart = NULL;
if (flag[0] != '-')
{ // not a flag
return flag;
};
if ((flag[0] == '-') && (flag[1] == '-'))
{
strippedFlagStart = &flag[2];
}
else
{
strippedFlagStart = &flag[1];
}
return strippedFlagStart;
}
int countArgs(string args)
{
if (args.size() == 0)
{
return 0;
}
int count = 1;
for (string::iterator it = args.begin(); it < args.end(); ++it)
{
if (*it == ',')
{
count++;
}
}
return count;
}
bool verifyNumOfArgs(string name, string value)
{
// HACK : we don't check device numOfArgs because image device format might contain ","
if ((name == "device") || (name == "d"))
{
return true;
}
if ((name == "image") || (name == "i"))
{
return true;
}
// Hack : VSD can be empty or contain "," so we shouldnt count its args
if (name == "vsd")
{
return true;
}
if (name == "output_file")
{
return true;
}
int expected = FlagMetaData().getNumOfArgs(name);
if (expected < 0)
{
printf(FLINT_INVALID_FLAG_ERROR, name.c_str());
return false;
}
// HACK : flash_params is 3 argument but given with comma separated instead of spaces like the rest
// so flag_arg_num gives a wrong value
if (name == "flash_params")
{
expected = 3;
}
int actual = countArgs(value);
if (name == "downstream_device_ids")
{
if (actual < 1)
{
printf(FLINT_TOO_FEW_MINIMUM_ARGS_ERROR, 1, actual);
return false;
}
return true;
}
if (actual < expected)
{
printf(FLINT_TOO_FEW_ARGS_ERROR, expected, actual);
return false;
}
else if (actual > expected)
{
printf(FLINT_TOO_MANY_ARGS_ERROR, expected, actual);
return false;
}
return true;
}
bool strToInt(string str, int& num, int base = 0)
{
char* endp;
char* numStr = strcpy(new char[str.size() + 1], str.c_str());
num = strtol(numStr, &endp, base);
if (*endp)
{
delete[] numStr;
return false;
}
delete[] numStr;
return true;
}
bool strToNum(string str, u_int64_t& num, int base = 0)
{
char* endp;
char* numStr = strcpy(new char[str.size() + 1], str.c_str());
num = strtoul(numStr, &endp, base);
if (*endp)
{
delete[] numStr;
return false;
}
delete[] numStr;
return true;
}
// this function is used in extracting both guids and macs from user
bool getGUIDFromStr(string str, guid_t& guid, string prefixErr = "")
{
char* endp;
u_int64_t g;
g = strtoull(str.c_str(), &endp, 16);
if (*endp || (g == 0xffffffffffffffffULL && errno == ERANGE))
{
if (prefixErr.size() == 0)
{
printf("-E- Invalid Guid/Mac/Uid syntax (%s) %s \n", str.c_str(), errno ? strerror(errno) : "");
}
else
{
printf("%s\n", prefixErr.c_str());
}
return false;
}
guid.h = (u_int32_t)(g >> 32);
guid.l = (u_int32_t)(g & 0xffffffff);
return true;
}
bool isElementPresent(vector<string> strv, string str) //* should be renamed to isStrPresent, since it's not generic
{
for (vector<string>::iterator it = strv.begin(); it < strv.end(); it++)
{
if (*it == str)
{
return true;
}
}
return false;
}
bool stringsCommaSplit(string str, std::vector<int>& deviceIds) //* Should be renamed to something like
{ //* getIntsFromCommaSplitString
size_t pos;
std::vector<string> strv;
bool res = true;
while ((pos = str.find(',')) != string::npos)
{
string tmp = str.substr(0, pos);
if (!isElementPresent(strv, tmp))
{ //* Can be changed to: std::find(strv.begin(), strv.end(), tmp) != strv.end()
strv.push_back((string)tmp); //* So we can remove isElementPresent function
}
str = str.substr(pos + 1);
}
if (str != "")
{
if (!isElementPresent(strv, str))
{ //* Same as above
strv.push_back((string)str);
}
}
for (std::vector<string>::iterator it = strv.begin(); it < strv.end(); it++)
{
int num;
if (false == strToInt((*it).c_str(), num))
{
return false;
}
if (num < 0 || num > 255)
{
printf("Index value should be between 0 and 255.\n");
return false;
}
deviceIds.push_back(num);
}
return res;
}
guid_t incrGuid(guid_t baseGuid, unsigned int incrVal)
{
u_int64_t g = baseGuid.h;
g = (g << 32) | baseGuid.l;
g += incrVal;
guid_t userGuid;
userGuid.h = (u_int32_t)(g >> 32);
userGuid.l = (u_int32_t)g;
return userGuid;
}
guid_t GetBaseMac(guid_t baseGuid)
{
guid_t baseMac;
baseMac.l = (baseGuid.l & 0x00ffffff) | ((baseGuid.h & 0xff00) << 16);
baseMac.h = baseGuid.h >> 16;
return baseMac;
}
bool parseFlashParams(string params, flash_params_t& fp)
{
// Step 1 split by ","
std::vector<std::string> paramVec;
splitByDelimiters(paramVec, params, ",");
if (paramVec.size() != 3)
{
return false;
}
// Step 2 extract params
size_t length = paramVec[0].length();
const char* paramStr = paramVec[0].c_str();
memset(fp.type_name, 0, MAX_FLASH_NAME);
strncpy(fp.type_name, paramStr, length);
u_int64_t tmp;
if (!strToNum(paramVec[1], tmp))
{
return false;
}
fp.log2size = (int)tmp;
if (!strToNum(paramVec[2], tmp))
{
return false;
}
fp.num_of_flashes = (int)tmp;
return true;
}
/************************************
* Implementation of the Command line
* Parsing part of the Flint class
************************************/
#define FLASH_LIST_SZ 256
void Flint::initCmdParser()
{
bool isExternal = false;
#ifdef EXTERNAL
isExternal = true;
#endif
AddDescription("flint is a FW (firmware) burning and flash memory operations tool for Mellanox Infiniband HCAs,"
"Ethernet NIC cards, and switch devices.");
AddOptions("device",
'd',
"<device>",
"Device flash is connected to.\n"
"Commands affected: all");
AddOptions("image",
'i',
"<image>",
"Binary image file.\n"
"Commands affected: burn, verify");
AddOptions("latest_fw", ' ', "", "Commands affected: burn");
AddOptions("ir", ' ', "", "Commands affected: burn");
AddOptions("help", 'h', "", "Prints this message and exits");
AddOptions("hh", ' ', "", "Prints extended command help");
AddOptions("yes",
'y',
"",
"Non interactive mode - assume answer \"yes\" to all questions.\n"
"Commands affected: all");
AddOptions("no",
' ',
"",
"Non interactive mode - assume answer \"no\" to all questions.\n"
"Commands affected: all");
AddOptions("guid",
' ',
"<GUID>",
"GUID base value. 4 GUIDs are automatically assigned to the following values:\n\n"
"guid -> node GUID\n"
"guid+1 -> port1\n"
"guid+2 -> port2\n"
"guid+3 -> system image GUID.\n\n"
"Note: port2 guid will be assigned even for a single port HCA - The HCA ignores this value.\n\n"
"Commands affected: burn, sg");
AddOptions("guids",
' ',
"<GUIDS...>",
"4 GUIDs must be specified here.\n"
"The specified GUIDs are assigned to the following fields, respectively:\n"
"node, port1, port2 and system image GUID.\n\n"
"Note: port2 guid must be specified even for a single port HCA - The HCA ignores this value.\n"
"It can be set to 0x0.\n\n"
"Commands affected: burn, sg");
AddOptions("mac",
' ',
"<MAC>",
"MAC address base value. 2 MACs are automatically assigned to the following values:\n\n"
"mac -> port1\n"
"mac+1 -> port2\n\n"
"Commands affected: burn, sg");
AddOptions("macs",
' ',
"<MACs...>",
"2 MACs must be specified here.\n"
"The specified MACs are assigned to port1, port2, respectively.\n"
"Commands affected: burn, sg\n\n"
"Note: -mac/-macs flags are applicable only for Mellanox\n"
"\tTechnologies ethernet products.");
AddOptions("uid",
' ',
"<UID>",
"ConnectIB/SwitchIB only. Derive and set the device UIDs (GUIDs, MACs, WWNs).\n"
"UIDs are derived from the given base UID according to Mellanox Methodology\n"
"Commands affected: burn, sg");
AddOptions("blank_guids",
' ',
"",
"Burn the image with blank GUIDs and MACs (where applicable). These values can be set later using the"
" \"sg\" command (see details below).\n\n"
"Commands affected: burn");
AddOptions("clear_semaphore",
' ',
"",
"Force clear the flash semaphore on the device.\n"
"No command is allowed when this flag is used.\n"
"NOTE: May result in system instability or flash corruption if the device or another application is"
" currently using the flash.\n"
"Exercise caution.\n");
AddOptions("qq",
' ',
"",
"Run a quick query. When specified, flint will not perform full image integrity checks during the query"
" operation. This may shorten execution time when running over slow interfaces (e.g., I2C, MTUSB-1).\n"
"Commands affected: query");
AddOptions("low_cpu",
' ',
"",
"When specified, cpu usage will be reduced. Run time might be increased\n"
"Commands affected: query");
AddOptions("next_boot_fw_ver",
' ',
"",
"When specified, only next boot fw version is fetched\n"
"Commands affected: query",
true);
AddOptions("flashed_version",
' ',
"",
"When specified, only flashed fw version is fetched\n"
"Commands affected: query");
AddOptions("nofs", ' ', "", "Burn image in a non failsafe manner.");
AddOptions("allow_psid_change", ' ', "",
"Allow burning a FW image with a different PSID (Parameter Set ID)than the one currently on flash. Note"
" that changing a PSID may cause the device to malfunction. Use only if you know what you are doing",
isExternal);
AddOptions("apc", ' ', "", "another flag for allow psid change", isExternal);
AddOptions("allow_rom_change",
' ',
"",
"Allow burning/removing a ROM to/from FW image when product version is present.\n"
"Use only if you know what you are doing");
AddOptions("override_cache_replacement",
' ',
"",
"On SwitchX/ConnectIB devices:\n"
"Allow accessing the flash even if the cache replacement mode is enabled.\n"
"NOTE: This flag is intended for advanced users only.\n"
"Running in this mode may cause the firmware to hang.\n");
AddOptions("no_flash_verify", ' ', "", "Do not verify each write on the flash.");
AddOptions("use_fw", ' ', "", "Flash access will be done using FW (ConnectX-3/ConnectX-3Pro only).");
AddOptions("silent",
's',
"",
"Do not print burn progress flyer.\n"
"Commands affected: burn");
AddOptions("vsd", ' ', "<string>", "Write this string, of up to 208 characters, to VSD when burn.");
AddOptions("use_image_ps",
' ',
"",
"Burn vsd as appears in the given image - do not keep existing VSD on flash.\n"
"Commands affected: burn");
AddOptions("use_image_guids",
' ',
"",
"Burn (guids/macs) as appears in the given image.\n"
"Commands affected: burn");
AddOptions("use_image_rom",
' ',
"",
"Do not save the ROM which exists in the device.\n"
"Commands affected: burn");
AddOptions("use_dev_rom",
' ',
"",
"Save the ROM which exists in the device.\n"
"Commands affected: burn");
AddOptions("ignore_dev_data",
' ',
"",
"Do not attempt to take device data sections from device(sections will be taken from the image. FS3"
" Only).\n"
"Commands affected: burn");
AddOptions("no_fw_ctrl", ' ', "", "Do not attempt to work with the FW Ctrl update commands");
AddOptions("use_dev_img_info",
' ',
"",
"preserve select image info fields from the device upon FW update (FS3 Only).\n"
"Commands affected: burn",
true);
AddOptions("ignore_crc_check", ' ', "", "Prevents flint from failing due to CRC check",
true); // hidden
AddOptions("hexdump_format", ' ', "", "Prints rb command output in hexdump format",
true); // hidden
AddOptions("dual_image",
' ',
"",
"Make the burn process burn two images on flash (previously default algorithm). Current default"
" failsafe burn process burns a single image (in alternating locations).\n"
"Commands affected: burn");
AddOptions("striped_image",
' ',
"",
"Use this flag to indicate that the given image file is in a \"striped image\" format.\n"
"Commands affected: query verify");
AddOptions("banks", ' ', "<bank>", "Set the number of attached flash devices (banks)");
AddOptions("log", ' ', "<log_file>", "Print the burning status to the specified log file");
char flashList[FLASH_LIST_SZ] = {0};
char flashParDesc[FLASH_LIST_SZ * 2];
Flash::get_flash_list(flashList, FLASH_LIST_SZ);
snprintf(flashParDesc, FLASH_LIST_SZ * 2,
"Use the given parameters to access the flash instead of reading them from "
"the flash.\n"
"Supported parameters:\n"
"Type: The type of the flash, such as:%s.\n"
"log2size: The log2 of the flash size."
"num_of_flashes: the number of the flashes connected to the device.",
flashList);
AddOptions("flash_params", ' ', "<type, log2size, num_of_flashes>", flashParDesc);
AddOptions("version", 'v', "", "Version info.");
AddOptions("no_devid_check", ' ', "", "ignore device_id checks", true);
AddOptions("skip_ci_req", ' ', "", "skip sending cache image request to driver(windows)", true);
AddOptions("ocr", ' ', "", "another flag for override cache replacement", true);
AddOptions("private_key", ' ', "<key_file>", "path to PEM formatted private key to be used by the sign command");
AddOptions("public_key", ' ', "<key_file>", "path to PEM formatted public key to be used by the sign command");
AddOptions("key_uuid", ' ', "<uuid_file>", "UUID matching the given private key to be used by the sign command");
AddOptions("private_key2", ' ', "<key_file>", "path to PEM formatted private key to be used by the sign command");
AddOptions("hmac_key", ' ', "<hmac_key>", "path to file containing key (For FS4 image only).");
AddOptions("key_uuid2", ' ', "<uuid_file>", "UUID matching the given private key to be used by the sign command");
AddOptions("psid", ' ', "<PSID>", "Use this PSID while burning livefish device using MFA2 archive");
AddOptions("cc", ' ', "<Congestion_Control>",
"Use this flag while burning to device a Congestion Control Component");
AddOptions("linkx", ' ', "", "Use this flag while burning to device a LinkX Component");
AddOptions("downstream_device_id_start_index",
' ',
"<downstream_device_id_start_index>",
"Use this flag while burning to device a LinkX Component. Begin from 0",
false,
false,
1);
AddOptions("num_of_downstream_devices",
' ',
"<num_of_downstream_devices>",
"Use this flag while burning to device a LinkX Component to specify the number of devices to burn",
false,
false,
1);
AddOptions("linkx_auto_update", ' ', "", "Use this flag while burning all cable devices connected to host.", false,
false, 1);
AddOptions("activate",
' ',
"",
"Use this flag to apply the activation of all cable devices connected to host. By default, the "
"activation is not performed.",
false,
false,
1);
AddOptions(
"activate_delay_sec",
' ',
"<timeout in seconds>",
"Use this flag to activate all cable devices connected to host with delay, acceptable values are between 0 and "
"255 (default - 1). Important: 'activate' flag must be set. This flag is relevant only for cable components.",
false,
false,
1);
AddOptions("download_transfer",
' ',
"",
"Use this flag to perform the download and transfer of all cable data for cables. By default, the "
"download and transfer are not performed . This flag is relevant only for cable components.",
false,
false,
1);
AddOptions("downstream_device_ids",
' ',
"<list of ports>",
"Use this flag to specify the LNKX ports to perform query. List must be only comma-separated numbers, "
"without spaces.",
false,
false,
1);
AddOptions(
"openssl_engine",
' ',
"<string>",
"Name of the OpenSSL engine to used by the sign/rsa_sign commands to work with the HSM hardware via OpenSSL API");
AddOptions("openssl_key_id",
' ',
"<string>",
"Key identification string to be used by the sign/rsa_sign commands to work with the HSM hardware via "
"OpenSSL API");
AddOptions("output_file", ' ', "<string>", "output file name for exporting the public key from PEM/BIN");
AddOptions("user_password", ' ', "<string>", "the HSM user password string in order to work with HSM device");
#ifdef __WIN__
AddOptions("cpu_util",
' ',
"<CPU_UTIL>",
"Use this flag to reduce CPU utilization while burning, Windows only. Legal values are from 1 (lowest "
"CPU) to 5 (highest CPU)");
#endif
AddOptions(
"cert_chain_index",
' ',
"<index>",
"Use this flag to specify the certificate location, acceptable values are between 0 and 7 (default - 0). "
"In case index=0 certificate chain will be stored at CERT_CHAIN_0 section, otherwise at DIGITAL_CERT_RW "
"section according to given index.\n"
"This flag is relevant only for set_attestation_cert_chain command.");
AddOptions("component_type", ' ', "<type string>", "component to query, currently only \"sync_clock\" supported.");
for (map_sub_cmd_t_to_subcommand::iterator it = _subcommands.begin(); it != _subcommands.end(); it++)
{
if (it->first == SC_ResetCfg)
{
// hidden command so "forget" mentioning it
continue;
}
string str1 = it->second->getFlagL() + ((it->second->getFlagS() == "") ? (" ") : ("|")) +
it->second->getFlagS() + " " + it->second->getParam();
string str2 = it->second->getDesc();
AddOptionalSectionData("COMMANDS SUMMARY", str1, str2);
}
AddOptionalSectionData("RETURN VALUES", "0", "Successful completion.");
AddOptionalSectionData("RETURN VALUES", "1", "An error has occurred.");
AddOptionalSectionData("RETURN VALUES", "7",
"For burn command - burning new firmware option was not chosen by the user when prompted, "
"thus the firmware burning process was aborted.");
for (map_sub_cmd_t_to_subcommand::iterator it = _subcommands.begin(); it != _subcommands.end(); it++)
{
if (it->first == SC_ResetCfg)
{
// hidden command so "forget" mentioning it
continue;
}
string str = "Name:\n"
"\t" +
it->second->getName() + "\n" +
"Description:\n"
"\t" +
it->second->getExtDesc() + "\n" +
"Command:\n"
"\t" +
it->second->getFlagL() + ((it->second->getFlagS() == "") ? (" ") : ("|")) +
it->second->getFlagS() + " " + it->second->getParam() + "\n" +
"Parameters:\n"
"\t" +
it->second->getParamExp() + "\n" +
"Examples:\n"
"\t" +
it->second->getExample() + "\n\n\n";
AddOptionalSectionData("COMMANDS DESCRIPTION", str);
}
_cmdParser.AddRequester(this);
}
ParseStatus Flint::HandleOption(string name, string value)
{
// TODO: consider verifying num of args inside each if statements that needs its arg num verified
// thus we will be able to get rid of the hacks inside the function in the expense of a longer code.
if (!(verifyNumOfArgs(name, value)))
{
return PARSE_ERROR;
}
int delta = 1;
if (name == "device" || name == "d")
{
_flintParams.device_specified = true;
_flintParams.device = value;
}
else if (name == "help" || name == "h")
{
vector<string> excluded_sections;
excluded_sections.push_back("COMMANDS DESCRIPTION");
cout << _cmdParser.GetUsage(false, excluded_sections);
return PARSE_OK_WITH_EXIT;
}
else if (name == "version" || name == "v")
{
#ifdef EXTERNAL
print_version_string(FLINT_NAME, "");
#else
print_version_string(FLINT_NAME "(oem)", "");
#endif
return PARSE_OK_WITH_EXIT;
}
else if (name == "hh")
{
cout << _cmdParser.GetUsage();
return PARSE_OK_WITH_EXIT;
}
else if (name == "no_devid_check")
{
_flintParams.no_devid_check = true;
}
else if (name == "skip_ci_req")
{
_flintParams.skip_ci_req = true;
}
else if (name == "guid")
{
_flintParams.guid_specified = true;
guid_t g;
if (!getGUIDFromStr(value, g))
{
return PARSE_ERROR;
}
for (int i = 0; i < GUIDS; i++)
{
_flintParams.user_guids.push_back(incrGuid(g, i));
}
// for (std::vector<guid_t>::iterator it=_flintParams.user_guids.begin();it != _flintParams.user_guids.end();
// it++){
// printf("%8.8x%8.8x\n",it->h,it->l);
// }
}
else if (name == "guids")
{
_flintParams.guids_specified = true;
std::vector<std::string> strs;
splitByDelimiters(strs, value, ",");