Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/stand/efiboot Add module support.



details:   https://anonhg.NetBSD.org/src/rev/094eff210026
branches:  trunk
changeset: 934984:094eff210026
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Jun 21 17:24:26 2020 +0000

description:
Add module support.

diffstat:

 sys/stand/efiboot/Makefile.efiboot  |    8 +-
 sys/stand/efiboot/boot.c            |   50 +++++++++++-
 sys/stand/efiboot/bootaa64/Makefile |    3 +-
 sys/stand/efiboot/bootarm/Makefile  |    3 +-
 sys/stand/efiboot/efifdt.c          |   17 +++-
 sys/stand/efiboot/efifdt.h          |    3 +-
 sys/stand/efiboot/exec.c            |   31 +++++++-
 sys/stand/efiboot/module.c          |  153 ++++++++++++++++++++++++++++++++++++
 sys/stand/efiboot/module.h          |   37 ++++++++
 sys/stand/efiboot/version           |    3 +-
 10 files changed, 298 insertions(+), 10 deletions(-)

diffs (truncated from 457 to 300 lines):

diff -r 5f5db9d0a763 -r 094eff210026 sys/stand/efiboot/Makefile.efiboot
--- a/sys/stand/efiboot/Makefile.efiboot        Sun Jun 21 17:17:01 2020 +0000
+++ b/sys/stand/efiboot/Makefile.efiboot        Sun Jun 21 17:24:26 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.efiboot,v 1.13 2020/05/14 19:19:08 riastradh Exp $
+# $NetBSD: Makefile.efiboot,v 1.14 2020/06/21 17:24:26 jmcneill Exp $
 
 S=             ${.CURDIR}/../../..
 
@@ -21,8 +21,10 @@
 
 .PATH: ${EFIDIR}/gnuefi
 SOURCES=       crt0-efi-${GNUEFIARCH}.S reloc_${GNUEFIARCH}.c
-SOURCES+=      boot.c conf.c console.c dev_net.c devopen.c exec.c panic.c prompt.c
-SOURCES+=      efiboot.c efichar.c efidev.c efienv.c efigetsecs.c efifdt.c efifile.c efiblock.c efinet.c efipxe.c efiacpi.c efirng.c smbios.c
+SOURCES+=      boot.c conf.c console.c dev_net.c devopen.c exec.c module.c \
+               panic.c prompt.c
+SOURCES+=      efiboot.c efichar.c efidev.c efienv.c efigetsecs.c efifdt.c \
+               efifile.c efiblock.c efinet.c efipxe.c efiacpi.c efirng.c smbios.c
 
 .PATH: ${S}/external/bsd/libfdt/dist
 CPPFLAGS+=     -I${S}/external/bsd/libfdt/dist
diff -r 5f5db9d0a763 -r 094eff210026 sys/stand/efiboot/boot.c
--- a/sys/stand/efiboot/boot.c  Sun Jun 21 17:17:01 2020 +0000
+++ b/sys/stand/efiboot/boot.c  Sun Jun 21 17:24:26 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: boot.c,v 1.21 2020/05/14 19:19:08 riastradh Exp $      */
+/*     $NetBSD: boot.c,v 1.22 2020/06/21 17:24:26 jmcneill Exp $       */
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <nonaka%netbsd.org@localhost>
@@ -33,6 +33,7 @@
 #include "efiacpi.h"
 #include "efienv.h"
 #include "efirng.h"
+#include "module.h"
 
 #include <sys/bootblock.h>
 #include <sys/boot_flag.h>
@@ -90,6 +91,9 @@
 void   command_plist(char *);
 void   command_initrd(char *);
 void   command_rndseed(char *);
+void   command_modules(char *);
+void   command_load(char *);
+void   command_unload(char *);
 void   command_ls(char *);
 void   command_mem(char *);
 void   command_printenv(char *);
@@ -107,6 +111,9 @@
        { "plist",      command_plist,          "plist [dev:][filename]" },
        { "initrd",     command_initrd,         "initrd [dev:][filename]" },
        { "rndseed",    command_rndseed,        "rndseed [dev:][filename]" },
