Move the efi loaders to be under sys/boot/efi. This will help us add

support for booting arm and arm64 from UEFI.

Differential Revision:	https://reviews.freebsd.org/D2164
Reviewed by:	emaste, imp (previous version)
Sponsored by:	The FreeBSD Foundation
This commit is contained in:
andrew 2015-04-01 08:30:40 +00:00
parent b7c417708f
commit 0c094dfe11
26 changed files with 92 additions and 96 deletions

View File

@ -1,7 +0,0 @@
# $FreeBSD$
.include <bsd.own.mk>
SUBDIR= efi boot1.efi
.include <bsd.subdir.mk>

View File

@ -1,12 +0,0 @@
# Common defines for all of /sys/boot/amd64/
#
# $FreeBSD$
BINDIR?= /boot
# See conf/kern.mk for the correct set of these
CFLAGS+= -ffreestanding -mno-red-zone
CFLAGS+= -mno-mmx -mno-sse -mno-aes -mno-avx -msoft-float
LDFLAGS+= -nostdlib
.include "../Makefile.inc"

View File

@ -2,4 +2,8 @@
SUBDIR= libefi
.if ${MACHINE_CPUARCH} == "amd64"
SUBDIR+= loader boot1
.endif
.include <bsd.subdir.mk>

View File

@ -7,7 +7,10 @@ CFLAGS+= -march=i386
.endif
# Options used when building app-specific efi components
# See conf/kern.mk for the correct set of these
CFLAGS+= -ffreestanding -fshort-wchar -Wformat
CFLAGS+= -mno-red-zone
CFLAGS+= -mno-mmx -mno-sse -mno-aes -mno-avx -msoft-float
LDFLAGS+= -nostdlib
.include "../Makefile.inc"

View File

@ -17,19 +17,19 @@ SRCS= boot1.c reloc.c start.S
CFLAGS+= -fPIC
CFLAGS+= -I.
CFLAGS+= -I${.CURDIR}/../../efi/include
CFLAGS+= -I${.CURDIR}/../../efi/include/${MACHINE_CPUARCH}
CFLAGS+= -I${.CURDIR}/../include
CFLAGS+= -I${.CURDIR}/../include/${MACHINE_CPUARCH}
CFLAGS+= -I${.CURDIR}/../../../contrib/dev/acpica/include
CFLAGS+= -I${.CURDIR}/../../..
# Always add MI sources and REGULAR efi loader bits
.PATH: ${.CURDIR}/../efi ${.CURDIR}/../../common
.PATH: ${.CURDIR}/../loader/arch/amd64 ${.CURDIR}/../../common
CFLAGS+= -I${.CURDIR}/../../common
FILES= boot1.efi boot1.efifat
FILESMODE_boot1.efi= ${BINMODE}
LDSCRIPT= ${.CURDIR}/../efi/ldscript.${MACHINE_CPUARCH}
LDSCRIPT= ${.CURDIR}/../loader/arch/${MACHINE_CPUARCH}/ldscript.${MACHINE_CPUARCH}
LDFLAGS= -Wl,-T${LDSCRIPT} -Wl,-Bsymbolic -shared -Wl,-znocombreloc
${PROG}: ${LDSCRIPT}
@ -39,7 +39,7 @@ OBJDUMP?= objdump
.if ${MACHINE_CPUARCH} == "amd64"
EFI_TARGET= efi-app-x86_64
.else
.elif ${MACHINE_CPUARCH} == "i386"
EFI_TARGET= efi-app-ia32
.endif

View File

