Skip to content

Commit d4cefc0

Browse files
committed
rimage: add quiet mode option
Add -Q and --quiet to suppress informational stdout logs. This makes it easier to use rimage in scripts while keeping stderr for error reporting. Signed-off-by: Adrian Bonislawski <adrian.bonislawski@intel.com>
1 parent c64e373 commit d4cefc0

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

tools/rimage/src/rimage.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <stdlib.h>
77
#include <stdio.h>
88
#include <unistd.h>
9+
#include <getopt.h>
910
#include <errno.h>
1011
#include <string.h>
1112
#include <stdbool.h>
@@ -34,6 +35,7 @@ static void usage(char *name)
3435
fprintf(stdout, "\t -y verify signed file\n");
3536
fprintf(stdout, "\t -q resign binary\n");
3637
fprintf(stdout, "\t -p set PV bit\n");
38+
fprintf(stdout, "\t -Q --quiet suppress informational stdout logs\n");
3739
}
3840

3941
int main(int argc, char *argv[])
@@ -45,12 +47,18 @@ int main(int argc, char *argv[])
4547
int use_ext_man = 0;
4648
unsigned int pv_bit = 0;
4749
bool imr_type_override = false;
50+
bool quiet = false;
51+
static const struct option long_options[] = {
52+
{ "quiet", no_argument, NULL, 'Q' },
53+
{ NULL, 0, NULL, 0 }
54+
};
4855

4956
memset(&image, 0, sizeof(image));
5057

5158
image.imr_type = MAN_DEFAULT_IMR_TYPE;
5259

53-
while ((opt = getopt(argc, argv, "ho:va:s:k:ri:f:b:ec:y:q:pl")) != -1) {
60+
while ((opt = getopt_long(argc, argv, "ho:va:s:k:ri:f:b:ec:y:q:plQ",
61+
long_options, NULL)) != -1) {
5462
switch (opt) {
5563
case 'o':
5664
image.out_file = optarg;
@@ -101,6 +109,9 @@ int main(int argc, char *argv[])
101109
case 'l':
102110
image.loadable_module = true;
103111
break;
112+
case 'Q':
113+
quiet = true;
114+
break;
104115
default:
105116
/* getopt's default error message is good enough */
106117
return 1;
@@ -153,6 +164,10 @@ int main(int argc, char *argv[])
153164
return -EINVAL;
154165
}
155166
}
167+
168+
if (quiet && !freopen("/dev/null", "w", stdout))
169+
fprintf(stderr, "error: unable to redirect stdout: %s\n", strerror(errno));
170+
156171
/* find machine */
157172
heap_adsp = malloc(sizeof(struct adsp));
158173
if (!heap_adsp) {

0 commit comments

Comments
 (0)