main.c (4353dd3b70783ebbc83fcf12d9c0af3fbab0223b) main.c (8842604446d1f005abcbf8c63c12eabdb5695094)
1// 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>

--- 300 unchanged lines hidden (view full) ---

309 /* TODO: Check the options by schema */
310 xbc_destroy_all();
311 free(buf);
312
313 /* Remove old boot config if exists */
314 ret = delete_xbc(path);
315 if (ret < 0) {
316 pr_err("Failed to delete previous boot config: %d\n", ret);
1// 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>

--- 300 unchanged lines hidden (view full) ---

309 /* TODO: Check the options by schema */
310 xbc_destroy_all();
311 free(buf);
312
313 /* Remove old boot config if exists */
314 ret = delete_xbc(path);
315 if (ret < 0) {
316 pr_err("Failed to delete previous boot config: %d\n", ret);
317 free(data);
317 return ret;
318 }
319
320 /* Apply new one */
321 fd = open(path, O_RDWR | O_APPEND);
322 if (fd < 0) {
323 pr_err("Failed to open %s: %d\n", path, fd);
318 return ret;
319 }
320
321 /* Apply new one */
322 fd = open(path, O_RDWR | O_APPEND);
323 if (fd < 0) {
324 pr_err("Failed to open %s: %d\n", path, fd);
325 free(data);
324 return fd;
325 }
326 /* TODO: Ensure the @path is initramfs/initrd image */
327 ret = write(fd, data, size + 8);
328 if (ret < 0) {
329 pr_err("Failed to apply a boot config: %d\n", ret);
326 return fd;
327 }
328 /* TODO: Ensure the @path is initramfs/initrd image */
329 ret = write(fd, data, size + 8);
330 if (ret < 0) {
331 pr_err("Failed to apply a boot config: %d\n", ret);
330 return ret;
332 goto out;
331 }
332 /* Write a magic word of the bootconfig */
333 ret = write(fd, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN);
334 if (ret < 0) {
335 pr_err("Failed to apply a boot config magic: %d\n", ret);
333 }
334 /* Write a magic word of the bootconfig */
335 ret = write(fd, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN);
336 if (ret < 0) {
337 pr_err("Failed to apply a boot config magic: %d\n", ret);
336 return ret;
338 goto out;
337 }
339 }
340out:
338 close(fd);
339 free(data);
340
341 close(fd);
342 free(data);
343
341 return 0;
344 return ret;
342}
343
344int usage(void)
345{
346 printf("Usage: bootconfig [OPTIONS] <INITRD>\n"
347 " Apply, delete or show boot config to initrd.\n"
348 " Options:\n"
349 " -a <config>: Apply boot config to initrd\n"

--- 45 unchanged lines hidden ---
345}
346
347int usage(void)
348{
349 printf("Usage: bootconfig [OPTIONS] <INITRD>\n"
350 " Apply, delete or show boot config to initrd.\n"
351 " Options:\n"
352 " -a <config>: Apply boot config to initrd\n"

--- 45 unchanged lines hidden ---