13

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?

Karthik Ramachandran
  • 11,347
  • 9
  • 43
  • 52

4 Answers4

7

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.

You can use the inb and outb 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.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.

phoxis
  • 52,327
  • 12
  • 74
  • 110
5

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.

Nemo
  • 65,634
  • 9
  • 110
  • 142
4

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. the efibootmgr utility) to what devices constitute the system console.

JdeBP
  • 1,891
  • 14
  • 23
2

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.

  • Intel Severs: Syscfg utility
  • Dell PowerEdge C Servers: setupbios or their syscfg
  • HP Servers: the CONREP utility
SolarKennedy
  • 108
  • 6