Skip to content

Commit 066b5cc

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 678de87 commit 066b5cc

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>
@@ -35,6 +36,7 @@ static void usage(char *name)
3536
fprintf(stdout, "\t -q resign binary\n");
3637
fprintf(stdout, "\t -p set PV bit\n");
3738
fprintf(stdout, "\t -d ignore detached sections\n");
39+
fprintf(stdout, "\t -Q, --quiet suppress informational stdout logs\n");
3840
}
3941

4042
int main(int argc, char *argv[])
@@ -46,12 +48,18 @@ int main(int argc, char *argv[])
4648
int use_ext_man = 0;
4749
unsigned int pv_bit = 0;
4850
bool imr_type_override = false;
51+
bool quiet = false;
52+
static const struct option long_options[] = {
53+
{ "quiet", no_argument, NULL, 'Q' },
54+
{ NULL, 0, NULL, 0 }
55+
};
4956

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

5259
image.imr_type = MAN_DEFAULT_IMR_TYPE;
5360

54-
while ((opt = getopt(argc, argv, "ho:va:s:k:ri:f:b:ec:y:q:pld")) != -1) {
61+
while ((opt = getopt_long(argc, argv, "ho:va:s:k:ri:f:b:ec:y:q:pldQ",
62+
long_options, NULL)) != -1) {
5563
switch (opt) {
5664
case 'o':
5765
image.out_file = optarg;
@@ -106,6 +114,9 @@ int main(int argc, char *argv[])
106114
/* ignore detached sections */
107115
image.ignore_detached = true;
108116
break;
117+
case 'Q':
118+
quiet = true;
119+
break;
109120
default:
110121
/* getopt's default error message is good enough */
111122
return 1;
@@ -158,6 +169,10 @@ int main(int argc, char *argv[])
158169
return -EINVAL;
159170
}
160171
}
172+
173+
if (quiet && !freopen("/dev/null", "w", stdout))
174+
fprintf(stderr, "error: unable to redirect stdout: %s\n", strerror(errno));
175+
161176
/* find machine */
162177
heap_adsp = malloc(sizeof(struct adsp));
163178
if (!heap_adsp) {

0 commit comments

Comments
 (0)