UEFI detection problem when booting FreeBSD from Grub

From: Luiz Amaral <email_at_luiz.eng.br>
Date: Fri, 11 Mar 2022 07:53:27 UTC
Hello,

I am currently booting FreeBSD via Grub in UEFI mode, but running into
issues with the boot method detection in FreeBSD.

I am using mfsBSD for it, together with the following Grub configuration:
kfreebsd /mfsbsd/boot/kernel/kernel.gz -Dh
kfreebsd_module_elf /mfsbsd/boot/kernel/efirt.ko
kfreebsd_loadenv /mfsbsd/boot/device.hints
kfreebsd_module /mfsbsd/mfsroot.gz type=mfs_root

I am able to boot mfsBSD just fine, and from within mfsBSD I am able to
provision FreeBSD on my local disk.
The only issue now is that I need to create a new boot entry that points
to the recently installed system, which I tried to do using efibootmgr.
Whenever I tried to invoke efibootmgr, I was greeted with:
root@hwlb-awtest-02:~ # efibootmgr
efibootmgr: efi variables not supported on this system. root? kldload efirt?

I am explicitly loading efirt with Grub and on dmesg I can see an entry
for it, so I assume it's being loaded fine.
Mar 10 16:27:55 mfsbsd kernel: module efirt already present!

While checking other things, I realized that FreeBSD/mfsBSD was
detecting the boot method as BIOS instead of UEFI:
root@hwlb-awtest-02:~ # sysctl machdep.bootmethod
machdep.bootmethod: BIOS

What I am struggling now is to understand why this is happening. Does
loader.efi perform special operations before loading the kernel that
allows it to detect that it booted in UEFI mode? Did I miss something on
my Grub entry?

Thank you,
Luiz