Skip to content

Commit

Permalink
sysutils/grub2-pcbsd: fix build with gcc10
Browse files Browse the repository at this point in the history
Revive grub2-pcbsd and grub2-efi ports.
Thanks to lwhsu for valuable input.
Approved by:	lwhsu
  • Loading branch information
Kevin Lo authored and Kevin Lo committed Jul 6, 2021
1 parent c0e6f62 commit 310466c
Show file tree
Hide file tree
Showing 40 changed files with 3,665 additions and 2 deletions.
2 changes: 0 additions & 2 deletions MOVED
Expand Up @@ -12656,8 +12656,6 @@ net/linuxigd||2019-05-09|Has expired: Abandonware; use net/miniupnpd instead
net/openafs||2019-05-09|Has expired: Broken for more than 6 months
security/quantis||2019-05-09|Has expired: Broken for more than 6 months
sysutils/boxbackup||2019-05-09|Has expired: Broken for more than 6 months
sysutils/grub2-efi||2019-05-09|Has expired: Broken for more than 6 months
sysutils/grub2-pcbsd||2019-05-09|Has expired: Broken for more than 6 months
sysutils/mdcp||2019-05-09|Has expired: Broken for more than 6 months
sysutils/sbsigntool||2019-05-09|Has expired: Broken for more than 6 months
www/py-cherrypy-old||2019-05-09|Has expired: Lates version is in tree and no dependent ports
Expand Down
2 changes: 2 additions & 0 deletions sysutils/Makefile
Expand Up @@ -472,6 +472,8 @@
SUBDIR += graveman
SUBDIR += graylog
SUBDIR += grub2-bhyve
SUBDIR += grub2-efi
SUBDIR += grub2-pcbsd
SUBDIR += gsh
SUBDIR += gsmartcontrol
SUBDIR += gstopd
Expand Down
55 changes: 55 additions & 0 deletions sysutils/grub2-efi/Makefile
@@ -0,0 +1,55 @@
# Created by: kmoore@FreeBSD.org

PORTNAME= grub2-efi
PORTVERSION= 2.02
PORTREVISION= 20
CATEGORIES= sysutils
MASTER_SITES= LOCAL/kevlo
DISTNAME= grub-${PORTVERSION}_7

MAINTAINER= kevlo@FreeBSD.org
COMMENT= Multiboot EFI boot loader

LICENSE= GPLv3

RUN_DEPENDS= ${LOCALBASE}/bin/mformat:emulators/mtools \
${LOCALBASE}/bin/grub-mkrescue:sysutils/grub2-pcbsd
BUILD_DEPENDS= ${LOCALBASE}/bin/flex:textproc/flex \
${LOCALBASE}/bin/bash:shells/bash \
help2man:misc/help2man

ONLY_FOR_ARCHS= amd64
USES= autoreconf:build bison cpe gettext gmake python tar:xz

WRKSRC= ${WRKDIR}/grub-${PORTVERSION}
SSP_UNSAFE= yes
USE_GCC= yes
GNU_CONFIGURE= yes
MAKE_JOBS_UNSAFE= yes

CPE_PRODUCT= grub
CPE_VENDOR= gnu

CONFIGURE_ARGS= --with-platform=efi --disable-werror --localedir=${PREFIX}/share/locale
CONFIGURE_ENV= CPP="${CC} -E" \
LEX=${LOCALBASE}/bin/flex

.include <bsd.port.pre.mk>

post-patch:
@${LN} -s ${LOCALBASE}/share/fonts/dejavu/DejaVuSans.ttf ${WRKSRC}
@${TOUCH} -t 200001010000 ${WRKSRC}/Makefile.util.def

pre-configure:
@${REINPLACE_CMD} -e 's|python|${PYTHON_CMD}|g' ${WRKSRC}/autogen.sh
cd ${WRKSRC} && ./autogen.sh

post-configure:
@${LN} -sfh /usr/include/machine /usr/include/sys /usr/include/x86 ${WRKSRC}/grub-core

do-install:
@cd ${WRKSRC}/grub-core && ${GMAKE} install DESTDIR=${STAGEDIR}

RUN_DEPENDS:= ${RUN_DEPENDS:Ngcc*}

