]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - init/main.c
bootconfig: Load boot config from the tail of initrd
[linux.git] / init / main.c
index 1ecfd43ed4643461af60bb47f5d4f61aad9b12af..59c418a57f92d022d23463697366c0781a872b87 100644 (file)
@@ -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>
@@ -93,7 +94,6 @@
 #include <linux/rodata_test.h>
 #include <linux/jump_label.h>
 #include <linux/mem_encrypt.h>
-#include <linux/file.h>
 
 #include <asm/io.h>
 #include <asm/bugs.h>
@@ -246,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)
@@ -596,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();
@@ -1158,26 +1211,13 @@ static int __ref kernel_init(void *unused)
 
 void console_on_rootfs(void)
 {
-       struct file *file;
-       unsigned int i;
-
-       /* Open /dev/console in kernelspace, this should never fail */
-       file = filp_open("/dev/console", O_RDWR, 0);
-       if (IS_ERR(file))
-               goto err_out;
-
-       /* create stdin/stdout/stderr, this should never fail */
-       for (i = 0; i < 3; i++) {
-               if (f_dupfd(i, file, 0) != i)
-                       goto err_out;
-       }
-
-       return;
+       /* Open the /dev/console as stdin, this should never fail */
+       if (ksys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
+               pr_err("Warning: unable to open an initial console.\n");
 
-err_out:
-       /* no panic -- this might not be fatal */
-       pr_err("Warning: unable to open an initial console.\n");
-       return;
+       /* create stdout/stderr */
+       (void) ksys_dup(0);
+       (void) ksys_dup(0);
 }
 
 static noinline void __init kernel_init_freeable(void)