mirror of https://github.com/thesofproject/sof.git
sof-ctl: add '-r' to support raw data mode
Using '-r' with '-s' means no abi header for the input file, and asks for not dumping abi header when using '-r' without '-s'. Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
This commit is contained in:
parent
0c2f1a6cdc
commit
fe28746bba
|
@ -64,6 +64,7 @@ static void usage(char *name)
|
||||||
fprintf(stdout, " -n control id e.g. 22\n");
|
fprintf(stdout, " -n control id e.g. 22\n");
|
||||||
fprintf(stdout, " -s set data using ASCII CSV input file\n");
|
fprintf(stdout, " -s set data using ASCII CSV input file\n");
|
||||||
fprintf(stdout, " -b set/get control in binary mode(e.g. for set, use binary input file, for get, dump out in hex format)\n");
|
fprintf(stdout, " -b set/get control in binary mode(e.g. for set, use binary input file, for get, dump out in hex format)\n");
|
||||||
|
fprintf(stdout, " -r no abi header for the input file, or not dumping abi header for get.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void header_init(struct ctl_data *ctl_data)
|
static void header_init(struct ctl_data *ctl_data)
|
||||||
|
@ -81,8 +82,11 @@ static int read_setup(struct ctl_data *ctl_data)
|
||||||
FILE *fh;
|
FILE *fh;
|
||||||
unsigned int x;
|
unsigned int x;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
struct sof_abi_hdr *hdr =
|
||||||
|
(struct sof_abi_hdr *)&ctl_data->buffer[2];
|
||||||
int n_max = ctl_data->ctrl_size / sizeof(unsigned int);
|
int n_max = ctl_data->ctrl_size / sizeof(unsigned int);
|
||||||
char *mode = ctl_data->binary ? "rb" : "r";
|
char *mode = ctl_data->binary ? "rb" : "r";
|
||||||
|
int abi_size = 0;
|
||||||
int separator;
|
int separator;
|
||||||
|
|
||||||
/* open input file */
|
/* open input file */
|
||||||
|
@ -93,10 +97,24 @@ static int read_setup(struct ctl_data *ctl_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctl_data->binary) {
|
if (ctl_data->binary) {
|
||||||
n = fread(&ctl_data->buffer[2], sizeof(int), n_max, fh);
|
/* create abi header*/
|
||||||
|
if (ctl_data->no_abi) {
|
||||||
|
header_init(ctl_data);
|
||||||
|
abi_size = sizeof(struct sof_abi_hdr) / sizeof(int);
|
||||||
|
}
|
||||||
|
|
||||||
|
n = fread(&ctl_data->buffer[2 + abi_size],
|
||||||
|
sizeof(int), n_max - abi_size, fh);
|
||||||
|
|
||||||
|
if (ctl_data->no_abi) {
|
||||||
|
hdr->size = n * sizeof(int);
|
||||||
|
n += abi_size;
|
||||||
|
}
|
||||||
|
|
||||||
goto read_done;
|
goto read_done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* reading for ASCII CSV txt */
|
||||||
while (fscanf(fh, "%u", &x) != EOF) {
|
while (fscanf(fh, "%u", &x) != EOF) {
|
||||||
if (n < n_max)
|
if (n < n_max)
|
||||||
ctl_data->buffer[2 + n] = x;
|
ctl_data->buffer[2 + n] = x;
|
||||||
|
@ -152,6 +170,14 @@ static void binary_data_dump(struct ctl_data *ctl_data)
|
||||||
/* exclude the type and size header */
|
/* exclude the type and size header */
|
||||||
int_offset = 2;
|
int_offset = 2;
|
||||||
|
|
||||||
|
/* exclude abi header if '-r' specified */
|
||||||
|
if (ctl_data->no_abi) {
|
||||||
|
int_offset += sizeof(struct sof_abi_hdr) /
|
||||||
|
sizeof(uint32_t);
|
||||||
|
n -= sizeof(struct sof_abi_hdr) /
|
||||||
|
sizeof(uint16_t);
|
||||||
|
}
|
||||||
|
|
||||||
/* get the dumping start address */
|
/* get the dumping start address */
|
||||||
config = (uint16_t *)&ctl_data->buffer[int_offset];
|
config = (uint16_t *)&ctl_data->buffer[int_offset];
|
||||||
|
|
||||||
|
@ -232,7 +258,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
ctl_data->dev = "hw:0";
|
ctl_data->dev = "hw:0";
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "hD:c:s:n:b")) != -1) {
|
while ((opt = getopt(argc, argv, "hD:c:s:n:br")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'D':
|
case 'D':
|
||||||
ctl_data->dev = optarg;
|
ctl_data->dev = optarg;
|
||||||
|
@ -252,6 +278,9 @@ int main(int argc, char *argv[])
|
||||||
case 'b':
|
case 'b':
|
||||||
ctl_data->binary = true;
|
ctl_data->binary = true;
|
||||||
break;
|
break;
|
||||||
|
case 'r':
|
||||||
|
ctl_data->no_abi = true;
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -314,6 +343,10 @@ int main(int argc, char *argv[])
|
||||||
fprintf(stderr, "Error: Input file unavailable.\n");
|
fprintf(stderr, "Error: Input file unavailable.\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* need more space for raw data file(no header in the file) */
|
||||||
|
if (ctl_data->no_abi)
|
||||||
|
ctl_data->ctrl_size += sizeof(struct sof_abi_hdr);
|
||||||
} else {
|
} else {
|
||||||
/* Get control attributes from info. */
|
/* Get control attributes from info. */
|
||||||
ctl_data->ctrl_size =
|
ctl_data->ctrl_size =
|
||||||
|
|
Loading…
Reference in New Issue