+       { "modules",    command_modules,        "modules [{on|off|reset}]" },
+       { "load",       command_load,           "load <module_name>" },
+       { "unload",     command_unload,         "unload <module_name>" },
        { "ls",         command_ls,             "ls [hdNn:/path]" },
        { "mem",        command_mem,            "mem" },
        { "printenv",   command_printenv,       "printenv [key]" },
@@ -193,6 +200,47 @@
 }
 
 void
+command_modules(char *arg)
+{
+       if (arg && *arg) {
+               if (strcmp(arg, "on") == 0)
+                       module_enable(1);
+               else if (strcmp(arg, "off") == 0)
+                       module_enable(0);
+               else if (strcmp(arg, "reset") == 0)
+                       module_remove_all();
+               else {
+                       command_help("");
+                       return;
+               }
+       } else {
+               printf("modules are %sabled\n", module_enabled ? "en" : "dis");
+       }
+}
+
+void
+command_load(char *arg)
+{
+       if (!arg || !*arg) {
+               command_help("");
+               return;
+       }
+
+       module_add(arg);
+}
+
+void
+command_unload(char *arg)
+{
+       if (!arg || !*arg) {
+               command_help("");
+               return;
+       }
+
+       module_remove(arg);
+}
+
+void
 command_ls(char *arg)
 {
        ls(arg);
diff -r 5f5db9d0a763 -r 094eff210026 sys/stand/efiboot/bootaa64/Makefile
--- a/sys/stand/efiboot/bootaa64/Makefile       Sun Jun 21 17:17:01 2020 +0000
+++ b/sys/stand/efiboot/bootaa64/Makefile       Sun Jun 21 17:24:26 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.7 2020/01/25 11:24:20 jmcneill Exp $
+# $NetBSD: Makefile,v 1.8 2020/06/21 17:24:26 jmcneill Exp $
 
 PROG=          bootaa64.efi
 OBJFMT=                binary
@@ -12,6 +12,7 @@
 CFLAGS+=       -DEFIBOOT_RUNTIME_ADDRESS=0xffff800000000000L
 CFLAGS+=       -DEFIBOOT_RUNTIME_SIZE=0x40000000UL
 CFLAGS+=       -DEFIBOOT_ACPI
+CFLAGS+=       -DEFIBOOT_MODULE_MACHINE=\"evbarm\"
 
 .include "${.CURDIR}/../Makefile.efiboot"
 
diff -r 5f5db9d0a763 -r 094eff210026 sys/stand/efiboot/bootarm/Makefile
--- a/sys/stand/efiboot/bootarm/Makefile        Sun Jun 21 17:17:01 2020 +0000
+++ b/sys/stand/efiboot/bootarm/Makefile        Sun Jun 21 17:24:26 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.4 2020/01/25 11:24:20 jmcneill Exp $
+# $NetBSD: Makefile,v 1.5 2020/06/21 17:24:26 jmcneill Exp $
 
 PROG=          bootarm.efi
 OBJFMT=                binary
@@ -11,6 +11,7 @@
 
 COPTS+=                -mfloat-abi=soft -mno-unaligned-access -ffreestanding -fno-unwind-tables
 CFLAGS+=       -DEFIBOOT_ALIGN=0x1000000
+CFLAGS+=       -DEFIBOOT_MODULE_MACHINE=\"evbarm\"
 LDFLAGS+=      -N
 
 .include "${.CURDIR}/../Makefile.efiboot"
diff -r 5f5db9d0a763 -r 094eff210026 sys/stand/efiboot/efifdt.c
--- a/sys/stand/efiboot/efifdt.c        Sun Jun 21 17:17:01 2020 +0000
+++ b/sys/stand/efiboot/efifdt.c        Sun Jun 21 17:24:26 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.c,v 1.23 2020/05/14 19:21:53 riastradh Exp $ */
+/* $NetBSD: efifdt.c,v 1.24 2020/06/21 17:24:26 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -425,3 +425,18 @@
        fdt_setprop_u64(fdt_data, chosen, "netbsd,efirng-end",
            efirng_addr + efirng_size);
 }
+
+/* pass in module information */
+void
+efi_fdt_module(const char *module_name, u_long module_addr, u_long module_size)
+{
+       int chosen;
+
+       if (module_size == 0)
+               return;
+
+       chosen = efi_fdt_chosen();
+       fdt_appendprop_string(fdt_data, chosen, "netbsd,module-names", module_name);
+       fdt_appendprop_u64(fdt_data, chosen, "netbsd,modules", module_addr);
+       fdt_appendprop_u64(fdt_data, chosen, "netbsd,modules", module_size);
+}
diff -r 5f5db9d0a763 -r 094eff210026 sys/stand/efiboot/efifdt.h
--- a/sys/stand/efiboot/efifdt.h        Sun Jun 21 17:17:01 2020 +0000
+++ b/sys/stand/efiboot/efifdt.h        Sun Jun 21 17:24:26 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: efifdt.h,v 1.8 2020/05/14 19:20:08 riastradh Exp $ */
+/* $NetBSD: efifdt.h,v 1.9 2020/06/21 17:24:26 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -39,5 +39,6 @@
 void efi_fdt_initrd(u_long, u_long);
 void efi_fdt_rndseed(u_long, u_long);
 void efi_fdt_efirng(u_long, u_long);
+void efi_fdt_module(const char *, u_long, u_long);
 void efi_fdt_init(u_long, u_long);
 void efi_fdt_fini(void);
diff -r 5f5db9d0a763 -r 094eff210026 sys/stand/efiboot/exec.c
--- a/sys/stand/efiboot/exec.c  Sun Jun 21 17:17:01 2020 +0000
+++ b/sys/stand/efiboot/exec.c  Sun Jun 21 17:24:26 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: exec.c,v 1.15 2020/05/23 16:40:41 thorpej Exp $ */
+/* $NetBSD: exec.c,v 1.16 2020/06/21 17:24:26 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2019 Jason R. Thorpe
@@ -32,7 +32,9 @@
 #include "efifdt.h"
 #include "efiacpi.h"
 #include "efirng.h"
+#include "module.h"
 
+#include <sys/param.h>
 #include <sys/reboot.h>
 
 extern char twiddle_toggle;
@@ -276,6 +278,32 @@
 }
 
 static void
+load_module(const char *module_name)
+{
+       EFI_PHYSICAL_ADDRESS addr;
+       u_long size;
+       char path[PATH_MAX];
+
+       snprintf(path, sizeof(path), "%s/%s/%s.kmod", module_prefix,
+           module_name, module_name);
+
+       if (load_file(path, 0, false, &addr, &size) != 0 || addr == 0 || size == 0)
+               return;
+
+       efi_fdt_module(module_name, (u_long)addr, size);
+}
+
+static void
+load_modules(const char *kernel_name)
+{
+       if (!module_enabled)
+               return;
+
+       module_init(kernel_name);
+       module_foreach(load_module);
+}
+
+static void
 generate_efirng(void)
 {
        EFI_PHYSICAL_ADDRESS addr;
@@ -387,6 +415,7 @@
                    &rndseed_addr, &rndseed_size);
 
                efi_fdt_init((marks[MARK_END] + FDT_ALIGN) & ~FDT_ALIGN, FDT_ALIGN + 1);
+               load_modules(fname);
                load_fdt_overlays();
                efi_fdt_initrd(initrd_addr, initrd_size);
                efi_fdt_rndseed(rndseed_addr, rndseed_size);
diff -r 5f5db9d0a763 -r 094eff210026 sys/stand/efiboot/module.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/stand/efiboot/module.c        Sun Jun 21 17:24:26 2020 +0000
@@ -0,0 +1,153 @@
+/* $NetBSD: module.c,v 1.1 2020/06/21 17:24:26 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jared McNeill <jmcneill%invisible.ca@localhost>.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "efiboot.h"
+#include "module.h"
+
+#include <sys/queue.h>
+
+int module_enabled = 1;
+char module_prefix[128];
+
+struct boot_module {
+       char *module_name;
+       TAILQ_ENTRY(boot_module) entries;
+};
+TAILQ_HEAD(, boot_module) boot_modules = TAILQ_HEAD_INITIALIZER(boot_modules);
+
+static const char *
+module_machine(void)
+{
+       return EFIBOOT_MODULE_MACHINE;
+}
+



Home | Main Index | Thread Index | Old Index