Skip to content

Commit

Permalink
bootconfig: Load boot config from the tail of initrd
Browse files Browse the repository at this point in the history
Load the extended boot config data from the tail of initrd
image. If there is an SKC data there, it has
[(u32)size][(u32)checksum] header (in really, this is a
footer) at the end of initrd. If the checksum (simple sum
of bytes) is match, this starts parsing it from there.

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

Signed-off-by: Masami Hiramatsu <[email protected]>
Signed-off-by: Steven Rostedt (VMware) <[email protected]>
  • Loading branch information
mhiramat authored and rostedt committed Jan 13, 2020
1 parent 76db5a2 commit 7684b85
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions init/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,7 @@ endif

config BOOT_CONFIG
bool "Boot config support"
depends on BLK_DEV_INITRD
select LIBXBC
default y
help
Expand Down
54 changes: 54 additions & 0 deletions init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <linux/initrd.h>
#include <linux/memblock.h>
#include <linux/acpi.h>
#include <linux/bootconfig.h>
#include <linux/console.h>
#include <linux/nmi.h>
#include <linux/percpu.h>
Expand Down Expand Up @@ -245,6 +246,58 @@ static int __init loglevel(char *str)

early_param("loglevel", loglevel);

#ifdef CONFIG_BOOT_CONFIG
u32 boot_config_checksum(unsigned char *p, u32 size)
{
u32 ret = 0;

while (size--)
ret += *p++;

return ret;
}

static void __init setup_boot_config(void)
{
u32 size, csum;
char *data, *copy;
u32 *hdr;

if (!initrd_end)
return;

hdr = (u32 *)(initrd_end - 8);
size = hdr[0];
csum = hdr[1];

if (size >= XBC_DATA_MAX)
return;

data = ((void *)hdr) - size;
if ((unsigned long)data < initrd_start)
return;

if (boot_config_checksum((unsigned char *)data, size) != csum)
return;

copy = memblock_alloc(size + 1, SMP_CACHE_BYTES);
if (!copy) {
pr_err("Failed to allocate memory for boot config\n");
return;
}

memcpy(copy, data, size);
copy[size] = '\0';

if (xbc_init(copy) < 0)
pr_err("Failed to parse boot config\n");
else
pr_info("Load boot config: %d bytes\n", size);
}
#else
#define setup_boot_config() do { } while (0)
#endif

/* Change NUL term back to "=", to make "param" the whole string. */
static int __init repair_env_string(char *param, char *val,
const char *unused, void *arg)
Expand Down Expand Up @@ -595,6 +648,7 @@ asmlinkage __visible void __init start_kernel(void)
pr_notice("%s", linux_banner);
early_security_init();
setup_arch(&command_line);
setup_boot_config();
setup_command_line(command_line);
setup_nr_cpu_ids();
setup_per_cpu_areas();
Expand Down

0 comments on commit 7684b85

Please sign in to comment.