diff options
Diffstat (limited to 'sys/boot/efi/loader')
-rw-r--r-- | sys/boot/efi/loader/Makefile | 102 | ||||
-rw-r--r-- | sys/boot/efi/loader/conf.c | 88 | ||||
-rw-r--r-- | sys/boot/efi/loader/main.c | 134 | ||||
-rw-r--r-- | sys/boot/efi/loader/version | 7 |
4 files changed, 331 insertions, 0 deletions
diff --git a/sys/boot/efi/loader/Makefile b/sys/boot/efi/loader/Makefile new file mode 100644 index 0000000..4fb3f0e --- /dev/null +++ b/sys/boot/efi/loader/Makefile @@ -0,0 +1,102 @@ +# $FreeBSD$ + +BASE= loader +PROG= ${BASE}.efi +NOMAN= +NEWVERSWHAT= "EFI boot" ${MACHINE_ARCH} + +.PATH: ${.CURDIR}/../common + +SRCS+= main.c conf.c + +# Enable BootForth +#BOOT_FORTH= yes +CFLAGS+= -I${.CURDIR}/../../ficl -I${.CURDIR}/../../ficl/alpha +.if BOOT_FORTH +CFLAGS+= -DBOOT_FORTH +.if exists(${.OBJDIR}/../../ficl/libficl.a) +LIBFICL= ${.OBJDIR}/../../ficl/libficl.a +.else +LIBFICL= ${.CURDIR}/../../ficl/libficl.a +.endif +.else +LIBFICL= +.endif + +# Always add MI sources +.PATH: ${.CURDIR}/../../common +.include <${.CURDIR}/../../common/Makefile.inc> +CFLAGS+= -I- +CFLAGS+= -I${.CURDIR}/../include +CFLAGS+= -I${.CURDIR}/../include/${MACHINE_ARCH} +CFLAGS+= -I${.CURDIR}/../../common -I${.CURDIR} +CFLAGS+= -I${.CURDIR}/../../.. -I. +CFLAGS+= -I${.CURDIR}/../libefi +CFLAGS+= -DLOADER +CFLAGS+= -Wall + +LDSCRIPT= ${.CURDIR}/../libefi/arch/${MACHINE_ARCH}/ldscript.${MACHINE_ARCH} +LDFLAGS= -nostdlib -T ${LDSCRIPT} -shared -Bsymbolic + +CLEANFILES+= setdef0.c setdef0.o setdef1.c setdef1.o setdefs.h start.o \ + vers.c vers.o ${BASE}.efi ${BASE}.sym ${BASE}.list +CLEANFILES+= loader.help +CLEANFILES+= machine + +CRT= start.o + +all: ${PROG} + +vers.o: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version + sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT} + ${CC} -c vers.c + +${BASE}.efi: ${BASE}.sym + ${OBJCOPY} -j .text \ + -j .hash \ + -j .data \ + -j .sdata \ + -j .dynamic \ + -j .rela \ + -j .reloc \ + -j .dynsym \ + --target=efi-app-${MACHINE_ARCH} \ + ${BASE}.sym ${BASE}.efi + +${BASE}.sym: ${OBJS} ${LIBSTAND} ${LIBARC} ${CRT} vers.o setdef0.o setdef1.o + ${LD} ${LDFLAGS} -o ${BASE}.sym -M \ + ${CRT} setdef0.o ${OBJS} setdef1.o vers.o \ + ${LIBFICL} ${LIBSTAND} ${LIBEFI} ${LIBSTAND} \ + > ${.OBJDIR}/${BASE}.list + +${BASE}.help: help.common help.efi + cat ${.ALLSRC} | awk -f ${.CURDIR}/../../common/merge_help.awk > ${.TARGET} + +beforeinstall: +.if exists(${.OBJDIR}/loader.help) + ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \ + ${.OBJDIR}/${BASE}.help ${DESTDIR}/boot +.else + ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 \ + ${.CURDIR}/${BASE}.help ${DESTDIR}/boot +.endif + +# Other fragments still to be brought in from ../Makfile.booters? +start.o: ${.CURDIR}/../libefi/arch/${MACHINE_ARCH}/start.S + ${CC} -c ${CFLAGS} $< + +setdef0.o: setdefs.h + +setdef1.o: setdefs.h + +machine: + ln -sf ${.CURDIR}/../../../${MACHINE_ARCH}/include machine + +.include <bsd.prog.mk> + +.ORDER: setdefs.h setdef0.c setdef1.c +setdefs.h setdef0.c setdef1.c: ${OBJS} + @echo Generating linker sets + @perl ${.CURDIR}/../../../kern/gensetdefs.pl ${OBJS} + +beforedepend ${OBJS}: machine diff --git a/sys/boot/efi/loader/conf.c b/sys/boot/efi/loader/conf.c new file mode 100644 index 0000000..49bfcc3 --- /dev/null +++ b/sys/boot/efi/loader/conf.c @@ -0,0 +1,88 @@ +/* + * $FreeBSD$ + * From $NetBSD: conf.c,v 1.2 1997/03/22 09:03:29 thorpej Exp $ + */ + +/* + * Copyright (c) 1997 + * Matthias Drochner. 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed for the NetBSD Project + * by Matthias Drochner. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 <stand.h> +#include <efi.h> +#include <efilib.h> + +#include "efiboot.h" + +/* + * We could use linker sets for some or all of these, but + * then we would have to control what ended up linked into + * the bootstrap. So it's easier to conditionalise things + * here. + * + * XXX rename these arrays to be consistent and less namespace-hostile + */ + +/* Exported for libstand */ +struct devsw *devsw[] = { +/* &efi_disk, */ + NULL +}; + +struct fs_ops *file_system[] = { + &ufs_fsops, + &zipfs_fsops, + NULL +}; + +/* Exported for ia64 only */ +/* + * Sort formats so that those that can detect based on arguments + * rather than reading the file go first. + */ +extern struct file_format ia64_elf; + +struct file_format *file_formats[] = { +/* &ia64_elf, */ + NULL +}; + +/* + * Consoles + * + * We don't prototype these in libalpha.h because they require + * data structures from bootstrap.h as well. + */ +extern struct console efi_console; + +struct console *consoles[] = { + &efi_console, + NULL +}; diff --git a/sys/boot/efi/loader/main.c b/sys/boot/efi/loader/main.c new file mode 100644 index 0000000..1caa84a --- /dev/null +++ b/sys/boot/efi/loader/main.c @@ -0,0 +1,134 @@ +/*- + * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> + * Copyright (c) 1998,2000 Doug Rabson <dfr@freebsd.org> + * 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 AUTHOR 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 AUTHOR 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. + * + * $FreeBSD$ + */ + +#include <stand.h> +#include <string.h> +#include <setjmp.h> + +#include <efi.h> +#include <efilib.h> + +#include "bootstrap.h" +#include "efiboot.h" + +extern char bootprog_name[]; +extern char bootprog_rev[]; +extern char bootprog_date[]; +extern char bootprog_maker[]; + +struct efi_devdesc currdev; /* our current device */ +struct arch_switch archsw; /* MI/MD interface boundary */ + +EFI_STATUS +efi_main (EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table) +{ + int i; + EFI_PHYSICAL_ADDRESS mem; + + efi_init(image_handle, system_table); + + /* + * Initialise the heap as early as possible. Once this is done, + * alloc() is usable. The stack is buried inside us, so this is + * safe. + */ + BS->AllocatePages(AllocateAnyPages, EfiLoaderData, + 512*1024/4096, &mem); + setheap((void *)mem, (void *)(mem + 512*1024)); + + /* + * XXX Chicken-and-egg problem; we want to have console output + * early, but some console attributes may depend on reading from + * eg. the boot device, which we can't do yet. We can use + * printf() etc. once this is done. + */ + cons_probe(); + + /* + * Initialise the block cache + */ + bcache_init(32, 512); /* 16k XXX tune this */ + + /* + * March through the device switch probing for things. + */ + for (i = 0; devsw[i] != NULL; i++) + if (devsw[i]->dv_init != NULL) + (devsw[i]->dv_init)(); + + printf("\n"); + printf("%s, Revision %s\n", bootprog_name, bootprog_rev); + printf("(%s, %s)\n", bootprog_maker, bootprog_date); +#if 0 + printf("Memory: %ld k\n", memsize() / 1024); +#endif + + /* We're booting from an SRM disk, try to spiff this */ + /* XXX presumes that biosdisk is first in devsw */ + currdev.d_dev = devsw[0]; + currdev.d_type = currdev.d_dev->dv_type; + currdev.d_kind.efidisk.unit = 0; + /* XXX should be able to detect this, default to autoprobe */ + currdev.d_kind.efidisk.slice = -1; + /* default to 'a' */ + currdev.d_kind.efidisk.partition = 0; + +#if 0 + /* Create arc-specific variables */ + bootfile = GetEnvironmentVariable(ARCENV_BOOTFILE); + if (bootfile) + setenv("bootfile", bootfile, 1); + + env_setenv("currdev", EV_VOLATILE, + arc_fmtdev(&currdev), arc_setcurrdev, env_nounset); + env_setenv("loaddev", EV_VOLATILE, + arc_fmtdev(&currdev), env_noset, env_nounset); +#endif + + setenv("LINES", "24", 1); /* optional */ + + archsw.arch_autoload = efi_autoload; + archsw.arch_getdev = efi_getdev; + archsw.arch_copyin = efi_copyin; + archsw.arch_copyout = efi_copyout; + archsw.arch_readin = efi_readin; + + interact(); /* doesn't return */ + + return EFI_SUCCESS; /* keep compiler happy */ +} + +COMMAND_SET(quit, "quit", "exit the loader", command_quit); + +static int +command_quit(int argc, char *argv[]) +{ + exit(0); + return(CMD_OK); +} diff --git a/sys/boot/efi/loader/version b/sys/boot/efi/loader/version new file mode 100644 index 0000000..d49b5ef --- /dev/null +++ b/sys/boot/efi/loader/version @@ -0,0 +1,7 @@ +$FreeBSD$ + +NOTE ANY CHANGES YOU MAKE TO THE BOOTBLOCKS HERE. The format of this +file is important. Make sure the current version number is on line 6. + +0.1: Initial EFI version, germinated from the NetBSD i386 + standalone, but enormously modified. |