@ -12,27 +12,24 @@ MK_SSP= no
PROG= loader.sym
INTERNALPROG=
.PATH: ${.CURDIR}/../../efi/loader
# architecture-specific loader code
SRCS= autoload.c \
bootinfo.c \
conf.c \
copy.c \
devicename.c \
elf64_freebsd.c \
framebuffer.c \
main.c \
reloc.c \
vers.c
SRCS+= amd64_tramp.S \
start.S
.PATH: ${.CURDIR}/../../i386/libi386
SRCS+= nullconsole.c \
comconsole.c
.PATH: ${.CURDIR}/arch/${MACHINE_CPUARCH}
.include "${.CURDIR}/arch/${MACHINE_CPUARCH}/Makefile.inc"
CFLAGS+= -fPIC
CFLAGS+= -I.
CFLAGS+= -I${.CURDIR}/../../efi/include
CFLAGS+= -I${.CURDIR}/../../efi/include/${MACHINE_CPUARCH}
CFLAGS+= -I${.CURDIR}
CFLAGS+= -I${.CURDIR}/arch/${MACHINE_CPUARCH}
CFLAGS+= -I${.CURDIR}/../include
CFLAGS+= -I${.CURDIR}/../include/${MACHINE_CPUARCH}
CFLAGS+= -I${.CURDIR}/../../../contrib/dev/acpica/include
CFLAGS+= -I${.CURDIR}/../../..
CFLAGS+= -DNO_PCI
@ -60,14 +57,14 @@ CFLAGS+= -I${.CURDIR}/../../common
FILES= loader.efi
FILESMODE_loader.efi= ${BINMODE}
LDSCRIPT= ${.CURDIR}/ldscript.${MACHINE_CPUARCH}
LDSCRIPT= ${.CURDIR}/arch/${MACHINE_CPUARCH}/ldscript.${MACHINE_CPUARCH}
LDFLAGS= -Wl,-T${LDSCRIPT} -Wl,-Bsymbolic -shared -Wl,-znocombreloc
CLEANFILES= vers.c loader.efi
NEWVERSWHAT= "EFI loader" ${MACHINE_CPUARCH}
vers.c: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version
vers.c: ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/../../efi/loader/version
sh ${.CURDIR}/../../common/newvers.sh ${.CURDIR}/version ${NEWVERSWHAT}
OBJCOPY?= objcopy
@ -75,7 +72,7 @@ OBJDUMP?= objdump
.if ${MACHINE_CPUARCH} == "amd64"
EFI_TARGET= efi-app-x86_64
.else
.elif ${MACHINE_CPUARCH} == "i386"
EFI_TARGET= efi-app-ia32
.endif
@ -89,7 +86,7 @@ loader.efi: loader.sym
-j .rela.dyn -j .reloc -j .eh_frame -j set_Xcommand_set \
--output-target=${EFI_TARGET} ${.ALLSRC} ${.TARGET}
LIBEFI= ${.OBJDIR}/../../efi/libefi/libefi.a
LIBEFI= ${.OBJDIR}/../libefi/libefi.a
DPADD= ${LIBFICL} ${LIBEFI} ${LIBSTAND} ${LDSCRIPT}
LDADD= ${LIBFICL} ${LIBEFI} ${LIBSTAND}

View File

@ -0,0 +1,11 @@
# $FreeBSD$
SRCS+= amd64_tramp.S \
start.S \
framebuffer.c \
elf64_freebsd.c \
reloc.c
.PATH: ${.CURDIR}/../../i386/libi386
SRCS+= nullconsole.c \
comconsole.c

View File

