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 MI EFI bootloader and AArch64 glue.



details:   https://anonhg.NetBSD.org/src/rev/994e9f9feec0
branches:  trunk
changeset: 992309:994e9f9feec0
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Fri Aug 24 02:01:06 2018 +0000

description:
Add MI EFI bootloader and AArch64 glue.

diffstat:

 sys/stand/efiboot/Makefile.efiboot       |  148 +++++++++++++++++++++++
 sys/stand/efiboot/boot.c                 |  144 ++++++++++++++++++++++
 sys/stand/efiboot/bootaa64/Makefile      |   14 ++
 sys/stand/efiboot/bootaa64/cache.S       |   98 +++++++++++++++
 sys/stand/efiboot/bootaa64/efibootaa64.c |   55 ++++++++
 sys/stand/efiboot/conf.c                 |   43 ++++++
 sys/stand/efiboot/console.c              |   63 ++++++++++
 sys/stand/efiboot/devopen.c              |   40 ++++++
 sys/stand/efiboot/devopen.h              |   34 +++++
 sys/stand/efiboot/efiboot.c              |  123 +++++++++++++++++++
 sys/stand/efiboot/efiboot.h              |   77 ++++++++++++
 sys/stand/efiboot/efiboot_machdep.h      |   33 +++++
 sys/stand/efiboot/efichar.c              |  195 +++++++++++++++++++++++++++++++
 sys/stand/efiboot/efifdt.c               |  124 +++++++++++++++++++
 sys/stand/efiboot/efifdt.h               |   33 +++++
 sys/stand/efiboot/efifile.c              |  163 +++++++++++++++++++++++++
 sys/stand/efiboot/efifile.h              |   33 +++++
 sys/stand/efiboot/efigetsecs.c           |   52 ++++++++
 sys/stand/efiboot/exec.c                 |   91 ++++++++++++++
 sys/stand/efiboot/panic.c                |   46 +++++++
 sys/stand/efiboot/prompt.c               |  152 ++++++++++++++++++++++++
 sys/stand/efiboot/version                |    7 +
 22 files changed, 1768 insertions(+), 0 deletions(-)

diffs (truncated from 1856 to 300 lines):

