Index: sys/stand/efiboot/exec.c =================================================================== RCS file: /cvsroot/src/sys/stand/efiboot/exec.c,v retrieving revision 1.19 diff -u -p -r1.19 exec.c --- sys/stand/efiboot/exec.c 10 Oct 2020 19:17:39 -0000 1.19 +++ sys/stand/efiboot/exec.c 12 Dec 2020 09:36:10 -0000 @@ -41,8 +41,17 @@ extern char twiddle_toggle; u_long load_offset = 0; +#ifndef PAGE_SIZE +#define PAGE_SIZE (4 * 1024) +#endif #define FDT_SPACE (4 * 1024 * 1024) -#define FDT_ALIGN ((2 * 1024 * 1024) - 1) +#define FDT_ALIGN (2 * 1024 * 1024) + +/* + * Wild guess at how big kernend_extra might get, or how much memory + * valloc_pages will use. + */ +#define KERNEL_EARLYALLOCATIONS (32 * 4 * 1024) static EFI_PHYSICAL_ADDRESS initrd_addr, dtb_addr, rndseed_addr, efirng_addr; static u_long initrd_size = 0, dtb_size = 0, rndseed_size = 0, efirng_size = 0; @@ -242,7 +251,7 @@ int exec_netbsd(const char *fname, const char *args) { EFI_PHYSICAL_ADDRESS addr; - u_long marks[MARK_MAX], alloc_size; + u_long marks[MARK_MAX], alloc_size, fdt_offset; EFI_STATUS status; int fd, ohowto; @@ -260,8 +269,17 @@ exec_netbsd(const char *fname, const cha return EIO; } close(fd); + marks[MARK_END] = (((u_long) marks[MARK_END] + sizeof(int) - 1)) & (-sizeof(int)); - alloc_size = marks[MARK_END] - marks[MARK_START] + FDT_SPACE + EFIBOOT_ALIGN; + + alloc_size = marks[MARK_END] - marks[MARK_START]; // kernel size + alloc_size = (alloc_size + PAGE_SIZE - 1) & -PAGE_SIZE; + alloc_size += KERNEL_EARLYALLOCATIONS; + alloc_size = (alloc_size + FDT_ALIGN - 1) & ~(FDT_ALIGN - 1); + + fdt_offset = alloc_size; + alloc_size += FDT_SPACE; // fdt max space + alloc_size = (alloc_size + EFIBOOT_ALIGN - 1) & ~(EFIBOOT_ALIGN - 1); #ifdef EFIBOOT_ALLOCATE_MAX_ADDRESS addr = EFIBOOT_ALLOCATE_MAX_ADDRESS; @@ -279,7 +297,7 @@ exec_netbsd(const char *fname, const cha } memset(marks, 0, sizeof(marks)); - load_offset = (addr + EFIBOOT_ALIGN) & ~(EFIBOOT_ALIGN - 1); + load_offset = (addr + EFIBOOT_ALIGN - 1) & ~(EFIBOOT_ALIGN - 1); fd = loadfile(fname, marks, LOAD_KERNEL); if (fd < 0) { printf("boot: %s: %s\n", fname, strerror(errno)); @@ -308,7 +326,7 @@ exec_netbsd(const char *fname, const cha load_file(get_rndseed_path(), 0, false, &rndseed_addr, &rndseed_size); - efi_fdt_init((marks[MARK_END] + FDT_ALIGN) & ~FDT_ALIGN, FDT_ALIGN + 1); + efi_fdt_init(marks[MARK_START] + fdt_offset, FDT_SPACE); load_modules(fname); load_fdt_overlays(); efi_fdt_initrd(initrd_addr, initrd_size);