在Linux内核模式下读取/写入EFI变量 [英] Reading/Writing EFI variables on Linux in kernel mode

查看:411
本文介绍了在Linux内核模式下读取/写入EFI变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Linux UEFI上工作.我想通过驱动程序代码访问efi变量. 目前,我正在寻找像efi.get_variable()这样的linux/efi.h API. 但是我不知道如何从驱动程序代码中调用这些API.

I am working on Linux UEFI .I want to access the efi variables through my driver code. Currently I'm looking linux/efi.h API like efi.get_variable(). but I'm not getting how to call those APIs with from my driver code.

    struct efi  efi1;
efi_init();         
    efi_char16_t *name = (efi_char16_t *)"Boot001";
    efi_guid_t *vendor = (efi_guid_t *)"8be4df61-93ca-11d2-aa0d-00e098032b8c";
    u32 *attr = (u32 *)0x7;
    unsigned long data_size = 1024;
    void *data = NULL;

    printk("\n Showing efi info \n");
    stat = efi1.get_variable(name,vendor,attr,&data_size,data);

使用此代码,我得到数据的NULL值. 那么,您能建议我该怎么办?或进行任何修改?

with this code I'm getting NULL value for data. So can you suggest what should I do? or any modification?

推荐答案

尝试将代码重写为类似以下内容(请注意,未经测试):

Try rewriting the code to something like this (beware, it's not tested):

efi_char16_t name[] = L"Boot0001";
efi_guid_t guid = EFI_GLOBAL_VARIABLE_GUID;
u32 attr;
unsigned long data_size = 0;
u8 *data = NULL;
efi_status_t status;

/* Get real size of UEFI variable */
status = efi.get_variable(name,&guid,&attr,&data_size,data);
if (status == EFI_BUFFER_TOO_SMALL) {
   /* Allocate data buffer of data_size bytes */
   data = (u8*)vmalloc(data_size);
   if (!data) {
       /* Your handling here */
   }

   /* Get variable contents into buffer */
   status = efi.get_variable(name,&guid,&attr,&data_size,data);
   if (status != EFI_SUCCESS) {
       /* Your handling here */
   }
   else {
       /* Variable is now in data */
   }   
} 
else if (status == EFI_NOT_FOUND) {
   /* There is no Boot0001 variable. Try Boot0000 maybe? */
} 
else {
   /* Your handling here */
}

这篇关于在Linux内核模式下读取/写入EFI变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