diff -r 4efda4a7b718 -r 994e9f9feec0 sys/stand/efiboot/Makefile.efiboot
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/stand/efiboot/Makefile.efiboot        Fri Aug 24 02:01:06 2018 +0000
@@ -0,0 +1,148 @@
+# $NetBSD: Makefile.efiboot,v 1.1 2018/08/24 02:01:06 jmcneill Exp $
+
+S=             ${.CURDIR}/../../..
+
+NOMAN=         # defined
+NOPIE=         # defined
+NOLIBCSANITIZER=# defined
+NOSANITIZER=   # defined
+NORELRO=       # defined
+PROG?=         boot.efi
+NEWVERSWHAT?=  "EFI Boot"
+
+EFIDIR= ${S}/external/bsd/gnu-efi/dist
+GNUEFIARCH?= ${MACHINE_CPU}
+CPPFLAGS+= -I${EFIDIR}/inc -I${EFIDIR}/inc/${GNUEFIARCH}
+CPPFLAGS+= -I${EFIDIR}/inc/protocol
+
+LDSCRIPT?= ${EFIDIR}/gnuefi/elf_${GNUEFIARCH}_efi.lds
+
+AFLAGS.start.S= ${${ACTIVE_CC} == "clang":?-no-integrated-as:}
+
+.PATH: ${EFIDIR}/gnuefi
+SOURCES=       crt0-efi-${GNUEFIARCH}.S reloc_${GNUEFIARCH}.c
+SOURCES+=      boot.c conf.c console.c devopen.c exec.c panic.c prompt.c
+SOURCES+=      efiboot.c efichar.c efifdt.c efifile.c
+
+.PATH: ${S}/external/bsd/libfdt/dist
+CPPFLAGS+=     -I${S}/external/bsd/libfdt/dist
+SOURCES+=      fdt.c fdt_addresses.c fdt_empty_tree.c
+SOURCES+=      fdt_ro.c fdt_rw.c fdt_strerror.c fdt_sw.c fdt_wip.c
+
+SRCS= ${SOURCES} ${EXTRA_SOURCES}
+
+.include <bsd.init.mk>
+
+STRIPFLAG=     # nothing
+
+LIBCRT0=       # nothing
+LIBCRTI=       # nothing
+LIBCRTBEGIN=   # nothing
+LIBCRTEND=     # nothing
+LIBC=          # nothing
+
+BINDIR=/usr/mdec
+BINMODE=444
+
+.PATH: ${.CURDIR} ${.CURDIR}/..
+.PATH: ${.CURDIR}/../../lib
+
+LDFLAGS+= -nostdlib -T${LDSCRIPT} -Bsymbolic -shared
+CPPFLAGS+= -I$S -I${.CURDIR} -I${.CURDIR}/../common -I$S/lib/libsa
+CPPFLAGS+= -I${.OBJDIR}
+CPPFLAGS+= -I${.CURDIR}/../../lib
+
+COPTS+=        -fpic -g -O2
+COPTS+=        -fshort-wchar -fno-strict-aliasing
+COPTS+=        -ffreestanding -fno-stack-protector
+LDFLAGS+= --defsym=EFI_SUBSYSTEM=0xa
+
+
+COPTS+= ${${ACTIVE_CC} == "gcc":? -Wno-error=unused-but-set-variable :}
+CPPFLAGS+= -nostdinc -D_STANDALONE
+CPPFLAGS+= -DEFIBOOT
+
+CPPFLAGS+= -Wall -Wmissing-prototypes
+CPPFLAGS+= -Wno-pointer-sign
+
+CPPFLAGS+= -DHEAP_VARIABLE
+#CPPFLAGS+= -DSUPPORT_CD9660
+CPPFLAGS+= -D"devb2cdb(bno)=(bno)"
+#CPPFLAGS+= -DSUPPORT_DOSFS
+#CPPFLAGS+= -DSUPPORT_EXT2FS
+#CPPFLAGS+= -DSUPPORT_BOOTP
+#CPPFLAGS+= -DSUPPORT_DHCP
+#CPPFLAGS+= -DSUPPORT_NFS
+#CPPFLAGS+= -DSUPPORT_TFTP
+#CPPFLAGS+= -DLIBSA_ENABLE_LS_OP
+
+#CPPFLAGS+= -DARP_DEBUG
+#CPPFLAGS+= -DBOOTP_DEBUG
+#CPPFLAGS+= -DNET_DEBUG
+#CPPFLAGS+= -DNETIF_DEBUG
+#CPPFLAGS+= -DNFS_DEBUG
+#CPPFLAGS+= -DRARP_DEBUG
+#CPPFLAGS+= -DRPC_DEBUG
+
+SAMISCCPPFLAGS+= -DLIBSA_PRINTF_LONGLONG_SUPPORT
+SAMISCCPPFLAGS+= -DLIBSA_PRINTF_WIDTH_SUPPORT
+SAMISCCPPFLAGS+= -D"cdb2devb(bno)=(bno)"
+
+### find out what to use for libsa
+SA_AS= library
+SAMISCMAKEFLAGS+="SA_USE_LOADFILE=yes"
+SAMISCMAKEFLAGS+="SA_USE_CREAD=yes"
+#SAMISCMAKEFLAGS+="SA_INCLUDE_NET=yes"
+#SAMISCMAKEFLAGS+="SA_ENABLE_LS_OP=yes"
+.include "${S}/lib/libsa/Makefile.inc"
+LIBSA= ${SALIB}
+
+### find out what to use for libkern
+KERN_AS= library
+LIBKERN_ARCH?= ${MACHINE_ARCH}
+KERNMISCMAKEFLAGS+="LIBKERN_ARCH=${LIBKERN_ARCH}"
+.include "${S}/lib/libkern/Makefile.inc"
+LIBKERN= ${KERNLIB}
+
+### find out what to use for libz
+Z_AS= library
+.include "${S}/lib/libz/Makefile.inc"
+LIBZ= ${ZLIB}
+
+### find out what to use for libgnuefi
+GNUEFI_AS= library
+LIBGNUEFI_ARCH?= ${MACHINE_ARCH}
+GNUEFIMISCMAKEFLAGS+="LIBGNUEFI_ARCH=${LIBGNUEFI_ARCH}"
+GNUEFIMISCCPPFLAGS+= -I${EFIDIR}/lib
+.include "${S}/lib/libgnuefi/Makefile.inc"
+LIBGNUEFI= ${GNUEFILIB}
+
+cleandir distclean: .WAIT cleanlibdir
+
+cleanlibdir:
+       -rm -rf lib
+
+LIBLIST= ${LIBGNUEFI} ${LIBSA} ${LIBZ} ${LIBKERN} ${LIBSA}
+
+VERSIONMACHINE=evbarm
+.include "${S}/conf/newvers_stand.mk"
+
+CLEANFILES+=   ${PROG}.so ${PROG}.tmp
+
+${PROG}: ${PROG}.so
+       ${OBJCOPY} -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel \
+           -j .rela -j .rel.* -j .rela.* -j .rel* -j .rela* \
+           -j .reloc -O binary ${PROG}.so ${.TARGET}
+
+.include <bsd.prog.mk>
+
+${PROG}.so: ${OBJS} ${LIBLIST} ${LDSCRIPT} ${.CURDIR}/../Makefile.efiboot
+       ${LD} ${LDFLAGS} -o ${.TARGET}.tmp ${OBJS} ${LIBLIST}
+       @if ${OBJDUMP} -t ${.TARGET}.tmp | grep 'UND'; then             \
+           (echo Undefined symbols; false);                            \
+       fi
+       rm -f ${.TARGET}
+       mv ${.TARGET}.tmp ${.TARGET}
+
+KLINK_MACHINE?=        ${MACHINE}
+.include <bsd.klinks.mk>
diff -r 4efda4a7b718 -r 994e9f9feec0 sys/stand/efiboot/boot.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/stand/efiboot/boot.c  Fri Aug 24 02:01:06 2018 +0000
@@ -0,0 +1,144 @@
+/*     $NetBSD: boot.c,v 1.1 2018/08/24 02:01:06 jmcneill Exp $        */
+
+/*-
+ * Copyright (c) 2016 Kimihiro Nonaka <nonaka%netbsd.org@localhost>
+ * Copyright (c) 2018 Jared McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * 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 REGENTS 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 REGENTS 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 <sys/bootblock.h>
+#include <sys/boot_flag.h>
+#include <machine/limits.h>
+
+#include <loadfile.h>
+
+extern const char bootprog_name[], bootprog_rev[], bootprog_kernrev[];
+
+extern char twiddle_toggle;
+
+static const char * const names[][2] = {
+       { "netbsd", "netbsd.gz" },
+       { "onetbsd", "onetbsd.gz" },
+       { "netbsd.old", "netbsd.old.gz" },
+};
+
+#define NUMNAMES       __arraycount(names)
+#define DEFFILENAME    names[0][0]
+
+#define        DEFTIMEOUT      5
+
+void   command_boot(char *);
+void   command_reset(char *);
+void   command_version(char *);
+void   command_quit(char *);
+
+const struct boot_command commands[] = {
+       { "boot",       command_boot,           "boot [fsN:][filename] [args]\n     (ex. \"fs0:\\netbsd.old -s\"" },
+       { "version",    command_version,        "version" },
+       { "help",       command_help,           "help|?" },
+       { "?",          command_help,           NULL },
+       { "quit",       command_quit,           "quit" },
+       { NULL,         NULL },
+};
+
+void
+command_help(char *arg)
+{
+       int n;
+
+       printf("commands are:\n");
+       for (n = 0; commands[n].c_name; n++) {
+               if (commands[n].c_help)
+                       printf("%s\n", commands[n].c_help);
+       }
+}
+
+void
+command_boot(char *arg)
+{
+       char *fname = arg;
+       char *bootargs = gettrailer(arg);
+
+       exec_netbsd(*fname ? fname : DEFFILENAME, bootargs);
+}
+
+void
+command_version(char *arg)
+{
+       char *ufirmware;
+       int rv;
+
+       printf("EFI version: %d.%02d\n",
+           ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff);
+       ufirmware = NULL;
+       rv = ucs2_to_utf8(ST->FirmwareVendor, &ufirmware);
+       if (rv == 0) {
+               printf("EFI Firmware: %s (rev %d.%02d)\n", ufirmware,
+                   ST->FirmwareRevision >> 16,
+                   ST->FirmwareRevision & 0xffff);
+               FreePool(ufirmware);
+       }
+}
+
+void
+command_quit(char *arg)
+{
+       efi_exit();
+}
+
+void
+print_banner(void)
+{
+       printf("\n\n"
+           ">> %s, Revision %s (from NetBSD %s)\n",
+           bootprog_name, bootprog_rev, bootprog_kernrev);
+}
+
+void
+boot(void)
+{
+       int currname, c;
+
+       print_banner();
+
+       printf("Press return to boot now, any other key for boot prompt\n");
+       for (currname = 0; currname < NUMNAMES; currname++) {
+               printf("booting %s - starting in ", names[currname][0]);
+
+               c = awaitkey(DEFTIMEOUT, 1);
+               if ((c != '\r') && (c != '\n') && (c != '\0')) {
+                       bootprompt(); /* does not return */
+               }
+
+               /*
+                * try pairs of names[] entries, foo and foo.gz
+                */
+               exec_netbsd(names[currname][0], "");
+               exec_netbsd(names[currname][1], "");
+       }
+
+       bootprompt();   /* does not return */
+}



Home | Main Index | Thread Index | Old Index