Skip to contentSkip to conversation

Patch to add newer i386 modinfo types

PATCH Eric McCorkle 2 participants 4 messages Apr 4, 2020 – Apr 5, 2020

lore
Share & tools
lore
#0 lore raw

I'm working on trying to get GRUB to properly set up the EFI framebuffer info for the freebsd kernel.

This is a patch to one of the includes that adds updates the modinfo types to match the FreeBSD kernel sources. Hopefully the EFI framebuffer patch will come shortly.

grub/i386/freebsd_linker.h renamed from grub/i386/freebsd_linker.h.orig +9 -0
@@ -65,9 +65,18 @@
 #define FREEBSD_MODINFOMD_HOWTO		0x0007	/* boothowto */
 #define FREEBSD_MODINFOMD_KERNEND	0x0008	/* kernend */
 #define FREEBSD_MODINFOMD_SHDR		0x0009	/* section header table */
+#define FREEBSD_MODINFOMD_CTORS_ADDR    0x000a  /* address of .ctors */
+#define FREEBSD_MODINFOMD_CTORS_SIZE    0x000b  /* size of .ctors */
+#define FREEBSD_MODINFOMD_FW_HANDLE     0x000c  /* firmware dependent handle */
+#define FREEBSD_MODINFOMD_KEYBUF        0x000d  /* crypto key intake buffer */
 #define FREEBSD_MODINFOMD_NOCOPY	0x8000	/* don't copy this metadata to the kernel */
 
 #define FREEBSD_MODINFOMD_SMAP		0x1001
+#define FREEBSD_MODINFOMD_SMAP_XATTR    0x1002
+#define FREEBSD_MODINFOMD_DTBP          0x1003
+#define FREEBSD_MODINFOMD_EFI_MAP       0x1004
+#define FREEBSD_MODINFOMD_EFI_FB        0x1005
+#define FREEBSD_MODINFOMD_EFI_MODULEP   0x1006
 
 #define FREEBSD_MODINFOMD_DEPLIST	(0x4001 | FREEBSD_MODINFOMD_NOCOPY)  /* depends on */
 
#1 lore raw

Here's a first attempt at a patch that adds the code necessary to pass the EFI framebuffer info into the FreeBSD kernel. I have tested this successfully on real hardware.

Quoted 8 lines · Eric McCorkle

I'm working on trying to get GRUB to properly set up the EFI framebuffer info for the freebsd kernel.

This is a patch to one of the includes that adds updates the modinfo types to match the FreeBSD kernel sources. Hopefully the EFI framebuffer patch will come shortly.

Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

loader/i386/bsd.c renamed from loader/i386/bsd.c.orig +72 -0
@@ -76,6 +76,29 @@
 static struct grub_relocator *relocator = NULL;
 static struct grub_openbsd_ramdisk_descriptor openbsd_ramdisk;
 
+#ifdef GRUB_MACHINE_EFI
+struct freebsd_efi_fb
+{
+  grub_uint64_t fb_addr;
+  grub_uint64_t fb_size;
+  grub_uint32_t fb_height;
+  grub_uint32_t fb_width;
+  grub_uint32_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;
+};
+
+struct freebsd_efi_map_header
+{
+  grub_uint64_t memory_size;
+  grub_uint64_t descriptor_size;
+  grub_uint32_t descriptor_version;
+  grub_uint8_t data[];
+};
+#endif
+
 struct bsd_tag
 {
   struct bsd_tag *next;
@@ -1567,7 +1590,56 @@
 				   FREEBSD_MODINFOMD_KERNEND, &data, len);
 	  if (err)
 	    return err;
+
+          /* TODO: add keys to keybuf */
+#ifdef GRUB_MACHINE_EFI
+          /* Add EFI firmware handle */
+          err = grub_bsd_add_meta (FREEBSD_MODINFO_METADATA |
+				   FREEBSD_MODINFOMD_FW_HANDLE,
+                                   &grub_efi_system_table,
+                                   sizeof (grub_efi_system_table));
+
+          if (err)
+            return err;
+
+          /* Add EFI frame buffer info */
+          struct freebsd_efi_fb efifb;
+          struct grub_video_mode_info mode_info;
+          void *framebuffer;
+
+          err = grub_video_get_info_and_fini (&mode_info, &framebuffer);
+
+          if (err)
+            return err;
+
+          efifb.fb_addr = (grub_addr_t) framebuffer;
+          efifb.fb_height = mode_info.height;
+          efifb.fb_width = mode_info.width;
+          efifb.fb_stride = mode_info.pitch / mode_info.bytes_per_pixel;
+          efifb.fb_size = mode_info.height * mode_info.pitch;
+          efifb.fb_mask_red =
+            ((1 << mode_info.red_mask_size) - 1) <<
+            mode_info.red_field_pos;
+          efifb.fb_mask_green =
+            ((1 << mode_info.green_mask_size) - 1) <<
+            mode_info.green_field_pos;
+          efifb.fb_mask_blue =
+            ((1 << mode_info.blue_mask_size) - 1) <<
+            mode_info.blue_field_pos;
+          efifb.fb_mask_reserved =
+            ((1 << mode_info.reserved_mask_size) - 1) <<
+            mode_info.reserved_field_pos;
+          err = grub_bsd_add_meta (FREEBSD_MODINFO_METADATA |
+				   FREEBSD_MODINFOMD_EFI_FB,
+                                   &efifb, sizeof (efifb));
+
+          if (err)
+            return err;
+
+          /* TODO: add EFI map */
+#endif
 	}
+
       grub_bsd_get_device (&freebsd_biosdev, &unit, &slice, &part);
       freebsd_zfsguid = 0;
       if (!is_64bit)
#2 lore raw

Dear Eric,

Am 05.04.20 um 03:54 schrieb Eric McCorkle:

Quoted 3 lines

Here's a first attempt at a patch that adds the code necessary to pass the EFI framebuffer info into the FreeBSD kernel. I have tested this successfully on real hardware.

Nice. Great work. What hardware (also firmware version) did you test with?

Could you please send the changes as git formatted patches. That way they can be easily applied, and there is a commit message. git format-patch and git send-email should do that for you.

Kind regards,

Paul

#3 lore raw

Will do. I want to try and get the TODOs in the code taken care of first, though.

Also, FYI, I just tested the FreeBSD port with clang, and it worked.

I'm boot-testing on a Librem 15 (amd64) with the original AMI BIOS (not coreboot). I'd have to look up the exact version.

Quoted 18 lines · Paul Menzel

Dear Eric,

Am 05.04.20 um 03:54 schrieb Eric McCorkle:

Quoted 3 lines

Here's a first attempt at a patch that adds the code necessary to pass the EFI framebuffer info into the FreeBSD kernel.  I have tested this successfully on real hardware.

Nice. Great work. What hardware (also firmware version) did you test with?

Could you please send the changes as git formatted patches. That way they can be easily applied, and there is a commit message. git format-patch and git send-email should do that for you.

Kind regards,

Paul