.include <bsd.port.post.mk>
3 changes: 3 additions & 0 deletions sysutils/grub2-efi/distinfo
@@ -0,0 +1,3 @@
TIMESTAMP = 1625569310
SHA256 (grub-2.02_7.tar.xz) = 044588d9754142f2982478cb4e7289ab1521fd4412b2a0804ce647c3ff73feff
SIZE (grub-2.02_7.tar.xz) = 5019120
12 changes: 12 additions & 0 deletions sysutils/grub2-efi/files/patch-grub-core_disk_geli.c
@@ -0,0 +1,12 @@
--- grub-core/disk/geli.c.orig 2015-01-30 16:34:55 UTC
+++ grub-core/disk/geli.c
@@ -445,6 +445,9 @@ recover_key (grub_disk_t source, grub_cr
if (!grub_password_get (passphrase, MAX_PASSPHRASE))
return grub_error (GRUB_ERR_BAD_ARGUMENT, "Passphrase not supplied");

+ /* Set the GELI passphrase to GRUB env, for passing to FreeBSD kernel */
+ grub_env_set ("gelipassphrase", passphrase);
+
/* Calculate the PBKDF2 of the user supplied passphrase. */
if (grub_le_to_cpu32 (header.niter) != 0)
{
11 changes: 11 additions & 0 deletions sysutils/grub2-efi/files/patch-grub-core_lib_libgcrypt_src_types.h
@@ -0,0 +1,11 @@
--- grub-core/lib/libgcrypt/src/types.h.orig 2014-03-03 16:00:26 UTC
+++ grub-core/lib/libgcrypt/src/types.h
@@ -113,6 +113,8 @@
#endif
#endif

+typedef uint64_t u64;
+
typedef union {
int a;
short b;
185 changes: 185 additions & 0 deletions sysutils/grub2-efi/files/patch-grub-core_loader_i386_bsd.c
@@ -0,0 +1,185 @@
--- grub-core/loader/i386/bsd.c.orig 2015-01-30 16:34:55 UTC
+++ grub-core/loader/i386/bsd.c
@@ -42,12 +42,14 @@
GRUB_MOD_LICENSE ("GPLv3+");

#include <grub/video.h>
+#include <grub/acpi.h>
#ifdef GRUB_MACHINE_PCBIOS
#include <grub/machine/biosnum.h>
#endif
#ifdef GRUB_MACHINE_EFI
#include <grub/efi/efi.h>
#define NETBSD_DEFAULT_VIDEO_MODE "800x600"
+#define FREEBSD_DEFAULT_VIDEO_MODE "auto"
#else
#define NETBSD_DEFAULT_VIDEO_MODE "text"
#include <grub/i386/pc/vbe.h>
@@ -585,6 +587,72 @@ freebsd_get_zfs (void)
grub_free (uuid);
}

+#ifdef GRUB_MACHINE_EFI
+
+static grub_err_t
+grub_freebsd_setup_video (void)
+{
+ struct grub_video_mode_info mode_info;
+ void *framebuffer;
+ const char *modevar;
+ struct grub_freebsd_btinfo_framebuf efifb;
+ grub_err_t err;
+ grub_video_driver_id_t driv_id;
+
+ modevar = grub_env_get ("gfxpayload");
+
+ /* Now all graphical modes are acceptable.
+ May change in future if we have modes without framebuffer. */
+ if (modevar && *modevar != 0)
+ {
+ char *tmp;
+ tmp = grub_xasprintf ("%s;" FREEBSD_DEFAULT_VIDEO_MODE, modevar);
+ if (! tmp)
+ return grub_errno;
+ err = grub_video_set_mode (tmp, 0, 0);
+ grub_free (tmp);
+ }
+ else
+ err = grub_video_set_mode (FREEBSD_DEFAULT_VIDEO_MODE, 0, 0);
+
+ if (err)
+ return err;
+
+ driv_id = grub_video_get_driver_id ();
+ if (driv_id == GRUB_VIDEO_DRIVER_NONE)
+ return GRUB_ERR_NONE;
+
+ err = grub_video_get_info_and_fini (&mode_info, &framebuffer);
+
+ if (err)
+ return err;
+
+ efifb.fb_width = mode_info.width;
+ efifb.fb_height = mode_info.height;
+ efifb.fb_stride = mode_info.pitch / mode_info.bytes_per_pixel;
+
+ efifb.fb_addr = (grub_addr_t) framebuffer;
+ efifb.fb_size = ALIGN_UP (mode_info.pitch * efifb.fb_height, 65536);
+
+ if ( mode_info.blue_field_pos == 16 ) {
+ efifb.fb_mask_red = 0x000000ff;
+ efifb.fb_mask_green = 0x0000ff00;
+ efifb.fb_mask_blue = 0x00ff0000;
+ }
+
+ if ( mode_info.blue_field_pos == 0 ) {
+ efifb.fb_mask_red = 0x00ff0000;
+ efifb.fb_mask_green = 0x0000ff00;
+ efifb.fb_mask_blue = 0x000000ff;
+ }
+
+ efifb.fb_mask_reserved = 0xff000000;
+
+ err = grub_bsd_add_meta ( FREEBSD_MODINFO_METADATA | FREEBSD_BTINFO_FRAMEBUF, &efifb, sizeof (efifb));
+ return err;
+}
+#endif
+
static grub_err_t
grub_freebsd_boot (void)
{
@@ -603,6 +671,55 @@ grub_freebsd_boot (void)

bi.boot_device = freebsd_biosdev;

+#ifdef GRUB_MACHINE_EFI
+ /* When booting in EFI mode, we need to export some additional kernel ACPI hints */
+ struct grub_acpi_rsdp_v10 *v1;
+ struct grub_acpi_rsdp_v20 *v2;
+ v1 = grub_acpi_get_rsdpv1 ();
+ v2 = grub_acpi_get_rsdpv2 ();
+ if (v2 && v2->length > 40)
+ v2 = 0;
+
+ int revision;
+ char acpiBuf[24];
+
+ if (v1)
+ {
+ revision = v1->revision;
+ if ( revision == 0 )
+ revision = 1;
+ grub_snprintf (acpiBuf, sizeof (acpiBuf), "%d", revision);
+ grub_env_set("kFreeBSD.hint.acpi.0.revision", acpiBuf);
+
+ grub_snprintf (acpiBuf, sizeof (acpiBuf), "%s", v1->oemid);
+ grub_env_set("kFreeBSD.hint.acpi.0.oem", acpiBuf);
+
+ grub_snprintf (acpiBuf, sizeof (acpiBuf), "0x%016x", v1->rsdt_addr);
+ grub_env_set("kFreeBSD.hint.acpi.0.rsdt", acpiBuf);
+
+ grub_snprintf (acpiBuf, sizeof (acpiBuf), "0x%016llx", (unsigned long long)v1);
+ grub_env_set("kFreeBSD.hint.acpi.0.rsdp", acpiBuf);
+ }
+
+ if (v2)
+ {
+ revision = v2->rsdpv1.revision;
+ if ( revision == 0 )
+ revision = 1;
+
+ grub_snprintf (acpiBuf, sizeof (acpiBuf), "%d", revision);
+ grub_env_set("kFreeBSD.hint.acpi.0.revision", acpiBuf);
+
+ grub_snprintf (acpiBuf, sizeof (acpiBuf), "0x%016llx", (unsigned long long)v2->xsdt_addr);
+ grub_env_set("kFreeBSD.hint.acpi.0.xsdt", acpiBuf);
+
+ grub_snprintf (acpiBuf, sizeof (acpiBuf), "%d", v2->length);
+ grub_env_set("kFreeBSD.hint.acpi.0.xsdt_length", acpiBuf);
+ }
+
+
+#endif
+
p_size = 0;
FOR_SORTED_ENV (var)
if ((grub_memcmp (var->name, "kFreeBSD.", sizeof("kFreeBSD.") - 1) == 0) && (var->name[sizeof("kFreeBSD.") - 1]))
@@ -688,6 +805,10 @@ grub_freebsd_boot (void)
*(grub_uint32_t *) p_tag = bootflags;
break;

+ case FREEBSD_MODINFO_METADATA | FREEBSD_BTINFO_FRAMEBUF:
+ grub_memcpy (p_tag, tag->data, tag->len);
+ break;
+
case FREEBSD_MODINFO_METADATA | FREEBSD_MODINFOMD_ENVP:
if (is_64bit)
*(grub_uint64_t *) p_tag = bi.environment;
@@ -717,7 +838,10 @@ grub_freebsd_boot (void)

bi.kern_end = kern_end;

+#ifndef GRUB_MACHINE_EFI
+ /* Don't set text mode on EFI boot */
grub_video_set_mode ("text", 0, 0);
+#endif

if (is_64bit)
{
@@ -1561,6 +1685,16 @@ grub_cmd_freebsd (grub_extcmd_context_t
FREEBSD_MODINFOMD_KERNEND, &data, len);
if (err)
return err;
+
+#ifdef GRUB_MACHINE_EFI
+ err = grub_freebsd_setup_video ();
+ if (err)
+ {
+ grub_print_error ();
+ grub_puts_ (N_("Booting in EFI blind mode"));
+ grub_errno = GRUB_ERR_NONE;
+ }
+#endif
}
grub_bsd_get_device (&freebsd_biosdev, &unit, &slice, &part);
freebsd_zfsguid = 0;
20 changes: 20 additions & 0 deletions sysutils/grub2-efi/files/patch-grub-core_partmap_gpt.c
@@ -0,0 +1,20 @@
--- grub-core/partmap/gpt.c.orig 2014-10-20 16:16:07 UTC
+++ grub-core/partmap/gpt.c
@@ -37,6 +37,7 @@ static const grub_gpt_part_type_t grub_g

#ifdef GRUB_UTIL
static const grub_gpt_part_type_t grub_gpt_partition_type_bios_boot = GRUB_GPT_PARTITION_TYPE_BIOS_BOOT;
+static const grub_gpt_part_type_t grub_gpt_partition_type_freebsd_boot = GRUB_GPT_PARTITION_TYPE_FREEBSD_BOOT;
#endif

/* 512 << 7 = 65536 byte sectors. */
@@ -155,7 +156,8 @@ find_usable_region (grub_disk_t disk __a
disk->partition = p2;

/* If there's an embed region, it is in a dedicated partition. */
- if (! grub_memcmp (&gptdata.type, &grub_gpt_partition_type_bios_boot, 16))
+ if (! grub_memcmp (&gptdata.type, &grub_gpt_partition_type_bios_boot, 16) ||
+ ! grub_memcmp (&gptdata.type, &grub_gpt_partition_type_freebsd_boot, 16))
{
ctx->start = p->start;
ctx->len = p->len;
17 changes: 17 additions & 0 deletions sysutils/grub2-efi/files/patch-include_grub_gpt__partition.h
@@ -0,0 +1,17 @@
--- include/grub/gpt_partition.h.orig 2014-03-03 16:00:26 UTC
+++ include/grub/gpt_partition.h
@@ -43,6 +43,14 @@ typedef struct grub_gpt_part_type grub_g
{ 0x74, 0x4e, 0x65, 0x65, 0x64, 0x45, 0x46, 0x49 } \
}

+#define GRUB_GPT_PARTITION_TYPE_FREEBSD_BOOT \
+ { grub_cpu_to_le32_compile_time (0x83bd6b9d), \
+ grub_cpu_to_le16_compile_time (0x7f41), \
+ grub_cpu_to_le16_compile_time (0x11dc), \
+ { 0xbe, 0x0b, 0x00, 0x15, 0x60, 0xb8, 0x4f, 0x0f } \
+ }
+
+
#define GRUB_GPT_PARTITION_TYPE_LDM \
{ grub_cpu_to_le32_compile_time (0x5808C8AAU),\
grub_cpu_to_le16_compile_time (0x7E8F), \
10 changes: 10 additions & 0 deletions sysutils/grub2-efi/files/patch-include_grub_i386_bsd.h
@@ -0,0 +1,10 @@
--- include/grub/i386/bsd.h.orig 2014-12-30 21:10:24 UTC
+++ include/grub/i386/bsd.h
@@ -26,6 +26,7 @@
#include <grub/i386/netbsd_reboot.h>
#include <grub/i386/openbsd_reboot.h>
#include <grub/i386/freebsd_linker.h>
+#include <grub/i386/freebsd_bootinfo.h>
#include <grub/i386/netbsd_bootinfo.h>
#include <grub/i386/openbsd_bootarg.h>

@@ -0,0 +1,36 @@
--- include/grub/i386/freebsd_bootinfo.h.orig 2015-06-07 21:44:01 UTC
+++ include/grub/i386/freebsd_bootinfo.h
@@ -0,0 +1,33 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2008,2009 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/types.h>
+
+#define FREEBSD_BTINFO_FRAMEBUF 0x1005
+
+struct grub_freebsd_btinfo_framebuf {
+ grub_uint64_t fb_addr;
+ grub_uint64_t fb_size;
+ grub_int32_t fb_height;
+ grub_int32_t fb_width;
+ grub_int32_t fb_stride;
+ grub_uint32_t fb_mask_red;
+ grub_uint32_t fb_mask_green;
+ grub_uint32_t fb_mask_blue;
+ grub_uint32_t fb_mask_reserved;
+};
5 changes: 5 additions & 0 deletions sysutils/grub2-efi/files/patch-po_LINGUAS
@@ -0,0 +1,5 @@
--- po/LINGUAS.orig 2015-01-30 16:30:32 UTC
+++ po/LINGUAS
@@ -1 +1 @@
-ast ca da de de@hebrew de_CH en@arabic en@cyrillic en@greek en@hebrew en@piglatin en@quot eo es fi fr gl hu id it ja lt nb nl pa pl pt_BR ru sl sv tr uk vi zh_CN zh_TW
+ast ca da de eo es fi fr gl hu id it ja lt nb nl pa pl pt_BR ru sl sv tr uk vi zh_CN zh_TW
8 changes: 8 additions & 0 deletions sysutils/grub2-efi/pkg-descr
@@ -0,0 +1,8 @@
GNU GRUB is a multiboot boot loader. It was derived from GRUB, the GRand
Unified Bootloader, which was originally designed and implemented by Erich
Stefan Boleyn.

This port builds the GRUB x86_64-efi boot modules, allowing grub-install
or grub-mkrescue to install with EFI support.

WWW: http://www.gnu.org/software/grub/

0 comments on commit 310466c

Please sign in to comment.