@ -47,7 +47,7 @@ __FBSDID("$FreeBSD$");
#include "actypes.h"
#include "actbl.h"
#include "x86_efi.h"
#include "loader_efi.h"
static EFI_GUID acpi_guid = ACPI_TABLE_GUID;
static EFI_GUID acpi20_guid = ACPI_20_TABLE_GUID;
@ -57,8 +57,14 @@ extern int bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp);
static int elf64_exec(struct preloaded_file *amp);
static int elf64_obj_exec(struct preloaded_file *amp);
struct file_format amd64_elf = { elf64_loadfile, elf64_exec };
struct file_format amd64_elf_obj = { elf64_obj_loadfile, elf64_obj_exec };
static struct file_format amd64_elf = { elf64_loadfile, elf64_exec };
static struct file_format amd64_elf_obj = { elf64_obj_loadfile, elf64_obj_exec };
struct file_format *file_formats[] = {
&amd64_elf,
&amd64_elf_obj,
NULL
};
#define PG_V 0x001
#define PG_RW 0x002
@ -168,7 +174,7 @@ elf64_exec(struct preloaded_file *fp)
if (err != 0)
return(err);
status = BS->ExitBootServices(IH, x86_efi_mapkey);
status = BS->ExitBootServices(IH, efi_mapkey);
if (EFI_ERROR(status)) {
printf("%s: ExitBootServices() returned 0x%lx\n", __func__,
(long)status);
@ -177,7 +183,7 @@ elf64_exec(struct preloaded_file *fp)
dev_cleanup();
trampoline(trampstack, x86_efi_copy_finish, kernend, modulep, PT4,
trampoline(trampstack, efi_copy_finish, kernend, modulep, PT4,
ehdr->e_entry);
panic("exec returned");

View File

@ -28,7 +28,7 @@
__FBSDID("$FreeBSD$");
int
x86_efi_autoload(void)
efi_autoload(void)
{
return (0);

View File

@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
#include <sys/linker.h>
#include <sys/boot.h>
#include <machine/cpufunc.h>
#include <machine/elf.h>
#include <machine/metadata.h>
#include <machine/psl.h>
#include <machine/specialreg.h>
@ -45,9 +46,9 @@ __FBSDID("$FreeBSD$");
#include "bootstrap.h"
#include "framebuffer.h"
#include "x86_efi.h"
#include "loader_efi.h"
UINTN x86_efi_mapkey;
UINTN efi_mapkey;
static const char howto_switches[] = "aCdrgDmphsv";
static int howto_masks[] = {
@ -260,7 +261,7 @@ bi_load_efi_data(struct preloaded_file *kfp)
* one is marked as being loader data.
*/
sz = 0;
BS->GetMemoryMap(&sz, NULL, &x86_efi_mapkey, &mmsz, &mmver);
BS->GetMemoryMap(&sz, NULL, &efi_mapkey, &mmsz, &mmver);
sz += mmsz;
sz = (sz + 0xf) & ~0xf;
pages = EFI_SIZE_TO_PAGES(sz + efisz);
@ -280,7 +281,7 @@ bi_load_efi_data(struct preloaded_file *kfp)
efihdr = (struct efi_map_header *)addr;
mm = (void *)((uint8_t *)efihdr + efisz);
sz = (EFI_PAGE_SIZE * pages) - efisz;
status = BS->GetMemoryMap(&sz, mm, &x86_efi_mapkey, &mmsz, &mmver);
status = BS->GetMemoryMap(&sz, mm, &efi_mapkey, &mmsz, &mmver);
if (EFI_ERROR(status)) {
printf("%s: GetMemoryMap() returned 0x%lx\n", __func__,
(long)status);
@ -333,7 +334,7 @@ bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp)
}
/* Try reading the /etc/fstab file to select the root device */
getrootmount(x86_efi_fmtdev((void *)rootdev));
getrootmount(efi_fmtdev((void *)rootdev));
addr = 0;
for (xp = file_findfile(NULL, NULL); xp != NULL; xp = xp->f_next) {
@ -375,6 +376,6 @@ bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp)
/* Copy module list and metadata. */
(void)bi_copymodules(addr);
return (0);
}

View File

@ -53,15 +53,6 @@ struct netif_driver *netif_drivers[] = {
NULL
};
extern struct file_format amd64_elf;
extern struct file_format amd64_elf_obj;
struct file_format *file_formats[] = {
&amd64_elf,
&amd64_elf_obj,
NULL
};
extern struct console efi_console;
extern struct console comconsole;
extern struct console nullconsole;

View File

@ -48,7 +48,7 @@ int stage_offset_set = 0;
ssize_t stage_offset;
int
x86_efi_copy_init(void)
efi_copy_init(void)
{
EFI_STATUS status;
@ -65,7 +65,7 @@ x86_efi_copy_init(void)
}
ssize_t
x86_efi_copyin(const void *src, vm_offset_t dest, const size_t len)
efi_copyin(const void *src, vm_offset_t dest, const size_t len)
{
if (!stage_offset_set) {
@ -83,7 +83,7 @@ x86_efi_copyin(const void *src, vm_offset_t dest, const size_t len)
}
ssize_t
x86_efi_copyout(const vm_offset_t src, void *dest, const size_t len)
efi_copyout(const vm_offset_t src, void *dest, const size_t len)
{
/* XXX: Callers do not check for failure. */
@ -97,7 +97,7 @@ x86_efi_copyout(const vm_offset_t src, void *dest, const size_t len)
ssize_t
x86_efi_readin(const int fd, vm_offset_t dest, const size_t len)
efi_readin(const int fd, vm_offset_t dest, const size_t len)
{
if (dest + stage_offset + len > staging_end) {
@ -108,7 +108,7 @@ x86_efi_readin(const int fd, vm_offset_t dest, const size_t len)
}
void
x86_efi_copy_finish(void)
efi_copy_finish(void)
{
uint64_t *src, *dst, *last;

View File

@ -36,7 +36,7 @@ __FBSDID("$FreeBSD$");
#include <efi.h>
#include <efilib.h>
static int x86_efi_parsedev(struct devdesc **, const char *, const char **);
static int efi_parsedev(struct devdesc **, const char *, const char **);
/*
* Point (dev) at an allocated device specifier for the device matching the
@ -44,7 +44,7 @@ static int x86_efi_parsedev(struct devdesc **, const char *, const char **);
* use that. If not, use the default device.
*/
int
x86_efi_getdev(void **vdev, const char *devspec, const char **path)
efi_getdev(void **vdev, const char *devspec, const char **path)
{
struct devdesc **dev = (struct devdesc **)vdev;
int rv;
@ -54,14 +54,14 @@ x86_efi_getdev(void **vdev, const char *devspec, const char **path)
* use the current device instead.
*/
if (devspec == NULL || *devspec == '/' || !strchr(devspec, ':')) {
rv = x86_efi_parsedev(dev, getenv("currdev"), NULL);
rv = efi_parsedev(dev, getenv("currdev"), NULL);
if (rv == 0 && path != NULL)
*path = devspec;
return (rv);
}
/* Parse the device name off the beginning of the devspec. */
return (x86_efi_parsedev(dev, devspec, path));
return (efi_parsedev(dev, devspec, path));
}
/*
@ -78,7 +78,7 @@ x86_efi_getdev(void **vdev, const char *devspec, const char **path)
* fs<unit>:
*/
static int
x86_efi_parsedev(struct devdesc **dev, const char *devspec, const char **path)
efi_parsedev(struct devdesc **dev, const char *devspec, const char **path)
{
struct devdesc *idev;
struct devsw *dv;
@ -132,7 +132,7 @@ x86_efi_parsedev(struct devdesc **dev, const char *devspec, const char **path)
}
char *
x86_efi_fmtdev(void *vdev)
efi_fmtdev(void *vdev)
{
struct devdesc *dev = (struct devdesc *)vdev;
static char buf[32]; /* XXX device length constant? */
@ -154,12 +154,12 @@ x86_efi_fmtdev(void *vdev)
* Set currdev to suit the value being supplied in (value)
*/
int
x86_efi_setcurrdev(struct env_var *ev, int flags, const void *value)
efi_setcurrdev(struct env_var *ev, int flags, const void *value)
{
struct devdesc *ncurr;
int rv;
rv = x86_efi_parsedev(&ncurr, value, NULL);
rv = efi_parsedev(&ncurr, value, NULL);
if (rv != 0)
return(rv);

View File

@ -28,22 +28,24 @@
* $FreeBSD$
*/
#ifndef _X86_EFI_COPY_H_
#define _X86_EFI_COPY_H_
#ifndef _LOADER_EFI_COPY_H_
#define _LOADER_EFI_COPY_H_
int x86_efi_autoload(void);
int efi_autoload(void);
int x86_efi_getdev(void **vdev, const char *devspec, const char **path);
char *x86_efi_fmtdev(void *vdev);
int x86_efi_setcurrdev(struct env_var *ev, int flags, const void *value);
int efi_getdev(void **vdev, const char *devspec, const char **path);
char *efi_fmtdev(void *vdev);
int efi_setcurrdev(struct env_var *ev, int flags, const void *value);
int x86_efi_copy_init(void);
void x86_efi_copy_finish(void);
int efi_copy_init(void);
ssize_t x86_efi_copyin(const void *src, vm_offset_t dest, const size_t len);
ssize_t x86_efi_copyout(const vm_offset_t src, void *dest, const size_t len);
ssize_t x86_efi_readin(const int fd, vm_offset_t dest, const size_t len);
ssize_t efi_copyin(const void *src, vm_offset_t dest, const size_t len);
ssize_t efi_copyout(const vm_offset_t src, void *dest, const size_t len);
ssize_t efi_readin(const int fd, vm_offset_t dest, const size_t len);
void * efi_translate(vm_offset_t ptr);
extern UINTN x86_efi_mapkey;
extern UINTN efi_mapkey;
#endif /* _X86_EFI_COPY_H_ */
void efi_copy_finish(void);
#endif /* _LOADER_EFI_COPY_H_ */

View File

@ -36,7 +36,7 @@ __FBSDID("$FreeBSD$");
#include <efilib.h>
#include <bootstrap.h>
#include "x86_efi.h"
#include "loader_efi.h"
extern char bootprog_name[];
extern char bootprog_rev[];
@ -73,7 +73,7 @@ main(int argc, CHAR16 *argv[])
*/
cons_probe();
if (x86_efi_copy_init()) {
if (efi_copy_init()) {
printf("failed to allocate staging area\n");
return (EFI_BUFFER_TOO_SMALL);
}
@ -115,18 +115,18 @@ main(int argc, CHAR16 *argv[])
*/
BS->SetWatchdogTimer(0, 0, 0, NULL);
env_setenv("currdev", EV_VOLATILE, x86_efi_fmtdev(&currdev),
x86_efi_setcurrdev, env_nounset);
env_setenv("loaddev", EV_VOLATILE, x86_efi_fmtdev(&currdev), env_noset,
env_setenv("currdev", EV_VOLATILE, efi_fmtdev(&currdev),
efi_setcurrdev, env_nounset);
env_setenv("loaddev", EV_VOLATILE, efi_fmtdev(&currdev), env_noset,
env_nounset);
setenv("LINES", "24", 1); /* optional */
archsw.arch_autoload = x86_efi_autoload;
archsw.arch_getdev = x86_efi_getdev;
archsw.arch_copyin = x86_efi_copyin;
archsw.arch_copyout = x86_efi_copyout;
archsw.arch_readin = x86_efi_readin;
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(NULL); /* doesn't return */