-
Notifications
You must be signed in to change notification settings - Fork 0
Build Warning: Avoid using getcwd #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Parithi098
wants to merge
1
commit into
main
Choose a base branch
from
bugfix/build-warnings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2306,14 +2306,14 @@ static int sjtag_unlock(int argc, char **argv) | |
| struct switchtec_sn_ver_info sn_info = {}; | ||
| uint8_t sjtag_hr[SJTAG_HR_LEN]; | ||
| struct sjtag_debug_token debug_token; | ||
| FILE *debug_token_bin_file; | ||
| char dir_path[1024]; | ||
|
|
||
| int ret; | ||
| static struct { | ||
| struct switchtec_dev *dev; | ||
| FILE *sjtag_debug_token; | ||
| const char *sjtag_debug_token_file; | ||
| int out_fd; | ||
| const char *out_filename; | ||
| bool verbose; | ||
| bool force_hr; | ||
| } cfg = { | ||
|
|
@@ -2322,17 +2322,29 @@ static int sjtag_unlock(int argc, char **argv) | |
|
|
||
| const struct argconfig_options opts[] = { | ||
| DEVICE_OPTION_MFG, | ||
| {"sjtag_debug_token_file", | ||
| .cfg_type=CFG_FILE_R, | ||
| .value_addr=&cfg.sjtag_debug_token, | ||
| .argument_type=optional_positional, | ||
| .help="Optional Argument. If not provided, the Debug Token will be generated\n"\ | ||
| "SJTAG Debug Token File(.bin)\n" \ | ||
| "Generated by the HSM Server\n"}, | ||
| {"verbose", 'v', "", CFG_NONE, &cfg.verbose, no_argument, | ||
| "print additional sjtag-unlock information"}, | ||
| {"force_hr", 'f', "", CFG_NONE, &cfg.force_hr, no_argument, | ||
| "send HR for all SJTAG mode"}, | ||
| { | ||
| "debug_token_input_file", 'i', | ||
| .cfg_type=CFG_FILE_R, | ||
| .value_addr=&cfg.sjtag_debug_token, | ||
| .argument_type=required_argument, | ||
| .help="Optional Argument. If not provided, the Debug Token will be generated\n" | ||
| }, | ||
| { | ||
| "debug_token_output_file", 'o', | ||
| .cfg_type=CFG_FD_WR, | ||
| .value_addr=&cfg.out_fd, | ||
| .argument_type=required_argument, | ||
| .force_default="sjtag_debug_token.bin", | ||
| .help="Optional Argument. If not provided, generated Debug Token File will be named sjtag_debug_token.bin\n" | ||
| }, | ||
| { | ||
| "verbose", 'v', "", CFG_NONE, &cfg.verbose, no_argument, | ||
| "print additional sjtag-unlock information" | ||
| }, | ||
| { | ||
| "force_hr", 'f', "", CFG_NONE, &cfg.force_hr, no_argument, | ||
| "send HR for all SJTAG mode" | ||
| }, | ||
| {NULL} | ||
| }; | ||
|
|
||
|
|
@@ -2400,18 +2412,16 @@ static int sjtag_unlock(int argc, char **argv) | |
| break; | ||
| } | ||
|
|
||
| debug_token_bin_file = fopen("sjtag_debug_token.bin", "wb"); | ||
| if (NULL == debug_token_bin_file) | ||
| /* Save the generated Debug Token as a binary */ | ||
| ret = write(cfg.out_fd, debug_token.debug_token, SJTAG_DEBUG_TOKEN_LEN); | ||
| if (ret < 0) | ||
| { | ||
| switchtec_perror("Error opening file"); | ||
| ret = -1; | ||
| break; | ||
| } | ||
|
|
||
| fwrite(debug_token.debug_token, sizeof(uint8_t), SJTAG_DEBUG_TOKEN_LEN, debug_token_bin_file); | ||
| fclose(debug_token_bin_file); | ||
| getcwd(dir_path, sizeof(dir_path)); | ||
| printf("Generated SJTAG Debug Token Path: %s/sjtag_debug_token.bin\n", dir_path); | ||
| switchtec_perror("Error saving the Debug token"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test this path by providing the invalid absolute path. |
||
| } | ||
| else | ||
| { | ||
| fprintf(stderr, "\nGenerated SJTAG Debug token saved to %s\n", cfg.out_filename); | ||
| } | ||
| } | ||
|
|
||
| ret = switchtec_sjtag_get_nonce(cfg.dev, &nonce); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it like if not provided, debug token will not be generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rarun-mchp both arguments 'i'(debug_token_input_file) and 'o'(debug_token_output_file) are optional.
'o' is for SJTAG unlocking with HSM
'i' is for SJTAG unlocking without HSM
'o' with file name - sjtag_debug_token.bin is the default
i.e., switchtec mfg sjtag-unlock
So, to answer your question, even if no arguments are provided, debug token bin will still be generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expand the help statement.