【问题标题】:Reading/Writing EFI variables on Linux in kernel mode在内核模式下在 Linux 上读取/写入 EFI 变量
【发布时间】:2013-12-26 16:18:49
【问题描述】:

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

    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 数据值。 那么你能建议我该怎么做吗?或任何修改?

【问题讨论】:

  • 您确定可以将char * 转换为efi_guid_t * 吗? u32 *attr = (u32 *)0x7; 看起来非常非常错误。在初始化之前,您还在使用efi1
  • 此外,我认为您无需致电 efi_init - 这已在启动时完成。
  • @tangrs ,我对如何初始化 efi1 并访问这些变量感到困惑,所以你能建议任何修改吗?

标签: linux-kernel linux-device-driver efi uefi


【解决方案1】:

尝试将代码改写成这样(注意,它没有经过测试):

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 */
}

【讨论】:

  • 这很有帮助。非常感谢。 @CodeRush
猜你喜欢
  • 1970-01-01
  • 2013-01-10
  • 1970-01-01
  • 2021-11-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多