Sphere478 wrote on 2025-03-13, 22:56:
When will the next modding episode be? 😀
Hi Sphere478,
You are right to keep asking when I will continue with the DIY BIOS modding guide.
It took me a long time, but now the next episode is here! 😊
Note that Part 7 of this story is a recent addition to my patching repertoire. This part about manually compressing the System BIOS module and adding it to the compressed BIN-file, needed to be included here.
Enjoy!
Jan
#Part 6 – How to patch a compressed Award BIOS
With this part I will start a series of episodes about the compressed Award Modular BIOS v4.5xPG(M).
I will first show how to handle the compressed modules in these BIOSes, followed by a description of what you can patch to get better CPU support and fix bugs.
The compressed BIOS
From about 1996 the 128KB (E)EPROM size was not sufficient anymore to contain all BIOS routines, so BIOS developers started to use compressed BIOSes. The top 20KB or so of these compressed BIOSes is not compressed and contains the initial boot code and the decompression engine. Also the ESCD block where the BIOS stores its PnP data is located here. On a 128KB BIOS, this leaves about 108KB for the compressed modules. Due to a slightly different organization, a 256KB BIOS will usually have 220KB compressed code space available.
These 256KB compressed BIOSes started to appear not long after the 128KB compressed BIOS, and obviously could contain more and larger modules, like for extra option ROMs and full screen logo’s.
While on an uncompressed BIOS all code and data is readily available directly from the ROM (or from Shadow RAM at the same addresses when copied there to improve performance), a compressed BIOS has to perform a lot of extra steps to get its contents ready for use.
Only the Bootblock in the top 8KB of the BIOS is largely the same on both the compressed and uncompressed BIOS. At power-up or reset, the BIOS Bootblock is always the first code to be executed and performs the initial chipset setup and RAM test. The uncompressed BIOS then jumps directly to the POST block to perform the Power-On-Self-Test.
The compressed BIOS however first calls the decompression engine to decompress all compressed BIOS modules into RAM. After an integrity check, the decompressed modules are copied to their allocated place in RAM or Shadow RAM. The 128KB main BIOS module original.tmp is thereby always copied to real mode addresses E000:0000h-F000:FFFFh in Shadow RAM.
Because this address range is the same as for the (E)EPROM containing the compressed BIOS, the (E)EPROM access is disabled when the decompressed main BIOS module in Shadow RAM gets control.
Apart from a few exceptions from the 1995/1996 transition period, the Award BIOSes up to v4.50G are uncompressed while v4.50PG and v4.51PG BIOSes are the compressed versions.
When you open such a compressed BIOS in a Hexeditor and look at the beginning of the BIN file, you see the header of the first compressed module. This header contains an -lh5- string at offsets 02h-06h, indicating an LZH level-1 compressed file. At offset 16h you see the filename of this compressed module.
The attachment Compressed BIOS.png is no longer available
On an 128KB BIOS, the first compressed module is always the main BIOS component and usually has original.tmp as filename. The other compressed modules are placed directly behind this main module, just like the compressed files in a zip archive.
On the 256KB BIOS, the placing of the compressed modules is a bit different. The compressed original.tmp is located at offset 20000h and together with the bootblock, have the whole 128KB second half of the BIOS for themselves. The first half, so from offset 0h to 1FFFFh, is for all additional modules.
Award Tools
For the Award BIOS, there are some nice tools from Award Software to handle the compressed BIOS. I use MODBIN v4.50.82a and CBROM v1.30c for socket 7 BIOSes.
The attachment awdtools.zip is no longer available
With the CBROM tool, you can view and manipulate the compressed components in the BIOS BIN file.
This is what you get when using the /d command-line switch for dumping the contents of the BIOS on screen:
The attachment CBROM S1590 BIOS.png is no longer available
This CBROM ouput is from a Tyan S1590 v1.16c socket 7 BIOS, the first compressed BIOS I patched, back in November 2000. 😊
Extracting and Loading modules from the compressed BIOS
Most patches I do in the socket 7 BIOS, have to be made in the main BIOS module. So how do we get this module in decompressed form from the compressed BIOS BIN-file?
It appears that Award’s MODBIN tool is not only useful for viewing and editing the BIOS Setup menus, but can also be used to easily get the main BIOS image from the compressed BIN file.
If you load the BIN in MODBIN and then exit the program without making any changes, 2 new files are created. One of them, ORIGINAL.TMP, is the decompressed main BIOS image file. The size of this file is always 128KB.
I always rename this ORIGINAL.TMP file to have a working copy and to avoid it to be overwritten the next time I start MODBIN. Any appropriate filename for the BIOS in question will do, but below I will use a generic BIOSNAME.IMG as example.
After analyzing the disassembly listing from the decompressed BIOS image and doing the actual patching with my hexeditor, I run the patched image through the disassembler again to check for errors.
Note that Award made a lot of code changes over time so that I need to check each BIOS carefully to see what needs to be changed.
Just as with the earlier described 486 patches, I will provide a binary signature to help you find the spot in your decompressed BIOS image where to apply the patch. This string of bytes will uniquely identify the offending code or data so you don’t have to mess with a disassembler. The search function of your Hexeditor is then all you need.
After patching there is the trick of placing the patched main BIOS image back in compressed form into the BIN file and getting the checksum bytes right. It appeared that this can be done via a special procedure under Windows, with the help of MODBIN.
This procedure makes use of the multitasking capability of Windows, but because MODBIN is a DOS program we have to use a 32-bit Windows version. Any 32-bit Windows, from Win95 to Windows 10 will do.
Although the below procedure could be modified to be used from 64-bit Windows with the help of a DOS emulator like DOSBox, I find it easier to use it under 32-bit Windows directly.
• In Windows explorer, navigate to the folder that contains the BIOS files to work on. This folder should at least have the patched decompressed main BIOS image file (BIOSNM-J.IMG) and a renamed copy of the original compressed BIOS BIN file, that will become the new BIOS.
• Type CMD in the addressbar in explorer and hit the Enter key. This will open a Command window with the current folder as focus.
• Run MODBIN from the CMD-prompt and load the new BIN in MODBIN.
• Now use the same explorer trick to open a second CMD window with a focus on the same folder.
• Use the Copy command to replace the ORIGINAL.TMP file by the patched BIOS image. In our example this command would look like: COPY BIOSNM-J.IMG ORIGINAL.TMP
You will get a question if you want to overwrite ORIGINAL.TMP and hit the Y key to confirm.
• Close this second window with the EXIT command.
• Go back to MODBIN in the first CMD window and select "Update file" to compress and save the patched BIOS image in the new BIN file. MODBIN will automatically calculate the checksum over all the compressed BIOS components and correct the checksum bytes of the BIN.
Note that you have to use MODBIN v4.50.77 or later to get the correct checksum bytes!
However, this trick only works for changes made in the E000h segment (the first 64KB half of the 128KB ORIGINAL.TMP).
Unlike this E000h segment, the F000h segment, in the second half of ORIGINAL.TMP, cannot be changed directly because MODBIN holds a work copy in memory, overwriting any changes when you update the file. Only the changes you make here via MODBIN's menus are allowed in the F000h segment.
Luckily, most changes needed for patching CPU and HDD support have to be made in the E000h segment.
There is a way to make changes in the F000h segment manually, but I will tell about this complicated procedure in the next episode.
As a final crosscheck I check both the original and the patched BIN file with Award's CBROM tool. With the /D switch you can view all BIOS components in the compressed BIN file. The patched BIN should contain the same components and should still have some compressed code space left.
You can also use CBROM to manipulate other modules, like the BIOS extension helper module AWARDEXT.ROM. With CBROM /? you can view the various options.
For extracting, releasing, or loading the AWARDEXT.ROM module you have to use the commands:
CBROM 2A5xxxxx.bin /other 4100:0 extract
CBROM 2A5xxxxx.bin /other 4100:0 release
CBROM 2A5xxxxx.bin /other 4100:0 awardext.rom
To fix the Award BIOS 64GB HDD limit bug, changes will be needed in this AWARDEXT.ROM module.
I will show the details in a later episode.
- more in the next posting -