Deployment Solution

 View Only

Read, Write, and Update the BIOS with Linux Automation, Part 2 

Nov 07, 2008 09:14 AM

In my previous article, I outlined how to compile two software packages that are used in reading/writing to/from the BIOS. Those packages were called "libsmbios" and "dmidecode". I also provided an archive with source code and compiled copies of these packages. For this article, I will outline how to add these to our Linux automation images and will demonstrate some simple scenarios where you may use these tools.

As I said in part 1, I OFFER NO WARRANTY TO ANY TERRIBLE/UNFORTUNANTE THINGS THAT MAY HAPPEN TO YOUR SYSTEM FROM USING THESE TOOLS! Obviously I wouldn't write this article if I thought there was a good chance of that happening but you should always do some prior investigation before attempting to make changes to the BIOS.

Image Modification

I assume that you have followed my previous guide and compiled the programs or you have downloaded my archive and extracted its contents. In either case, we are concerned with one directory in particular and that is the "local" directory that lives underneath the "src" directory.

This directory needs to be accessible from a Windows machine in some fashion. It doesn't matter if you share the directory, copy and paste to the Windows machine, put it on a thumb drive, etc; Windows needs to be able to access its contents.

The folder structure of "local" should look like the following...

Now we need to make our directory structure on the Linux image. Open the Boot Disk Creator from the Deployment Solution console. Find your image and right click on the name, click "New -> Folder". Name the folder "usr", all lowercase. Now right click on the "usr" folder and make two new folders underneath it called "bin" and "lib", again all lowercase. It should look like the following when you are done.

Now we can add our files. Right click on "lib" and then click "Add File". When the file browser comes up, go to the "local" folder from earlier. Once there, go inside the "lib" folder and open the filename libsmbios.so.2.0.0. This is the shared library for all the programs from the libsmbios package. A shared library in the Unix/Linux/BSD world is equivalent to a DLL in Windows.

Now we can add our actual programs to the bin folder. Right click on "bin" and then click "Add File". Browse to the folder "local" and then "sbin". You can add any files from here that you would like. Below I've added a list of the files for each package. You should refer to each project's documentation for a briefing on what each program is for. If in doubt, just look at my screenshot below and copy what I did or just add the four commands that are covered in this article. (getSystemId, assetTag, propertyTag, dmidecode)

  • Libsmbios
    • Supported
      • assetTag
      • dellBiosUpdate
      • dellLcdBrightness
      • dellMediaDirectCtl
      • dellWirelessCtl
      • dumpSmbios
      • getSystemId
      • propertyTag
      • serviceTag
      • verifySmiPassword
      • wakeupCtl
    • Un-supported
      • activateCmosToken
      • createUnitTestFiles
      • disable_console_redir
      • getPasswordFormat
      • probes
      • stateByteCtl
      • ascii2enUS_scancode
      • dellLEDCtl
      • dumpCmos
      • isCmosTokenActive
      • smitest
      • upBootCtl
  • dmidecode
    • biosdecode
    • dmidecode
    • ownership
    • vpddecode

You Linux automation image should look something like this at the end.

Note: You may be wondering why we added files from the "sbin" folder to the "bin" folder. In a normal Linux environment, programs that can only be executed by the root user are put in the "sbin" directory. Since the only user in the Deployment Solution Linux image is root, it doesn't actually matter if these files go into a "sbin" directory or a "bin" directory. Also, the Linux image does not add "/usr/sbin" to its PATH environment variable. To change this would require a modification to one of the built-in scripts. Thus it's just easier for us to dump everything into "/usr/bin".

You can now build this image and have access to all of those programs.

Use Cases

Using the commands and viewing their output is the best way to determine what kind of data can be mined from these tools. Check out my tech tip on how to stop the DS agent and just use the command line. This way you can play around with the commands and try different things to find your expected result.

I've put together several "use cases" in this article hoping that someone will find one or more of them useful. If you have an idea that's not listed, don't be afraid to contact me. I've only written documentation on the programs I've used extensively, so anything not mentioned below should be researched on your own.

I'm writing these commands in a way that would be useful for scripting. You should be able to copy/paste these right into DS. Any lines starting with a hash (#) are comments and are not executed by the interpreter. For more information on BASH scripting, check this link.

Note: When writing scripts for DS Automation Linux (and almost all shell scripts in general), the first line of every file should be "#!/bin/bash" without the quotes. This tells the operating system what interpreter to use for the file.

getSystemId

The "getSystemId" program prints some output to the screen that looks like this.

Libsmbios:  2.0.3
System ID:  0x014E
Service Tag: ABCD123
Express Service Code: 12345678901
Product Name: Latitude D800
BIOS Version: A11
Vendor:    Dell Computer Corporation
Is Dell:   1

A lot of things here can be very useful. Here are some examples.

#!/bin/bash

# Grab System ID
getSystemId | grep "^System ID" | sed "s/System ID: *\(.*\)$/\1/"
# Returns: 0x014E

# Grab Service Tag
getSystemId | grep "^Service Tag" | sed "s/Service Tag: *\(.*\)$/\1/"
# Returns: ABCD123

# Service Code
getSystemId | grep "^Express" | sed "s/Express Service Code: *\(.*\)$/\1/"
# Returns: 12345678901

# Bios Version
getSystemId | grep "^BIOS" | sed "s/BIOS Version: *\(.*\)$/\1/"
# Returns: A11

# Vendor
getSystemId | grep "^Vendor" | sed "s/Vendor: *\(.*\)$/\1/"
# Returns: Dell Computer Corporation

# Product Name
getSystemId | grep "^Product Name" | sed "s/Product Name: *\(.*\)$/\1/"
# Returns: Latitude D800

