How to change hidden CFG Lock setting
I'm going to clarify the procedure how to figure out the offset for
CFG Lock setting and how to apply needed change in BIOS.
Please note, it's not exactly patching the BIOS. It's about changing it's hidden variables.
View attachment 367163
If you don't have needed tools, then for first you should acquire these tools. Needed tools are UEFITool and IFR-Extractor. Also you need GRUB Shell to change settings.
Shortly about setup_var
UEFI documentation ((U)EFI = (Unified) Extensible Firmware Interface):
EFI variables can be read and modified in Linux, which is done trough the sys pseudo-filesystem, where EFI varies are mounted at /sys/firmware/efi/efivars. Some GRUB versions supports modifying EFI variable storage space (VSS) via command setup_var, which can take up to two arguments, a variable identifier/offset (0xDF etc) and a value to write to this variable (0x1 etc).
Command setup_var in the modified GRUB can change settings which are stored in the "Setup-{guid}" efivar and with setup_var_2(setup_var_3 settings which are stored in the "Config-{guid}" efivar.
Usage of setup_var
To read current configuration:
To write setting
Download tools:
Download BIOS or save it to the disk from BIOS GUI
- Download BIOS from Gigabyte website (22g) or
- save it to the disk from your BIOS settings GUI (FAT16 or FAT32 drive is needed for that)
Extract CFG Lock related block from BIOS
Code:
cd ~/Desktop
mkdir cfglockfix
curl -L http://download.gigabyte.eu/FileList/BIOS/mb_bios_ga-z170x-ud5-th_f22g.zip -o bios.zip -s
unzip -a bios.zip
rm autoexec.bat
rm Efiflash.exe
rm bios.zip
curl -L https://github.com/LongSoft/UEFITool/releases/download/t20181011/UEFITool_NE_A52_mac.zip -o uefitool.zip -s
unzip -a uefitool.zip
rm uefitool.zip
curl -L https://github.com/LongSoft/Universal-IFR-Extractor/releases/download/v0.3.5/ifrextract_v0.3.5.osx.zip -o ifextract.zip -s
unzip -a ifextract.zip
rm ifextract.zip
./UEFITool.app/Contents/MacOS/UEFITool ~/Desktop/cfglockfix/Z17XU5TH.22g
Now we should have UEFITool opened with with BIOS image Z17XU5TH.22g.
Then we press CMD+F and and select text and type CFG Lock and press OK.
View attachment 363796
View attachment 363795
Then we have to double click on search result, which leads as to the section containing CFG Lock setting.
Then we right click on selected block and select extract body and safe it as PE32Section.efi and quit UEFITool.
View attachment 363797
View attachment 363798
Then we run following command on terminal
Code:
./ifrextract PE32Section.efi PE32Section.txt
We should have now text file which reveals offset for CFG Lock setting.
View attachment 363801
Code:
0x33377 Form: View/Configure CPU Lock Options, FormId: 0x2734 {01 86 34 27 11 07}
0x3337D One Of: CFG Lock, VarStoreInfo (VarOffset/VarName): 0x4EF, VarStore: 0x1, QuestionId: 0x24C, Size: 1, Min: 0x0, Max 0x1, Step: 0x0 {05 91 B4 08 B5 08 4C 02 01 00 EF 04 10 10 00 01 00}
0x3338E One Of Option: Disabled, Value (8 bit): 0x0 {09 07 04 00 00 00 00}
0x33395 One Of Option: Enabled, Value (8 bit): 0x1 (default) {09 07 03 00 30 00 01}
0x3339C End One Of {29 02}
0x3339E One Of: Overclocking Lock, VarStoreInfo (VarOffset/VarName): 0x59E, VarStore: 0x1, QuestionId: 0x24D, Size: 1, Min: 0x0, Max 0x1, Step: 0x0 {05 91 B0 08 B1 08 4D 02 01 00 9E 05 10 10 00 01 00}
0x333AF One Of Option: Disabled, Value (8 bit): 0x0 (default) {09 07 04 00 30 00 00}
0x333B6 One Of Option: Enabled, Value (8 bit): 0x1 {09 07 03 00 00 00 01}
0x333BD End One Of {29 02}
0x333BF End Form {29 02}
The line we are interested about is:
One Of: CFG Lock, VarStoreInfo (VarOffset/VarName): 0x4EF, VarStore: 0x1,...
0x4EF is offset and
0x1 is default setting.
We have figured out the command to use with
modified GRUB Shell for motherboard Z170X-UD5 TH BIOS version f22g:
Seems that for various Z170X-UD5 TH BIOS versions (F20 and newer) offset is 0x4EF:
Didn't check older versions.
How to create bootable USB for GRUB shell
1 . Make bootable USB stick for Grub Shell
Inject USB stick into USB port and follow next steps... Be very careful, that you dont erase your system or other important disks accidentally.
a. Mac Instuctions
- Open Disk Utility
- Select your USB drive (Entire drive, not partition)
- Click Partition
- Choose GUID scheme, FAT format and any name you like.
View attachment 367157
b. Linux Instructions
If for some case Mac instructions doesn't suit you, you can create bootable USB on Linux Terminal easily too. Run
lsblk --fs to detect your USB device, for example /dev/sdc or /dev/sda etc. Terminal commands below are for USB device /dev/sdc, use your own device instead of that.
Code:
lsblk --fs
sudo parted -s /dev/sdc print
sudo wipefs -a /dev/sdc
sudo parted -s /dev/sdc print
sudo parted /dev/sdc help mktable
sudo parted /dev/sdc mktable msdos
sudo parted /dev/sdc help mkpart
sudo parted /dev/sdc mkpart primary fat32 0% 100%
sudo mkfs.fat -F 32 /dev/sdc1
sudo parted /dev/sdc set 1 boot on
lsblk --fs
2. Download and put Grub Shell on usb
- Download Grub Shell from grub-mod-setup_var
- Extract it into ~/Downloads folder
- Rename it from modGRUBShell.efi to bootx64.efi
- Copy bootx64.efi into USB disk
Code:
cd /Volumes/NO\ NAME
ls
mkdir -p /Volumes/NO\ NAME/EFI/BOOT
cp -iR ~/Downloads/bootx64.efi /Volumes/NO\ NAME/EFI/BOOT/bootx64.efi
View attachment 367158
3. Make changes
- Reboot from USB disk / Press F12 key for boot options
- Change settings
Make sure that you have UEFI boot enabled
View attachment 367160
Press F12 key for boot options
View attachment 367159
On GRUB shell you can now use setup_var or setup_var_2 or setup_var_3 commands.
View attachment 367161
To check variable just enter setup_var <offset> for example:
or
NB! On some BIOS you might find this useful, use
setup_var_3 instead of setup_var. Read more on
grub-mod-setup_var