Skip to content

Commit

Permalink
Merge pull request #35 from arthursimchaev/dev
Browse files Browse the repository at this point in the history
Change the tool's version struct
  • Loading branch information
arthur-simchaev-sndk authored May 10, 2022
2 parents d21ec41 + 115f2f1 commit 40f78fa
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 28 deletions.
42 changes: 41 additions & 1 deletion options.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ static int verify_region(struct tool_options *options);
static int verify_and_set_hmr_method(struct tool_options *options);
static int verify_and_set_hmr_unit(struct tool_options *options);
static int verify_sg_struct(struct tool_options *options);
static int verify_output_data(struct tool_options *options);

#define MAX_ADDRESS 0xFFFF

Expand All @@ -48,9 +49,11 @@ int init_options(int opt_cnt, char *opt_arr[], struct tool_options *options)
static struct option long_opts[] = {
{"peer", no_argument, NULL, 'u'}, /* UFS device */
{"local", no_argument, NULL, 'l'}, /* UFS host*/
/* output file for the descriptor file store */
{"output_file", required_argument, NULL, 'D'},
{NULL, 0, NULL, 0}
};
static char *short_opts = "t:p:w:i:s:O:L:n:k:m:d:x:y:g:rocea";
static char *short_opts = "t:p:w:i:s:O:L:n:k:m:d:x:y:g:D:rocea";

while (-1 !=
(curr_opt = getopt_long(opt_cnt, opt_arr, short_opts,
Expand Down Expand Up @@ -132,6 +135,9 @@ int init_options(int opt_cnt, char *opt_arr[], struct tool_options *options)
case 'g':
rc = verify_sg_struct(options);
break;
case 'D':
rc = verify_output_data(options);
break;
default:
rc = -EINVAL;
break;
Expand Down Expand Up @@ -829,3 +835,37 @@ verify_and_set_flag_operation(int opr_type, struct tool_options *options)
return ERROR;
}

static int verify_output_data(struct tool_options *options)
{
int len;

if (options->data != 0) {
print_error("Duplicate Output path %d",
options->data);
goto out;
}

if (optarg == 0) {
print_error("Output path missed");
goto out;
}

len = strlen(optarg);
if (len >= PATH_MAX) {
print_error("Output path is too long");
goto out;
}

options->data = (char *)calloc(1, len);
if (!options->data) {
print_error("Memory Allocation problem");
goto out;
}

strcpy(options->data, optarg);
return OK;

out:
return ERROR;
}

4 changes: 2 additions & 2 deletions scsi_bsg_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ int write_buffer(int fd, __u8 *buf, __u8 mode, __u8 buf_id, __u32 buf_offset,
unsigned char write_buf_cmd [WRITE_BUF_CMDLEN] = {
WRITE_BUFFER_CMD, 0, 0, 0, 0, 0, 0, 0, 0, 0};

if (fd < 0 || buf == NULL || byte_count <= 0) {
if (fd < 0 || byte_count < 0) {
perror("scsi write cmd: wrong parameters");
return -EINVAL;
}
Expand All @@ -110,7 +110,7 @@ int read_buffer(int fd, __u8 *buf, __u8 mode, __u8 buf_id,
unsigned char read_buf_cmd[READ_BUF_CMDLEN] = {READ_BUFFER_CMD,
0, 0, 0, 0, 0, 0, 0, 0, 0};

if (fd < 0 || buf == NULL || byte_count <= 0) {
if (fd < 0 || byte_count < 0) {
print_error("scsi read cmd: wrong parameters");
return -EINVAL;
}
Expand Down
2 changes: 1 addition & 1 deletion ufs.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "ufs_rpmb.h"
#include "ufs_hmr.h"

#define UFS_BSG_UTIL_VERSION "1.10"
#define UFS_BSG_UTIL_VERSION "1.11.1"
typedef int (*command_function)(struct tool_options *opt);

struct tool_command {
Expand Down
43 changes: 19 additions & 24 deletions ufs_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ struct attr_fields ufs_attrs[] = {
{"bRefClkFreq", BYTE, (URD|UWRT), (READ_NRML|WRITE_PRSIST), DEV},
{"bConfigDescrLock", BYTE, (URD|UWRT), (READ_NRML|WRITE_ONCE), DEV},
{"bMaxNumOfRTT", BYTE, (URD|UWRT), (READ_NRML|WRITE_PRSIST), DEV},
{"wExceptionEventControl", WORD, URD, READ_NRML, DEV},
{"wExceptionEventControl", WORD, URD, (READ_NRML|WRITE_VLT), DEV},
{"wExceptionEventStatus", WORD, URD, READ_ONLY, DEV},
{"dSecondsPassed", DWORD, UWRT, WRITE_ONLY, DEV},
{"wContextConf", WORD, (URD|UWRT), (READ_NRML|WRITE_VLT), ARRAY},
Expand Down Expand Up @@ -527,6 +527,7 @@ void desc_help(char *tool_name)
printf("\t\t for String descriptor\n");
printf("\n\t-i\t Set index parameter(default = 0)\n");
printf("\n\t-s\t Set selector parameter(default = 0)\n");
printf("\n\t-D/--output_file Set descriptor file output path\n");
printf("\n\t-p\t path to ufs bsg device\n");
}

Expand Down Expand Up @@ -794,8 +795,6 @@ static int do_conf_desc(int fd, __u8 opt, __u8 index, char *data_file)
__u8 conf_desc_buf[QUERY_DESC_CONFIGURAION_MAX_SIZE] = {0};
int offset, i;
int data_fd = INVALID;
char *filename_header = "config_desc_data_ind_%d";
char output_file[30] = {0};

if (opt == WRITE) {
data_fd = open(data_file, O_RDONLY);
Expand Down Expand Up @@ -859,24 +858,24 @@ static int do_conf_desc(int fd, __u8 opt, __u8 index, char *data_file)
lun_off);
offset = offset + lun_off;
}
sprintf(output_file, filename_header, index);
data_fd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR);
if (data_fd < 0) {
perror("can't open output file");
return ERROR;
}
if (data_file) {
data_fd = open(data_file, O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR);
if (data_fd < 0) {
perror("can't open output file");
return ERROR;
}

rc = write(data_fd, conf_desc_buf, conf_desc_buf[0]);
if (rc <= 0) {
print_error("Could not write config data into %s file",
output_file);
rc = ERROR;
goto out;
}
rc = write(data_fd, conf_desc_buf, conf_desc_buf[0]);
if (rc <= 0) {
print_error("Could not write config data");
rc = ERROR;
goto out;
}

printf("Config Descriptor was written into %s file\n",
output_file);
printf("Config Descriptor was written into %s file\n",
data_file);
}
}
out:
if (data_fd != INVALID)
Expand Down Expand Up @@ -914,11 +913,7 @@ int do_desc(struct tool_options *opt)
rc = do_device_desc(fd, NULL);
break;
case QUERY_DESC_IDN_CONFIGURAION:
if (opt->opr == READ)
rc = do_conf_desc(fd, opt->opr, opt->index, NULL);
else
rc = do_conf_desc(fd, opt->opr, opt->index,
(char *)opt->data);
rc = do_conf_desc(fd, opt->opr, opt->index, (char *)opt->data);
break;
case QUERY_DESC_IDN_UNIT:
rc = do_unit_desc(fd, opt->index);
Expand Down

0 comments on commit 40f78fa

Please sign in to comment.