blob: 6cd6080cac04cf44517476b0378ddb500f39bd92 [file] [log] [blame]
Masami Hiramatsu950313e2020-01-11 01:03:56 +09001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Boot config tool for initrd image
4 */
5#include <stdio.h>
6#include <stdlib.h>
7#include <sys/types.h>
8#include <sys/stat.h>
9#include <fcntl.h>
10#include <unistd.h>
11#include <string.h>
12#include <errno.h>
Masami Hiramatsue8684352020-11-20 11:29:13 +090013#include <endian.h>
Masami Hiramatsu950313e2020-01-11 01:03:56 +090014
15#include <linux/kernel.h>
16#include <linux/bootconfig.h>
17
Masami Hiramatsue4f70b72020-08-10 17:34:51 +090018static int xbc_show_value(struct xbc_node *node, bool semicolon)
Masami Hiramatsu950313e2020-01-11 01:03:56 +090019{
Masami Hiramatsue4f70b72020-08-10 17:34:51 +090020 const char *val, *eol;
Masami Hiramatsu272da322020-06-16 19:14:17 +090021 char q;
Masami Hiramatsu950313e2020-01-11 01:03:56 +090022 int i = 0;
23
Masami Hiramatsue4f70b72020-08-10 17:34:51 +090024 eol = semicolon ? ";\n" : "\n";
Masami Hiramatsu950313e2020-01-11 01:03:56 +090025 xbc_array_for_each_value(node, val) {
Masami Hiramatsu272da322020-06-16 19:14:17 +090026 if (strchr(val, '"'))
27 q = '\'';
28 else
29 q = '"';
Masami Hiramatsue4f70b72020-08-10 17:34:51 +090030 printf("%c%s%c%s", q, val, q, node->next ? ", " : eol);
Masami Hiramatsu950313e2020-01-11 01:03:56 +090031 i++;
32 }
33 return i;
34}
35
36static void xbc_show_compact_tree(void)
37{
38 struct xbc_node *node, *cnode;
39 int depth = 0, i;
40
41 node = xbc_root_node();
42 while (node && xbc_node_is_key(node)) {
43 for (i = 0; i < depth; i++)
44 printf("\t");
45 cnode = xbc_node_get_child(node);
46 while (cnode && xbc_node_is_key(cnode) && !cnode->next) {
47 printf("%s.", xbc_node_get_data(node));
48 node = cnode;
49 cnode = xbc_node_get_child(node);
50 }
51 if (cnode && xbc_node_is_key(cnode)) {
52 printf("%s {\n", xbc_node_get_data(node));
53 depth++;
54 node = cnode;
55 continue;
56 } else if (cnode && xbc_node_is_value(cnode)) {
57 printf("%s = ", xbc_node_get_data(node));
Masami Hiramatsue4f70b72020-08-10 17:34:51 +090058 xbc_show_value(cnode, true);
Masami Hiramatsu950313e2020-01-11 01:03:56 +090059 } else {
60 printf("%s;\n", xbc_node_get_data(node));
61 }
62
63 if (node->next) {
64 node = xbc_node_get_next(node);
65 continue;
66 }
67 while (!node->next) {
68 node = xbc_node_get_parent(node);
69 if (!node)
70 return;
71 if (!xbc_node_get_child(node)->next)
72 continue;
73 depth--;
74 for (i = 0; i < depth; i++)
75 printf("\t");
76 printf("}\n");
77 }
78 node = xbc_node_get_next(node);
79 }
80}
81
Masami Hiramatsue4f70b72020-08-10 17:34:51 +090082static void xbc_show_list(void)
83{
84 char key[XBC_KEYLEN_MAX];
85 struct xbc_node *leaf;
86 const char *val;
87 int ret = 0;
88
89 xbc_for_each_key_value(leaf, val) {
90 ret = xbc_node_compose_key(leaf, key, XBC_KEYLEN_MAX);
91 if (ret < 0)
92 break;
93 printf("%s = ", key);
94 if (!val || val[0] == '\0') {
95 printf("\"\"\n");
96 continue;
97 }
98 xbc_show_value(xbc_node_get_child(leaf), false);
99 }
100}
101
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900102/* Simple real checksum */
Masami Hiramatsu483ce672020-08-10 17:35:01 +0900103static int checksum(unsigned char *buf, int len)
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900104{
105 int i, sum = 0;
106
107 for (i = 0; i < len; i++)
108 sum += buf[i];
109
110 return sum;
111}
112
113#define PAGE_SIZE 4096
114
Masami Hiramatsu483ce672020-08-10 17:35:01 +0900115static int load_xbc_fd(int fd, char **buf, int size)
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900116{
117 int ret;
118
119 *buf = malloc(size + 1);
120 if (!*buf)
121 return -ENOMEM;
122
123 ret = read(fd, *buf, size);
124 if (ret < 0)
125 return -errno;
126 (*buf)[size] = '\0';
127
128 return ret;
129}
130
131/* Return the read size or -errno */
Masami Hiramatsu483ce672020-08-10 17:35:01 +0900132static int load_xbc_file(const char *path, char **buf)
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900133{
134 struct stat stat;
135 int fd, ret;
136
137 fd = open(path, O_RDONLY);
138 if (fd < 0)
139 return -errno;
140 ret = fstat(fd, &stat);
141 if (ret < 0)
142 return -errno;
143
144 ret = load_xbc_fd(fd, buf, stat.st_size);
145
146 close(fd);
147
148 return ret;
149}
150
Masami Hiramatsua61ea632020-11-19 14:53:22 +0900151static int pr_errno(const char *msg, int err)
152{
153 pr_err("%s: %d\n", msg, err);
154 return err;
155}
156
Masami Hiramatsu483ce672020-08-10 17:35:01 +0900157static int load_xbc_from_initrd(int fd, char **buf)
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900158{
159 struct stat stat;
160 int ret;
161 u32 size = 0, csum = 0, rcsum;
Masami Hiramatsu85c46b72020-02-20 21:18:42 +0900162 char magic[BOOTCONFIG_MAGIC_LEN];
Masami Hiramatsu89b74ca2020-03-03 20:24:50 +0900163 const char *msg;
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900164
165 ret = fstat(fd, &stat);
166 if (ret < 0)
167 return -errno;
168
Masami Hiramatsu85c46b72020-02-20 21:18:42 +0900169 if (stat.st_size < 8 + BOOTCONFIG_MAGIC_LEN)
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900170 return 0;
171
Masami Hiramatsua61ea632020-11-19 14:53:22 +0900172 if (lseek(fd, -BOOTCONFIG_MAGIC_LEN, SEEK_END) < 0)
173 return pr_errno("Failed to lseek for magic", -errno);
174
Masami Hiramatsu85c46b72020-02-20 21:18:42 +0900175 if (read(fd, magic, BOOTCONFIG_MAGIC_LEN) < 0)
Masami Hiramatsua61ea632020-11-19 14:53:22 +0900176 return pr_errno("Failed to read", -errno);
177
Masami Hiramatsu85c46b72020-02-20 21:18:42 +0900178 /* Check the bootconfig magic bytes */
179 if (memcmp(magic, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN) != 0)
180 return 0;
181
Masami Hiramatsua61ea632020-11-19 14:53:22 +0900182 if (lseek(fd, -(8 + BOOTCONFIG_MAGIC_LEN), SEEK_END) < 0)
183 return pr_errno("Failed to lseek for size", -errno);
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900184
185 if (read(fd, &size, sizeof(u32)) < 0)
Masami Hiramatsua61ea632020-11-19 14:53:22 +0900186 return pr_errno("Failed to read size", -errno);
Masami Hiramatsue8684352020-11-20 11:29:13 +0900187 size = le32toh(size);
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900188
189 if (read(fd, &csum, sizeof(u32)) < 0)
Masami Hiramatsua61ea632020-11-19 14:53:22 +0900190 return pr_errno("Failed to read checksum", -errno);
Masami Hiramatsue8684352020-11-20 11:29:13 +0900191 csum = le32toh(csum);
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900192
Masami Hiramatsu85c46b72020-02-20 21:18:42 +0900193 /* Wrong size error */
194 if (stat.st_size < size + 8 + BOOTCONFIG_MAGIC_LEN) {
195 pr_err("bootconfig size is too big\n");
196 return -E2BIG;
197 }
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900198
Masami Hiramatsu85c46b72020-02-20 21:18:42 +0900199 if (lseek(fd, stat.st_size - (size + 8 + BOOTCONFIG_MAGIC_LEN),
Masami Hiramatsua61ea632020-11-19 14:53:22 +0900200 SEEK_SET) < 0)
201 return pr_errno("Failed to lseek", -errno);
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900202
203 ret = load_xbc_fd(fd, buf, size);
204 if (ret < 0)
205 return ret;
206
Masami Hiramatsu85c46b72020-02-20 21:18:42 +0900207 /* Wrong Checksum */
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900208 rcsum = checksum((unsigned char *)*buf, size);
209 if (csum != rcsum) {
Masami Hiramatsu97378002020-02-09 22:05:13 +0900210 pr_err("checksum error: %d != %d\n", csum, rcsum);
Masami Hiramatsu85c46b72020-02-20 21:18:42 +0900211 return -EINVAL;
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900212 }
213
Masami Hiramatsu89b74ca2020-03-03 20:24:50 +0900214 ret = xbc_init(*buf, &msg, NULL);
Masami Hiramatsu85c46b72020-02-20 21:18:42 +0900215 /* Wrong data */
Masami Hiramatsu89b74ca2020-03-03 20:24:50 +0900216 if (ret < 0) {
217 pr_err("parse error: %s.\n", msg);
Masami Hiramatsu85c46b72020-02-20 21:18:42 +0900218 return ret;
Masami Hiramatsu89b74ca2020-03-03 20:24:50 +0900219 }
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900220
221 return size;
222}
223
Masami Hiramatsud052e1c2020-08-10 17:34:41 +0900224static void show_xbc_error(const char *data, const char *msg, int pos)
225{
226 int lin = 1, col, i;
227
228 if (pos < 0) {
229 pr_err("Error: %s.\n", msg);
230 return;
231 }
232
233 /* Note that pos starts from 0 but lin and col should start from 1. */
234 col = pos + 1;
235 for (i = 0; i < pos; i++) {
236 if (data[i] == '\n') {
237 lin++;
238 col = pos - i;
239 }
240 }
241 pr_err("Parse Error: %s at %d:%d\n", msg, lin, col);
242
243}
244
245static int init_xbc_with_error(char *buf, int len)
246{
247 char *copy = strdup(buf);
248 const char *msg;
249 int ret, pos;
250
251 if (!copy)
252 return -ENOMEM;
253
254 ret = xbc_init(buf, &msg, &pos);
255 if (ret < 0)
256 show_xbc_error(copy, msg, pos);
257 free(copy);
258
259 return ret;
260}
261
Masami Hiramatsu483ce672020-08-10 17:35:01 +0900262static int show_xbc(const char *path, bool list)
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900263{
264 int ret, fd;
265 char *buf = NULL;
Masami Hiramatsud052e1c2020-08-10 17:34:41 +0900266 struct stat st;
267
268 ret = stat(path, &st);
269 if (ret < 0) {
Masami Hiramatsua61ea632020-11-19 14:53:22 +0900270 ret = -errno;
271 pr_err("Failed to stat %s: %d\n", path, ret);
272 return ret;
Masami Hiramatsud052e1c2020-08-10 17:34:41 +0900273 }
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900274
275 fd = open(path, O_RDONLY);
276 if (fd < 0) {
Masami Hiramatsua61ea632020-11-19 14:53:22 +0900277 ret = -errno;
278 pr_err("Failed to open initrd %s: %d\n", path, ret);
279 return ret;
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900280 }
281
282 ret = load_xbc_from_initrd(fd, &buf);
Masami Hiramatsud052e1c2020-08-10 17:34:41 +0900283 close(fd);
Masami Hiramatsuf91cb5b2020-06-16 19:14:25 +0900284 if (ret < 0) {
Masami Hiramatsu97378002020-02-09 22:05:13 +0900285 pr_err("Failed to load a boot config from initrd: %d\n", ret);
Masami Hiramatsuf91cb5b2020-06-16 19:14:25 +0900286 goto out;
287 }
Masami Hiramatsud052e1c2020-08-10 17:34:41 +0900288 /* Assume a bootconfig file if it is enough small */
289 if (ret == 0 && st.st_size <= XBC_DATA_MAX) {
290 ret = load_xbc_file(path, &buf);
291 if (ret < 0) {
292 pr_err("Failed to load a boot config: %d\n", ret);
293 goto out;
294 }
295 if (init_xbc_with_error(buf, ret) < 0)
296 goto out;
297 }
Masami Hiramatsue4f70b72020-08-10 17:34:51 +0900298 if (list)
299 xbc_show_list();
300 else
301 xbc_show_compact_tree();
Masami Hiramatsuf91cb5b2020-06-16 19:14:25 +0900302 ret = 0;
303out:
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900304 free(buf);
305
306 return ret;
307}
308
Masami Hiramatsu483ce672020-08-10 17:35:01 +0900309static int delete_xbc(const char *path)
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900310{
311 struct stat stat;
312 int ret = 0, fd, size;
313 char *buf = NULL;
314
315 fd = open(path, O_RDWR);
316 if (fd < 0) {
Masami Hiramatsua61ea632020-11-19 14:53:22 +0900317 ret = -errno;
318 pr_err("Failed to open initrd %s: %d\n", path, ret);
319 return ret;
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900320 }
321
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900322 size = load_xbc_from_initrd(fd, &buf);
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900323 if (size < 0) {
324 ret = size;
Masami Hiramatsu97378002020-02-09 22:05:13 +0900325 pr_err("Failed to load a boot config from initrd: %d\n", ret);
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900326 } else if (size > 0) {
327 ret = fstat(fd, &stat);
328 if (!ret)
Masami Hiramatsu85c46b72020-02-20 21:18:42 +0900329 ret = ftruncate(fd, stat.st_size
330 - size - 8 - BOOTCONFIG_MAGIC_LEN);
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900331 if (ret)
332 ret = -errno;
333 } /* Ignore if there is no boot config in initrd */
334
335 close(fd);
336 free(buf);
337
338 return ret;
339}
340
Masami Hiramatsu483ce672020-08-10 17:35:01 +0900341static int apply_xbc(const char *path, const char *xbc_path)
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900342{
Masami Hiramatsue1cef2d2020-11-19 14:53:40 +0900343 char *buf, *data, *p;
344 size_t total_size;
Masami Hiramatsua995e6b2020-11-19 14:53:31 +0900345 struct stat stat;
Masami Hiramatsu89b74ca2020-03-03 20:24:50 +0900346 const char *msg;
Masami Hiramatsue1cef2d2020-11-19 14:53:40 +0900347 u32 size, csum;
348 int pos, pad;
349 int ret, fd;
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900350
351 ret = load_xbc_file(xbc_path, &buf);
352 if (ret < 0) {
Masami Hiramatsu97378002020-02-09 22:05:13 +0900353 pr_err("Failed to load %s : %d\n", xbc_path, ret);
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900354 return ret;
355 }
356 size = strlen(buf) + 1;
357 csum = checksum((unsigned char *)buf, size);
358
Masami Hiramatsue1cef2d2020-11-19 14:53:40 +0900359 /* Backup the bootconfig data */
360 data = calloc(size + BOOTCONFIG_ALIGN +
361 sizeof(u32) + sizeof(u32) + BOOTCONFIG_MAGIC_LEN, 1);
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900362 if (!data)
363 return -ENOMEM;
Masami Hiramatsue1cef2d2020-11-19 14:53:40 +0900364 memcpy(data, buf, size);
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900365
366 /* Check the data format */
Masami Hiramatsu89b74ca2020-03-03 20:24:50 +0900367 ret = xbc_init(buf, &msg, &pos);
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900368 if (ret < 0) {
Masami Hiramatsu89b74ca2020-03-03 20:24:50 +0900369 show_xbc_error(data, msg, pos);
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900370 free(data);
371 free(buf);
Masami Hiramatsu89b74ca2020-03-03 20:24:50 +0900372
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900373 return ret;
374 }
375 printf("Apply %s to %s\n", xbc_path, path);
Masami Hiramatsu0f0d0a72020-02-05 22:50:13 +0900376 printf("\tNumber of nodes: %d\n", ret);
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900377 printf("\tSize: %u bytes\n", (unsigned int)size);
378 printf("\tChecksum: %d\n", (unsigned int)csum);
379
380 /* TODO: Check the options by schema */
381 xbc_destroy_all();
382 free(buf);
383
384 /* Remove old boot config if exists */
385 ret = delete_xbc(path);
386 if (ret < 0) {
Masami Hiramatsu97378002020-02-09 22:05:13 +0900387 pr_err("Failed to delete previous boot config: %d\n", ret);
Yunfeng Ye88426042020-05-07 17:23:36 +0800388 free(data);
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900389 return ret;
390 }
391
392 /* Apply new one */
393 fd = open(path, O_RDWR | O_APPEND);
394 if (fd < 0) {
Masami Hiramatsua61ea632020-11-19 14:53:22 +0900395 ret = -errno;
396 pr_err("Failed to open %s: %d\n", path, ret);
Yunfeng Ye88426042020-05-07 17:23:36 +0800397 free(data);
Masami Hiramatsua61ea632020-11-19 14:53:22 +0900398 return ret;
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900399 }
400 /* TODO: Ensure the @path is initramfs/initrd image */
Masami Hiramatsua995e6b2020-11-19 14:53:31 +0900401 if (fstat(fd, &stat) < 0) {
Zhen Leic9cb5832021-05-08 11:42:16 +0800402 ret = -errno;
Masami Hiramatsua995e6b2020-11-19 14:53:31 +0900403 pr_err("Failed to get the size of %s\n", path);
Yunfeng Ye88426042020-05-07 17:23:36 +0800404 goto out;
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900405 }
Masami Hiramatsue1cef2d2020-11-19 14:53:40 +0900406
407 /* To align up the total size to BOOTCONFIG_ALIGN, get padding size */
408 total_size = stat.st_size + size + sizeof(u32) * 2 + BOOTCONFIG_MAGIC_LEN;
409 pad = ((total_size + BOOTCONFIG_ALIGN - 1) & (~BOOTCONFIG_ALIGN_MASK)) - total_size;
410 size += pad;
411
412 /* Add a footer */
413 p = data + size;
Masami Hiramatsue8684352020-11-20 11:29:13 +0900414 *(u32 *)p = htole32(size);
Masami Hiramatsue1cef2d2020-11-19 14:53:40 +0900415 p += sizeof(u32);
416
Masami Hiramatsue8684352020-11-20 11:29:13 +0900417 *(u32 *)p = htole32(csum);
Masami Hiramatsue1cef2d2020-11-19 14:53:40 +0900418 p += sizeof(u32);
419
420 memcpy(p, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN);
421 p += BOOTCONFIG_MAGIC_LEN;
422
423 total_size = p - data;
424
425 ret = write(fd, data, total_size);
426 if (ret < total_size) {
Masami Hiramatsua995e6b2020-11-19 14:53:31 +0900427 if (ret < 0)
428 ret = -errno;
429 pr_err("Failed to apply a boot config: %d\n", ret);
Masami Hiramatsue1cef2d2020-11-19 14:53:40 +0900430 if (ret >= 0)
431 goto out_rollback;
432 } else
433 ret = 0;
434
Yunfeng Ye88426042020-05-07 17:23:36 +0800435out:
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900436 close(fd);
437 free(data);
438
Yunfeng Ye88426042020-05-07 17:23:36 +0800439 return ret;
Masami Hiramatsua995e6b2020-11-19 14:53:31 +0900440
441out_rollback:
442 /* Map the partial write to -ENOSPC */
443 if (ret >= 0)
444 ret = -ENOSPC;
445 if (ftruncate(fd, stat.st_size) < 0) {
446 ret = -errno;
447 pr_err("Failed to rollback the write error: %d\n", ret);
448 pr_err("The initrd %s may be corrupted. Recommend to rebuild.\n", path);
449 }
450 goto out;
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900451}
452
Masami Hiramatsu483ce672020-08-10 17:35:01 +0900453static int usage(void)
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900454{
455 printf("Usage: bootconfig [OPTIONS] <INITRD>\n"
Masami Hiramatsud052e1c2020-08-10 17:34:41 +0900456 "Or bootconfig <CONFIG>\n"
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900457 " Apply, delete or show boot config to initrd.\n"
458 " Options:\n"
459 " -a <config>: Apply boot config to initrd\n"
Masami Hiramatsue4f70b72020-08-10 17:34:51 +0900460 " -d : Delete boot config file from initrd\n"
461 " -l : list boot config in initrd or file\n\n"
Masami Hiramatsud052e1c2020-08-10 17:34:41 +0900462 " If no option is given, show the bootconfig in the given file.\n");
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900463 return -1;
464}
465
466int main(int argc, char **argv)
467{
468 char *path = NULL;
469 char *apply = NULL;
Masami Hiramatsue4f70b72020-08-10 17:34:51 +0900470 bool delete = false, list = false;
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900471 int opt;
472
Masami Hiramatsue4f70b72020-08-10 17:34:51 +0900473 while ((opt = getopt(argc, argv, "hda:l")) != -1) {
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900474 switch (opt) {
475 case 'd':
476 delete = true;
477 break;
478 case 'a':
479 apply = optarg;
480 break;
Masami Hiramatsue4f70b72020-08-10 17:34:51 +0900481 case 'l':
482 list = true;
483 break;
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900484 case 'h':
485 default:
486 return usage();
487 }
488 }
489
Masami Hiramatsue4f70b72020-08-10 17:34:51 +0900490 if ((apply && delete) || (delete && list) || (apply && list)) {
491 pr_err("Error: You can give one of -a, -d or -l at once.\n");
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900492 return usage();
493 }
494
495 if (optind >= argc) {
Masami Hiramatsu97378002020-02-09 22:05:13 +0900496 pr_err("Error: No initrd is specified.\n");
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900497 return usage();
498 }
499
500 path = argv[optind];
501
502 if (apply)
503 return apply_xbc(path, apply);
504 else if (delete)
505 return delete_xbc(path);
506
Masami Hiramatsue4f70b72020-08-10 17:34:51 +0900507 return show_xbc(path, list);
Masami Hiramatsu950313e2020-01-11 01:03:56 +0900508}