Index: head/sys/boot/efi/Makefile =================================================================== --- head/sys/boot/efi/Makefile +++ head/sys/boot/efi/Makefile @@ -1,7 +1,15 @@ # $FreeBSD$ +.include + SUBDIR= libefi +.if ${TARGET_CPUARCH} == "aarch64" || ${TARGET_CPUARCH} == "arm" +.if ${MK_FDT} != "no" +SUBDIR+= fdt +.endif +.endif + .if ${MACHINE_CPUARCH} == "amd64" SUBDIR+= loader boot1 .endif Index: head/sys/boot/efi/loader/Makefile =================================================================== --- head/sys/boot/efi/loader/Makefile +++ head/sys/boot/efi/loader/Makefile @@ -42,6 +42,15 @@ LIBFICL= ${.OBJDIR}/../../ficl/libficl.a .endif +LOADER_FDT_SUPPORT?= no +.if ${MK_FDT} != "no" && ${LOADER_FDT_SUPPORT} != "no" +CFLAGS+= -I${.CURDIR}/../../fdt +CFLAGS+= -I${.OBJDIR}/../../fdt +CFLAGS+= -DLOADER_FDT_SUPPORT +LIBEFI_FDT= ${.OBJDIR}/../../efi/fdt/libefi_fdt.a +LIBFDT= ${.OBJDIR}/../../fdt/libfdt.a +.endif + # Include bcache code. HAVE_BCACHE= yes @@ -88,8 +97,9 @@ LIBEFI= ${.OBJDIR}/../libefi/libefi.a -DPADD= ${LIBFICL} ${LIBEFI} ${LIBSTAND} ${LDSCRIPT} -LDADD= ${LIBFICL} ${LIBEFI} ${LIBSTAND} +DPADD= ${LIBFICL} ${LIBEFI} ${LIBFDT} ${LIBEFI_FDT} ${LIBSTAND} \ + ${LDSCRIPT} +LDADD= ${LIBFICL} ${LIBEFI} ${LIBFDT} ${LIBEFI_FDT} ${LIBSTAND} .endif # ${COMPILER_TYPE} != "gcc" Index: head/sys/boot/efi/loader/bootinfo.c =================================================================== --- head/sys/boot/efi/loader/bootinfo.c +++ head/sys/boot/efi/loader/bootinfo.c @@ -51,6 +51,10 @@ #include "framebuffer.h" #endif +#if defined(LOADER_FDT_SUPPORT) +#include +#endif + UINTN efi_mapkey; static const char howto_switches[] = "aCdrgDmphsv"; @@ -324,6 +328,10 @@ vm_offset_t size; char *rootdevname; int howto; +#if defined(LOADER_FDT_SUPPORT) + vm_offset_t dtbp; + int dtb_size; +#endif howto = bi_getboothowto(args); @@ -358,6 +366,16 @@ /* Pad to a page boundary. */ addr = roundup(addr, PAGE_SIZE); +#if defined(LOADER_FDT_SUPPORT) + /* Handle device tree blob */ + dtbp = addr; + dtb_size = fdt_copy(addr); + + /* Pad to a page boundary */ + if (dtb_size) + addr += roundup(dtb_size, PAGE_SIZE); +#endif + kfp = file_findfile(NULL, "elf kernel"); if (kfp == NULL) kfp = file_findfile(NULL, "elf64 kernel"); @@ -366,6 +384,13 @@ kernend = 0; /* fill it in later */ file_addmetadata(kfp, MODINFOMD_HOWTO, sizeof howto, &howto); file_addmetadata(kfp, MODINFOMD_ENVP, sizeof envp, &envp); +#if defined(LOADER_FDT_SUPPORT) + if (dtb_size) + file_addmetadata(kfp, MODINFOMD_DTBP, sizeof dtbp, &dtbp); + else + pager_output("WARNING! Trying to fire up the kernel, but no " + "device tree blob found!\n"); +#endif file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof kernend, &kernend); bi_load_efi_data(kfp); Index: head/sys/boot/efi/loader/main.c =================================================================== --- head/sys/boot/efi/loader/main.c +++ head/sys/boot/efi/loader/main.c @@ -387,3 +387,22 @@ return (CMD_OK); } + +#ifdef LOADER_FDT_SUPPORT +extern int command_fdt_internal(int argc, char *argv[]); + +/* + * Since proper fdt command handling function is defined in fdt_loader_cmd.c, + * and declaring it as extern is in contradiction with COMMAND_SET() macro + * (which uses static pointer), we're defining wrapper function, which + * calls the proper fdt handling routine. + */ +static int +command_fdt(int argc, char *argv[]) +{ + + return (command_fdt_internal(argc, argv)); +} + +COMMAND_SET(fdt, "fdt", "flattened device tree handling", command_fdt); +#endif