查询和设置BIOS属性的API
假设我想更改 Linux 计算机的 BIOS 设置(如果重要的话,假设是 Ubuntu 11)。有哪些类型的 API 可以让您查询和操作 BIOS 设置?
此外,进行此类开发的良好资源是什么?
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?
Further, what are good resources for doing this type of development?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这一切都取决于“BIOS 设置”的含义。
在传统的PC/AT PC机器固件中,“BIOS设置”保存在与实时时钟芯片相关的非易失性RAM中。对于 NVRAM 的各个字节所代表的内容几乎没有标准化(尽管有一些常见约定),并且它们的含义因固件供应商和固件版本而异。用于操作 RTC NVRAM 的工具包括 Linux 和 FreeBSD
/dev/nvram
设备。但这并不是现代 PC 上唯一的非易失性 RAM。实际上,“BIOS ROM”也是非易失性 RAM。 (在正常操作中不能只对其进行写入。必须执行魔法才能启用写入周期。但它不是只读存储器。)后来的 PC 固件使用这个大得多(可能高达16MiB(而不是 256 字节)非易失性 RAM 用于设置存储。扩展系统配置数据和臭名昭著的 DMI 池等系统管理数据都存储在那里。用于操作这些数据的工具包括使用
/dev/mem
的 Linuxdmidecode
实用程序。在具有 EFI 固件的现代 PC 上,“BIOS”NVRAM 通常是存储 EFI 固件环境变量的位置。这些可以通过
uefivars
等工具进行操作,依次 依赖/sys/firmware/efi
文件系统(虽然有些间接,但实际上,导出用于变量的内核模式 EFI API 到应用程序模式)。 EFI 变量是现代 EFI 固件的“设置”,控制着一系列内容,从 EFI 启动管理器菜单上的内容(参见efibootmgr
实用程序)到构成系统控制台的设备。This all depends from what one means by "BIOS setting".
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 no standardization 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/nvram
device.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
dmidecode
utility which uses/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/efi
filesystem (which effectively, albeit somewhat indirectly, exports the kernel-mode EFI API for variables to 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. theefibootmgr
utility) to what devices constitute the system console.我正在尝试在我的 wiki 上整理一个工具列表来执行此操作:
https://wiki.xkyle.com/Configuing_BIOS_From_Linux
虽然从技术上讲不是 API,但它们是执行您操作的方法正在问。
它们是特定于供应商的,并且适用于服务器。
I'm trying to curate a list of tools to do this on my wiki:
https://wiki.xkyle.com/Configuing_BIOS_From_Linux
While not technically API's, they are methods to do what you are asking.
They are vendor specific, and for servers.
您可以使用
inb
和outb
宏从这些端口读取和写入,以获取存储在 CMOS 中的整个 BIOS 设置。有关存储的设置内存格式,请查看:http://bochs.sourceforge.net/ techspec/CMOS-reference.txt这些映射实际上取决于供应商,但其中大多数应该是通用的。
虽然这不是一个 API,但是通过它您可以直接访问 CMOS 内存并制作您自己的 API。对于快速程序,我建议使用 API。在这种情况下查看@Nemo 的答案。
You can use the
inb
andoutb
macros 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.txtThese 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.
flashrom 是一个用于在 Linux 中刷新新 BIOS 映像的实用程序。
要修改 BIOS 设置本身,您可以使用 /dev/nvram 设备。
此页面提供了有关这两个方面的良好信息。
请注意,NVRAM 内容的含义完全取决于 BIOS 本身;不同的 BIOS 甚至同一 BIOS 的不同版本之间也会有所不同。因此,您唯一可以可靠地做的就是将 BIOS 设置保存在一个系统上,并将它们恢复到相同的系统上。
flashrom is a utility for flashing a new BIOS image from within Linux.
To modify the BIOS settings themselves, you can use the /dev/nvram device.
This page provides 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.