From 3d06fbd765808afd5213fee3259e56f65ae5e4c0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Imre=20Vad=C3=A1sz?= Date: Sat, 16 Apr 2016 12:48:58 +0200 Subject: [PATCH] sys/boot/efi/boot1: Port efi boot1 loader from FreeBSD to DragonFly. * Add PATH_* #define-s to boot1.c instead of using a paths.h header. * Remove ZFS related code. * Some fixes for compile errors. --- sys/boot/efi/boot1/boot1.c | 44 ++++++++++++++++++++++---------- sys/boot/efi/boot1/boot_module.h | 12 +++------ sys/boot/efi/boot1/ufs_module.c | 17 +++++++++--- sys/boot/efi/loader/self_reloc.c | 2 +- 4 files changed, 47 insertions(+), 28 deletions(-) diff --git a/sys/boot/efi/boot1/boot1.c b/sys/boot/efi/boot1/boot1.c index bbdd280e0d..257556ee13 100644 --- a/sys/boot/efi/boot1/boot1.c +++ b/sys/boot/efi/boot1/boot1.c @@ -17,15 +17,15 @@ * implied warranties, including, without limitation, the implied * warranties of merchantability and fitness for a particular * purpose. + * + * $FreeBSD: head/sys/boot/efi/boot1/boot1.c 296713 2016-03-12 06:50:16Z andrew $ */ -#include -__FBSDID("$FreeBSD: head/sys/boot/efi/boot1/boot1.c 296713 2016-03-12 06:50:16Z andrew $"); - #include #include #include #include +#include #include #include @@ -33,11 +33,13 @@ __FBSDID("$FreeBSD: head/sys/boot/efi/boot1/boot1.c 296713 2016-03-12 06:50:16Z #include "boot_module.h" #include "paths.h" +#define PATH_CONFIG "/boot/config" +#define PATH_DOTCONFIG "/boot.config" +#define PATH_LOADER "/loader.efi" /* /boot is dedicated */ +#define PATH_LOADER_ALT "/boot/loader.efi" /* /boot in root */ + static const boot_module_t *boot_modules[] = { -#ifdef EFI_ZFS_BOOT - &zfs_module, -#endif #ifdef EFI_UFS_BOOT &ufs_module #endif @@ -47,7 +49,6 @@ static const boot_module_t *boot_modules[] = /* The initial number of handles used to query EFI for partitions. */ #define NUM_HANDLES_INIT 24 -void putchar(int c); EFI_STATUS efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE* Xsystab); EFI_SYSTEM_TABLE *systab; @@ -59,6 +60,12 @@ static EFI_GUID DevicePathGUID = DEVICE_PATH_PROTOCOL; static EFI_GUID LoadedImageGUID = LOADED_IMAGE_PROTOCOL; static EFI_GUID ConsoleControlGUID = EFI_CONSOLE_CONTROL_PROTOCOL_GUID; +/* + * XXX DragonFly's libstand doesn't provide a way to override the malloc + * implementation yet. + */ +#if 0 + /* * Provide Malloc / Free backed by EFIs AllocatePool / FreePool which ensures * memory is correctly aligned avoiding EFI_INVALID_PARAMETER returns from @@ -81,6 +88,8 @@ Free(void *buf, const char *file __unused, int line __unused) (void)bs->FreePool(buf); } +#endif + /* * nodes_match returns TRUE if the imgpath isn't NULL and the nodes match, * FALSE otherwise. @@ -329,6 +338,7 @@ load_loader(const boot_module_t **modp, dev_info_t **devinfop, void **bufp, UINTN i; dev_info_t *dev; const boot_module_t *mod; + EFI_STATUS status; for (i = 0; i < NUM_BOOT_MODULES; i++) { if (boot_modules[i] == NULL) @@ -338,8 +348,12 @@ load_loader(const boot_module_t **modp, dev_info_t **devinfop, void **bufp, if (dev->preferred != preferred) continue; - if (mod->load(PATH_LOADER_EFI, dev, bufp, bufsize) == - EFI_SUCCESS) { + status = mod->load(PATH_LOADER, dev, bufp, bufsize); + if (status == EFI_NOT_FOUND) { + status = mod->load(PATH_LOADER_ALT, dev, bufp, + bufsize); + } + if (status == EFI_SUCCESS) { *devinfop = dev; *modp = mod; return (EFI_SUCCESS); @@ -355,7 +369,7 @@ load_loader(const boot_module_t **modp, dev_info_t **devinfop, void **bufp, * it simply boots, otherwise it returns the status of last EFI call. */ static EFI_STATUS -try_boot() +try_boot(void) { size_t bufsize, loadersize, cmdsize; void *buf, *loaderbuf; @@ -371,7 +385,8 @@ try_boot() status = load_loader(&mod, &dev, &loaderbuf, &loadersize, FALSE); if (status != EFI_SUCCESS) { - printf("Failed to load '%s'\n", PATH_LOADER_EFI); + printf("Failed to load '%s' or '%s'\n", + PATH_LOADER, PATH_LOADER_ALT); return (status); } } @@ -534,8 +549,9 @@ probe_handle_status(EFI_HANDLE h, EFI_DEVICE_PATH *imgpath) EFI_STATUS status; BOOLEAN preferred; + preferred = FALSE; status = probe_handle(h, imgpath, &preferred); - + DPRINTF("probe: "); switch (status) { case EFI_UNSUPPORTED: @@ -601,8 +617,8 @@ efi_main(EFI_HANDLE Ximage, EFI_SYSTEM_TABLE *Xsystab) conout->EnableCursor(conout, TRUE); conout->ClearScreen(conout); - printf("\n>> FreeBSD EFI boot block\n"); - printf(" Loader path: %s\n\n", PATH_LOADER_EFI); + printf("\n>> DragonFly EFI boot block\n"); + printf(" Loader path: %s:%s\n\n", PATH_LOADER, PATH_LOADER_ALT); printf(" Initializing modules:"); for (i = 0; i < NUM_BOOT_MODULES; i++) { if (boot_modules[i] == NULL) diff --git a/sys/boot/efi/boot1/boot_module.h b/sys/boot/efi/boot1/boot_module.h index 3945875d46..9f9cebd424 100644 --- a/sys/boot/efi/boot1/boot_module.h +++ b/sys/boot/efi/boot1/boot_module.h @@ -64,7 +64,7 @@ typedef struct boot_module_t const char *name; /* init is the optional initialiser for the module. */ - void (*init)(); + void (*init)(void); /* * probe checks to see if the module can handle dev. @@ -89,25 +89,19 @@ typedef struct boot_module_t void **buf, size_t *bufsize); /* status outputs information about the probed devices. */ - void (*status)(); + void (*status)(void); /* valid devices as found by probe. */ - dev_info_t *(*devices)(); + dev_info_t *(*devices)(void); } boot_module_t; /* Standard boot modules. */ #ifdef EFI_UFS_BOOT extern const boot_module_t ufs_module; #endif -#ifdef EFI_ZFS_BOOT -extern const boot_module_t zfs_module; -#endif /* Functions available to modules. */ extern void add_device(dev_info_t **devinfop, dev_info_t *devinfo); -extern void panic(const char *fmt, ...) __dead2; -extern int printf(const char *fmt, ...); -extern int vsnprintf(char *str, size_t sz, const char *fmt, va_list ap); extern EFI_SYSTEM_TABLE *systab; extern EFI_BOOT_SERVICES *bs; diff --git a/sys/boot/efi/boot1/ufs_module.c b/sys/boot/efi/boot1/ufs_module.c index 71559a782f..0d7097b03b 100644 --- a/sys/boot/efi/boot1/ufs_module.c +++ b/sys/boot/efi/boot1/ufs_module.c @@ -66,16 +66,25 @@ dskread(void *buf, u_int64_t lba, int nblk) return (0); } +/* For ufsread.c */ +uint64_t fs_off; +int ls; + +static struct ufs_dmadat __dmadat; +static struct ufs_dmadat *boot2_dmadat; + #include "ufsread.c" -static struct dmadat __dmadat; +#define fsread boot2_ufs_read +#define fsread_size boot2_ufs_read_size +#define lookup boot2_ufs_lookup static int init_dev(dev_info_t* dev) { devinfo = dev; - dmadat = &__dmadat; + boot2_dmadat = &__dmadat; return fsread(0, NULL, 0); } @@ -142,7 +151,7 @@ load(const char *filepath, dev_info_t *dev, void **bufp, size_t *bufsize) } static void -status() +status(void) { int i; dev_info_t *dev; @@ -164,7 +173,7 @@ status() } static dev_info_t * -_devices() +_devices(void) { return (devices); diff --git a/sys/boot/efi/loader/self_reloc.c b/sys/boot/efi/loader/self_reloc.c index 5a32029549..e4ecfc9f21 100644 --- a/sys/boot/efi/loader/self_reloc.c +++ b/sys/boot/efi/loader/self_reloc.c @@ -61,7 +61,7 @@ self_reloc(Elf_Addr baseaddr, ElfW_Dyn *dynamic) { Elf_Word relsz, relent; Elf_Addr *newaddr; - ElfW_Rel *rel; + ElfW_Rel *rel = 0; ElfW_Dyn *dynp; /* -- 2.41.0