Linux 用于查询和设置 bios 属性的 API

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6259124/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 04:22:30  来源:igfitidea点击:

APIs for querying and setting bios properties

clinuxoperating-systembios

提问by Karthik Ramachandran

Let's say I would like to change a setting in the BIOS of my computer in Linux (let's say Ubuntu 11 if it matters.) What types of APIs exist to allow you query and manipulate BIOS setting?

假设我想在 Linux 中更改计算机 BIOS 中的设置(如果重要的话,假设是 Ubuntu 11。)有哪些类型的 API 可以让您查询和操作 BIOS 设置?

Further, what are good resources for doing this type of development?

此外,进行此类开发的良好资源是什么?

回答by Nemo

flashromis a utility for flashing a new BIOS image from within Linux.

flashrom是一个用于从 Linux 中刷新新 BIOS 映像的实用程序。

To modify the BIOS settings themselves, you can use the /dev/nvram device.

要自行修改 BIOS 设置,您可以使用 /dev/nvram 设备。

This pageprovides good information on both of these.

本页提供了关于这两个方面的良好信息。

Note that the meaning of the NVRAM contents depends entirely on the BIOS itself; it will vary from BIOS to BIOS and even between revisions of the same BIOS. So the only thing you can reliably do is save the BIOS settings on one system and restore them onto an identical system.

请注意,NVRAM 内容的含义完全取决于 BIOS 本身;它会因 BIOS 的不同而不同,甚至会因同一 BIOS 的不同版本而异。因此,您唯一可以可靠地做的就是将 BIOS 设置保存在一个系统上,然后将它们恢复到相同的系统上。

回答by phoxis

The CMOS memory exists outside of the normal address space and cannot contain directly executable code. It is reachable through IN and OUT commands at port number 70h (112d) and 71h (113d). To read a CMOS byte, an OUT to port 70h is executed with the address of the byte to be read and an IN from port 71h will then retrieve the requested information.

CMOS 存储器存在于正常地址空间之外,不能包含直接可执行的代码。它可以通过端口号 70h (112d) 和 71h (113d) 的 IN 和 OUT 命令访问。要读取 CMOS 字节,将使用要读取的字节地址执行到端口 70h 的 OUT,然后端口 71h 的 IN 将检索请求的信息。

You can use the inband outbmacros to read and write from these ports to get the entire BIOS settings stored in the CMOS. For the settings memory format stored have a look at: http://bochs.sourceforge.net/techspec/CMOS-reference.txt

您可以使用inboutb宏从这些端口读取和写入,以获取存储在 CMOS 中的整个 BIOS 设置。有关存储的设置内存格式,请查看:http: //bochs.sourceforge.net/techspec/CMOS-reference.txt

These mappings are actually vendor dependent, but most of them should be common.

这些映射实际上依赖于供应商,但大多数应该是通用的。

Although this is not an API, but with this you can make direct access to the CMOS memory and make your own API. For a quick program i would recommend getting an API. Check out @Nemo's answer in this case.

虽然这不是一个 API,但是通过它您可以直接访问 CMOS 内存并制作您自己的 API。对于快速程序,我建议获取 API。在这种情况下查看@Nemo 的答案。

回答by JdeBP

This all depends from what one means by "BIOS setting".

这一切都取决于“BIOS设置”的含义。

In traditional, PC/AT, PC machine firmware, the "BIOS settings" are saved in the non-volatile RAM associated with the real-time clock chip. There is pretty much nostandardization as to what the individual bytes of NVRAM represent (although there are a couple of common conventions) and their meanings vary from firmware vendor to firmware vendor, and from firmware release to firmware release. Tools for manipulating the RTC NVRAM include the Linux and FreeBSD /dev/nvramdevice.

在传统的PC/AT、PC机固件中,“BIOS设置”保存在与实时时钟芯片相关联的非易失性RAM中。关于NVRAM 的各个字节代表什么几乎没有标准化(尽管有一些常见的约定),它们的含义因固件供应商而异,从固件版本到固件版本不同。用于操作 RTC NVRAM 的工具包括 Linux 和 FreeBSD/dev/nvram设备。

But this isn't the only non-volatile RAM on a modern PC. The "BIOS ROM" is also, in reality, non-volatile RAM. (One cannot just write to it in normal operation. One has to perform magic incantations to enable write cycles. But it is not Read-Only Memory.) Later PC firmwares use this much larger(potentially up to 16MiB as opposed to 256 bytes) non-volatile RAM for settings storage. System management data such as Extended System Configuration Data and the infamous DMI Pool are stored there. Tools for manipulating these data include the Linux dmidecodeutility which uses /dev/mem.

但这并不是现代 PC 上唯一的非易失性 RAM。“BIOS ROM”实际上也是非易失性 RAM。(不能只是在正常操作中写入它。必须执行魔术以启用写入周期。但它不是只读存储器。)后来的 PC 固件使用更大的内存(可能高达 16MiB,而不是 256 字节)用于设置存储的非易失性 RAM。系统管理数据,如扩展系统配置数据和臭名昭著的 DMI 池都存储在那里。处理这些数据的工具包括 Linuxdmidecode实用程序,它使用/dev/mem.

On a modern PC with EFI firmware, the "BIOS" NVRAM is usually where the EFI firmware environment variables are stored. These can be manipulated by tools such as uefivars, which in their turn rely upon the /sys/firmware/efifilesystem(which effectively, albeit somewhat indirectly, exports the kernel-mode EFI API for variablesto application mode). EFI variables are the "settings" of modern EFI firmwares, controlling a range of things from what's on the EFI Boot Manager menu (c.f. the efibootmgrutility) to what devices constitute the system console.

在带有 EFI 固件的现代 PC 上,“BIOS”NVRAM 通常是存储 EFI 固件环境变量的地方。这些可以通过诸如 之类的工具进行操作uefivars,而这些工具又依赖于/sys/firmware/efi文件系统(尽管有些间接地,它有效地将内核模式 EFI API 的变量导出到应用程序模式)。EFI 变量是现代 EFI 固件的“设置”,控制着从 EFI 引导管理器菜单(参见efibootmgr实用程序)上的内容到构成系统控制台的设备的一系列内容。

回答by SolarKennedy

I'm trying to curate a list of tools to do this on my wiki: https://wiki.xkyle.com/Configuing_BIOS_From_Linux

我正在尝试在我的 wiki 上策划一系列工具来执行此操作:https: //wiki.xkyle.com/Configuing_BIOS_From_Linux

While not technically API's, they are methods to do what you are asking.

虽然不是技术上的 API,但它们是完成您所要求的操作的方法。

They are vendor specific, and for servers.

它们是特定于供应商的,适用于服务器。

  • Intel Severs: Syscfg utility
  • Dell PowerEdge C Servers: setupbios or their syscfg
  • HP Servers: the CONREP utility
  • 英特尔服务器:Syscfg 实用程序
  • Dell PowerEdge C 服务器:setupbios 或它们的 syscfg
  • HP 服务器:CONREP 实用程序