Click here to Skip to main content
15,890,579 members
Articles / Programming Languages / C++

NvramRestorer - dumping and restoring BIOS settings in Windows

Rate me:
Please Sign up or sign in to vote.
3.31/5 (8 votes)
17 Jul 2009CPOL3 min read 35.7K   1.2K   10   4
This tiny tool allows for low-level R/W access to NVRAM bytes 14 to 127.

Introduction

This tiny tool can be used to access some bytes of your mainboard's NVRAM in Windows (should work from Win98 up to Win7 in principle, only tested on WinXP though). The BIOS stores its settings in this NVRAM, therefore it may be used to dump and restore these settings.

Background

I've had serious issues with an old ECS K7S5A mainboard, primarily because it kept on losing its BIOS settings once in a while, although I've tried different batteries and about 10 different BIOS versions. My first approach was to customize the BIOS so that its default settings comply with the optimal settings for the system.

Sadly, there's no way to modify the default FSB clock - every time the settings are lost, it's reduced from 147 MHz back to 100 MHz, resulting in only 2/3 speed (CPU and memory) - simply unacceptable. This is where I started to think about writing directly to the NVRAM containing the BIOS settings from within Windows (XP, in this case) after every boot. In case the current settings differ from the reference dump (defining the 147 MHz FSB) to be restored, a message box alerts my sister that by restarting the system, she'd get a nice speed boost of 47%.

Points of Interest

I've learned that the NVRAM is accessible through low-level I/O ports (in and out instructions in assembler). Recent Windows versions obviously do not allow access to these from user-space, therefore a driver needs to do the job for us. I've already used the great WinRing0 library before, so I've employed it again for this interesting low-level stuff.

So, how do we access the NVRAM using these I/O ports? Well, as it turns out, the first 128 bytes of the NVRAM are accessed by writing the byte offset (0 to 127) to I/O port 0x70 and then reading the byte from or writing its new value to I/O port 0x71.

I was a little worried because the BIOS flash tool displays 16 KB of NVRAM, and I found no information about accessing all these other bytes. Luckily, I've learned that the first 14 bytes are reserved for the RTC (Real Time Clock) and that the BIOS settings are usually stored right after these 14 bytes. Since there are 114 useful bytes to be accessed from I/O ports 0x70/0x71, i.e., more than 900 bits, I just hoped that it would be enough to contain the tightly packed settings along with a checksum at the end.

Therefore, I experimented with different BIOS settings (modifying just the FSB option) and dumped the 114 bytes from the NVRAM to a file. By comparing these dumps, I was pretty certain that it would be alright as they differed in two regions (1-2 bytes each) from each other - i.e., the bits related to the FSB setting and the checksum at the end.

Restoring a dump, i.e., writing it to NVRAM, works on that system. But, please keep in mind that it completely depends upon your BIOS, therefore perform some tests (dumps and comparisons) first. In case something goes wrong, you may need to reset the NVRAM manually, either by setting a jumper on the board or by pushing a button (it's mostly called Clear CMOS).

Summary

Well, I don't think many people will find this utility useful :D - I haven't heard of boards losing their settings once in a while myself until I got this K7S5A. But I find it interesting to be able to access such low-level stuff from within Windows (Linux provides the nvram module and a special /dev/nvram file) - I hope some of you can use this information.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionthanks! and does the CPU fan speed in NVRAM? Pin
matakk30-Nov-10 1:52
matakk30-Nov-10 1:52 
GeneralJust what I was looking for. Pin
sgub3-Mar-10 4:57
sgub3-Mar-10 4:57 
GeneralMy vote of 1 Pin
Michael Chourdakis21-Jan-10 9:16
mvaMichael Chourdakis21-Jan-10 9:16 
GeneralRe: My vote of 1 Pin
kinke20-Feb-10 23:18
kinke20-Feb-10 23:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.