Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 34 additions & 24 deletions cli/mfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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"
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expand the help statement.

},
{
"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}
};

Expand Down Expand Up @@ -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");
Copy link
Collaborator

Choose a reason for hiding this comment

The 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);
Expand Down