This fixed a problem for me when working with Parallels Desktop 18's UEFI.
To give some background:
Old VM consisting of three HDDs, originally using legacy gptzfsboot. Two disks zpool, one disk swap. For reasons, disks can't be modified in size and the bootloader won't fit the original boot partitions anymore. Since Parallels seems to have issues with FreeBSD 12+ legacy boot (or vice versa) I added an EFI partition on the swap disk.
Unfortunately, EFI boot wouldn't detect my root device automatically, but I could boot when setting it explicitly
set currdev=zfs:tank/root: load boot/kernel/kernel load boot/kernel/zfs.ko boot
Therefore I looked for a way to be able to set this variable somewhere else. Based on the sources and some search results, modifying /efi/freebsd/loader.env sounded promising, so I did this configuration:
rootdev=zfs:tank/root:
Unfortunately, this didn't work. After adding some debug code to loader.efi, I learned that the stat call on the file fails (even though the loader seems to look at the correct partition). Also, looking at the partition's content from within the boot loader didn't work (ls said something like / file not found). The EFI partition was formatted using FAT32, not sure if this is related or not (I didn't have time to test other formats yet).
Next, I discovered that I can create boot loader entries in Parallels Desktop's boot menu, so I did:
Add boot option → Select Partition → efi → BOOT → BOOTX64.efi and set the following fields:
Input the description: FreeBSD Input optional data: rootdev=zfs:tank/root:
Again, this failed, even though the boot loader clearly echoed them back:
Command line arguments: rootdev=zfs:tank/root:
Looking at the code revealed that only arguments [1..argc] are parsed, which lead me to this little patch.
I don't know enough about UEFI to understand if this is correct behavior or if this is actually a bug in Parallels Desktop. In case of the latter, this patch is moot.