Non-volatile memory in the UEFI
Posted: Sun Jan 02, 2022 10:43 am
Hello, I want to figure out how to save data to non-volatile memory in the UEFI such that data is still there after I reopen QEMU.
So I used to run my bootx64.efi by producing it and then just putting it to app/efi/boot/bootx64.efi and then I did and that worked very well.
However, I figured I wouldn't be able to save data in a non-volatile way like this and I would need to instead create a real FAT32 file system image with my /efi/boot/bootx64.efi on that image and then I'd be able to save data to that image. Is that correct?
Well, that aside, so far I know of two ways that should allow me to store data in a non-volatile way:
* Using UEFI variables (in the UEFI shell this can be done with `set`)
* Using the Simple File System Protocol and the File Protocol
* I read that there is a way to read a non-FAT32 file system (e.g. ext2) by using the Block I/O Protocol and parsing the file system myself. The non-FAT32 file system would still have to live on top of the FAT32 one though, right?
Are there other ways?
Well now I'm creating a bootable disk like this: https://wiki.osdev.org/UEFI_App_Bare_Bo ... _FAT_image
Then I run it like this:
It starts the UEFI shell. As a test I did `set a b`, rebooted and the variable was still there. But I figured that saving data specific to my image/application in the user's general `/usr/share/OVMF/OVMF_VARS.fd` wasn't good so I think variables are out of the race for non-volatile data storage. Unless there is a way to save the variables somewhere else?
Simply removing the last `-drive` argument from the above command actually starts the bootx64.efi.
Anyway, so as a start I tried obtaining the Simple File System Protocol and that seems to have worked: `EFI_BOOT_SERVICES.LocateProtocol()` returned `EFI_SUCCESS` for that protocol.
For the File Protocol, which is the necessary counterpart, however, `EFI_BOOT_SERVICES.LocateProtocol()` returns `EFI_NOT_FOUND` for that protocol and I can't figure out why.
What could I be doing wrong? Is my `fat.img` in its current state still read-only? Are my QEMU arguments wrong? Can I not store data in the file system in my FAT32 image?
I hope somebody can teach me how to store non-volatile data within the UEFI.
So I used to run my bootx64.efi by producing it and then just putting it to app/efi/boot/bootx64.efi and then I did
Code: Select all
qemu-system-x86_64 -bios /usr/share/OVMF/OVMF_CODE.fd -hdd fat:rw:app
However, I figured I wouldn't be able to save data in a non-volatile way like this and I would need to instead create a real FAT32 file system image with my /efi/boot/bootx64.efi on that image and then I'd be able to save data to that image. Is that correct?
Well, that aside, so far I know of two ways that should allow me to store data in a non-volatile way:
* Using UEFI variables (in the UEFI shell this can be done with `set`)
* Using the Simple File System Protocol and the File Protocol
* I read that there is a way to read a non-FAT32 file system (e.g. ext2) by using the Block I/O Protocol and parsing the file system myself. The non-FAT32 file system would still have to live on top of the FAT32 one though, right?
Are there other ways?
Well now I'm creating a bootable disk like this: https://wiki.osdev.org/UEFI_App_Bare_Bo ... _FAT_image
Then I run it like this:
Code: Select all
qemu-system-x86_64 -drive file=fat.img,media=disk,format=raw -drive if=pflash,format=raw,unit=0,file=/usr/share/OVMF/OVMF_CODE.fd,readonly=on -drive if=pflash,format=raw,unit=1,file=/usr/share/OVMF/OVMF_VARS.fd
Simply removing the last `-drive` argument from the above command actually starts the bootx64.efi.
Anyway, so as a start I tried obtaining the Simple File System Protocol and that seems to have worked: `EFI_BOOT_SERVICES.LocateProtocol()` returned `EFI_SUCCESS` for that protocol.
For the File Protocol, which is the necessary counterpart, however, `EFI_BOOT_SERVICES.LocateProtocol()` returns `EFI_NOT_FOUND` for that protocol and I can't figure out why.
What could I be doing wrong? Is my `fat.img` in its current state still read-only? Are my QEMU arguments wrong? Can I not store data in the file system in my FAT32 image?
I hope somebody can teach me how to store non-volatile data within the UEFI.