# Turn product name into a unix directory path, all lowercase
getSystemId | grep "^Product Name" | sed "s/Product Name: *\(.*\)$/\1/;s/ /\//g;y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
# Returns: latitude/d800

# Do something special if computer is Dell
isDell=`getSystemId | grep "^Is Dell" | sed "s/Is Dell: *\(.*\)$/\1/"`
if [ $isDell -eq 1 ]; then
	echo "Its a Dell"
else
	echo "Not a Dell"
fi

assetTag

The "assetTag" program can be used to read and set the asset tag. This utility was written with Dell computers in mind so I don't know how well it works with other systems. Here is an example of its usual output.

Existing Asset Tag: SYS272382

And here are some usable examples

 
#!/bin/bash

# Read the asset tag
assetTag | sed "s/Existing Asset Tag: *\(.*\)$/\1/"
# Returns: SYS272382

# Write asset tag to BIOS
# This requires us to load the "dcdbas" kernel module. Fortunately the image has the module installed

# This loads the module
modprobe dcdbas
# This sets the tag
assetTag --set SYS123456

# You can also use Deployment Solution's token replacement functions, like so
assetTag --set %COMPNAME%

propertyTag

The "propertyTag" program works in similar fashion. Heres some example output...

Existing Property Ownership Tag: Illinois State University

And some use case examples.

#!/bin/bash

# Read the property tag
propertyTag | sed "s/Existing Property Ownership Tag: *\(.*\)$/\1/"
# Returns: Illinois State University

# Write property tag to BIOS
# This requires us to load the "dcdbas" kernel module. Fortunately the image has the module installed

# This loads the module
modprobe dcdbas
# This sets the tag
propertyTag --set "Corporation A"

dmidecode

The "dmidecode" program can be used to return an enormous amount of data about your system. Because of the breadth of information the tool can report on, the developers have added some shortcuts for finding simple values. Using the "-s" argument and a keyword from the list below, you can quickly find the information you were looking for. Here is an example.

#!/bin/bash

# Grab processor speed (Frequency)
dmidecode -s processor-frequency
# Returns: 2800 MHz

# Grab chasis type
dmidecode -s chassis-type
# Returns: Mini Tower

And the keyword list is here

bios-vendor
bios-version
bios-release-date
system-manufacturer
system-product-name
system-version
system-serial-number
system-uuid
baseboard-manufacturer
baseboard-product-name
baseboard-version
baseboard-serial-number
baseboard-asset-tag
chassis-manufacturer
chassis-type
chassis-version
chassis-serial-number
chassis-asset-tag
processor-family
processor-manufacturer
processor-version
processor-frequency

For anything else not in that list, we will have to do some string manipulation as we did before with "libmsbios". Here are some examples of that.

#!/bin/bash

# Grab processor flags
dmidecode -t processor | sed -n '/Flags:/,/Version:/p' | sed '/Flags:/d;/Version:/d;s/^[ \t]*//g' 
# Returns this list

# FPU (Floating-point unit on-chip)
# VME (Virtual mode extension)
# DE (Debugging extension)
# PSE (Page size extension)
# TSC (Time stamp counter)
# MSR (Model specific registers)
# PAE (Physical address extension)
# MCE (Machine check exception)
# CX8 (CMPXCHG8 instruction supported)
# APIC (On-chip APIC hardware supported)
# SEP (Fast system call)
# MTRR (Memory type range registers)
# PGE (Page global enable)
# MCA (Machine check architecture)
# CMOV (Conditional move instruction supported)
# PAT (Page attribute table)
# PSE-36 (36-bit page size extension)
# CLFSH (CLFLUSH instruction supported)
# DS (Debug store)
# ACPI (ACPI supported)
# MMX (MMX technology supported)
# FXSR (Fast floating-point save and restore)
# SSE (Streaming SIMD extensions)
# SSE2 (Streaming SIMD extensions 2)
# SS (Self-snoop)

# Check for Intel Hyper-Threading
dmidecode -t processor | grep -q "HTT"
if [ $? -eq 0 ]; then
	echo "Hyper-Threading supported"
else
	echo "Hyper-Threading unsupported"
fi

# Find frontside bus speed
dmidecode -t processor | grep "External Clock" | sed 's/External Clock: \(.*\)$/\1/;s/^[ \t]//g'
# Returns: 800 MHz

# Look at memory banks and see what is installed
dmidecode -t memory | grep "Size:" | sed 's/^[ \t]*//g'
# Returns this list

# Size: 512 MB
# Size: 512 MB
# Size: No Module Installed
# Size: No Module Installed

# Read Bios Characteristics
dmidecode -t bios | sed -n '/Characteristics:/,/^$/p' | sed '/Characteristics/d;s/^[ \t]*//g;/^$/d'
# Returns this list

# PCI is supported
# PNP is supported
# APM is supported
# BIOS is upgradeable
# BIOS shadowing is allowed
# ESCD support is available
# Boot from CD is supported
# Selectable boot is supported
# EDD is supported
# Japanese floppy for Toshiba 1.2 MB is supported (int 13h)
# Print screen service is supported (int 5h)
# 8042 keyboard services are supported (int 9h)
# Serial services are supported (int 14h)
# Printer services are supported (int 17h)
# ACPI is supported
# USB legacy is supported
# AGP is supported
# LS-120 boot is supported
# BIOS boot specification is supported
# Function key-initiated network boot is supported

Hopefully these examples will give you a good head start on writing your own scripts.

Statistics
0 Favorited
0 Views
1 Files
0 Shares
0 Downloads
Attachment(s)
jpg file
6146.jpg   3 KB   1 version
Uploaded - Feb 25, 2020

Tags and Keywords

Comments

Nov 07, 2008 07:41 PM

Thanks for posting such a useful article. Please keep them coming.

Related Entries and Links

No Related Resource entered.