Skip to content

Commit

Permalink
tools: bootconfig: Add bootconfig command
Browse files Browse the repository at this point in the history
Add "bootconfig" command which operates the bootconfig
config-data on initrd image.

User can add/delete/verify the boot config on initrd
image using this command.

e.g.
Add a boot config to initrd image
 # bootconfig -a myboot.conf /boot/initrd.img

Remove it.
 # bootconfig -d /boot/initrd.img

Or verify (and show) it.
 # bootconfig /boot/initrd.img

Link: http://lkml.kernel.org/r/157867223582.17873.14342161849213219982.stgit@devnote2

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
[ Removed extra blank line at end of bootconfig.c ]
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
  • Loading branch information
Masami Hiramatsu authored and Steven Rostedt (VMware) committed Jan 13, 2020
1 parent 7684b85 commit 950313e
Show file tree
Hide file tree
Showing 12 changed files with 481 additions and 5 deletions.
1 change: 1 addition & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -15775,6 +15775,7 @@ M: Masami Hiramatsu <mhiramat@kernel.org>
S: Maintained
F: lib/bootconfig.c
F: include/linux/bootconfig.h
F: tools/bootconfig/*

SUN3/3X
M: Sam Creasey <sammy@sammy.net>
Expand Down
11 changes: 6 additions & 5 deletions tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ help:
@echo ' pci - PCI tools'
@echo ' perf - Linux performance measurement and analysis tool'
@echo ' selftests - various kernel selftests'
@echo ' bootconfig - boot config tool'
@echo ' spi - spi tools'
@echo ' tmon - thermal monitoring and tuning tool'
@echo ' turbostat - Intel CPU idle stats and freq reporting tool'
Expand Down Expand Up @@ -63,7 +64,7 @@ acpi: FORCE
cpupower: FORCE
$(call descend,power/$@)

cgroup firewire hv guest spi usb virtio vm bpf iio gpio objtool leds wmi pci firmware debugging: FORCE
cgroup firewire hv guest bootconfig spi usb virtio vm bpf iio gpio objtool leds wmi pci firmware debugging: FORCE
$(call descend,$@)

liblockdep: FORCE
Expand Down Expand Up @@ -96,7 +97,7 @@ kvm_stat: FORCE
$(call descend,kvm/$@)

all: acpi cgroup cpupower gpio hv firewire liblockdep \
perf selftests spi turbostat usb \
perf selftests bootconfig spi turbostat usb \
virtio vm bpf x86_energy_perf_policy \
tmon freefall iio objtool kvm_stat wmi \
pci debugging
Expand All @@ -107,7 +108,7 @@ acpi_install:
cpupower_install:
$(call descend,power/$(@:_install=),install)

cgroup_install firewire_install gpio_install hv_install iio_install perf_install spi_install usb_install virtio_install vm_install bpf_install objtool_install wmi_install pci_install debugging_install:
cgroup_install firewire_install gpio_install hv_install iio_install perf_install bootconfig_install spi_install usb_install virtio_install vm_install bpf_install objtool_install wmi_install pci_install debugging_install:
$(call descend,$(@:_install=),install)

liblockdep_install:
Expand Down Expand Up @@ -141,7 +142,7 @@ acpi_clean:
cpupower_clean:
$(call descend,power/cpupower,clean)

cgroup_clean hv_clean firewire_clean spi_clean usb_clean virtio_clean vm_clean wmi_clean bpf_clean iio_clean gpio_clean objtool_clean leds_clean pci_clean firmware_clean debugging_clean:
cgroup_clean hv_clean firewire_clean bootconfig_clean spi_clean usb_clean virtio_clean vm_clean wmi_clean bpf_clean iio_clean gpio_clean objtool_clean leds_clean pci_clean firmware_clean debugging_clean:
$(call descend,$(@:_clean=),clean)

liblockdep_clean:
Expand Down Expand Up @@ -176,7 +177,7 @@ build_clean:
$(call descend,build,clean)

clean: acpi_clean cgroup_clean cpupower_clean hv_clean firewire_clean \
perf_clean selftests_clean turbostat_clean spi_clean usb_clean virtio_clean \
perf_clean selftests_clean turbostat_clean bootconfig_clean spi_clean usb_clean virtio_clean \
vm_clean bpf_clean iio_clean x86_energy_perf_policy_clean tmon_clean \
freefall_clean build_clean libbpf_clean libsubcmd_clean liblockdep_clean \
gpio_clean objtool_clean leds_clean wmi_clean pci_clean firmware_clean debugging_clean \
Expand Down
1 change: 1 addition & 0 deletions tools/bootconfig/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bootconfig
20 changes: 20 additions & 0 deletions tools/bootconfig/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# SPDX-License-Identifier: GPL-2.0
# Makefile for bootconfig command

bindir ?= /usr/bin

HEADER = include/linux/bootconfig.h
CFLAGS = -Wall -g -I./include

PROGS = bootconfig

all: $(PROGS)

bootconfig: ../../lib/bootconfig.c main.c $(HEADER)
$(CC) $(filter %.c,$^) $(CFLAGS) -o $@

install: $(PROGS)
install bootconfig $(DESTDIR)$(bindir)

clean:
$(RM) -f *.o bootconfig
7 changes: 7 additions & 0 deletions tools/bootconfig/include/linux/bootconfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _BOOTCONFIG_LINUX_BOOTCONFIG_H
#define _BOOTCONFIG_LINUX_BOOTCONFIG_H

#include "../../../../include/linux/bootconfig.h"

#endif
12 changes: 12 additions & 0 deletions tools/bootconfig/include/linux/bug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _SKC_LINUX_BUG_H
#define _SKC_LINUX_BUG_H

#include <stdio.h>
#include <stdlib.h>

#define WARN_ON(cond) \
((cond) ? printf("Internal warning(%s:%d, %s): %s\n", \
__FILE__, __LINE__, __func__, #cond) : 0)

#endif
7 changes: 7 additions & 0 deletions tools/bootconfig/include/linux/ctype.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _SKC_LINUX_CTYPE_H
#define _SKC_LINUX_CTYPE_H

#include <ctype.h>

#endif
7 changes: 7 additions & 0 deletions tools/bootconfig/include/linux/errno.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _SKC_LINUX_ERRNO_H
#define _SKC_LINUX_ERRNO_H

#include <asm/errno.h>

#endif
18 changes: 18 additions & 0 deletions tools/bootconfig/include/linux/kernel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _SKC_LINUX_KERNEL_H
#define _SKC_LINUX_KERNEL_H

#include <stdlib.h>
#include <stdbool.h>

#include <linux/printk.h>

typedef unsigned short u16;
typedef unsigned int u32;

#define unlikely(cond) (cond)

#define __init
#define __initdata

#endif
17 changes: 17 additions & 0 deletions tools/bootconfig/include/linux/printk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _SKC_LINUX_PRINTK_H
#define _SKC_LINUX_PRINTK_H

#include <stdio.h>

/* controllable printf */
extern int pr_output;
#define printk(fmt, ...) \
(pr_output ? printf(fmt, __VA_ARGS__) : 0)

#define pr_err printk
#define pr_warn printk
#define pr_info printk
#define pr_debug printk

#endif
32 changes: 32 additions & 0 deletions tools/bootconfig/include/linux/string.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _SKC_LINUX_STRING_H
#define _SKC_LINUX_STRING_H

#include <string.h>

/* Copied from lib/string.c */
static inline char *skip_spaces(const char *str)
{
while (isspace(*str))
++str;
return (char *)str;
}

static inline char *strim(char *s)
{
size_t size;
char *end;

size = strlen(s);
if (!size)
return s;

end = s + size - 1;
while (end >= s && isspace(*end))
end--;
*(end + 1) = '\0';

return skip_spaces(s);
}

#endif
Loading

0 comments on commit 950313e

Please sign in to comment.