Lesson 10: Working with PCDs in UEFI Shell

If you’ve ever wondered how your computer knows what hardware is installed or where to find certain drivers, well bro, that’s all thanks to these magical little files.

Now before we get started, let me just say this: working with PCDs can be a real pain in the butt. They’re like those annoying cousins who always show up unannounced and insist on staying for dinner even though you have no idea what they want or how to feed them. But don’t freak out! With our trusty UEFI shell, we’ll learn how to navigate these treacherous waters with ease (or at least as easily as possible).

To start: let’s open up the UEFI shell and take a look around. To do this, simply press F2 or Del during startup (depending on your computer) until you see the BIOS menu. From there, navigate to “Advanced” settings and select “UEFI Shell.”

Once we’re in the shell, let’s create a new PCD by typing:

bash
# This script adds a new PCD (Platform Configuration Database) to the UEFI shell.
# PCDs are used to store platform-specific configuration settings.

# First, we need to open the UEFI shell by pressing F2 or Del during startup.
# This will bring up the BIOS menu.
# Depending on the computer, the key may be different.

# Once in the BIOS menu, navigate to "Advanced" settings and select "UEFI Shell."
# This will open the UEFI shell.

# Now, we can create a new PCD by using the "pcd add" command.
# The path to the PCD file is specified after the command.
# In this case, we are creating a PCD called "my_custom_pcd.txt" in the "/var/lib/pcds" directory.

pcd add /var/lib/pcds/my_custom_pcd.txt

This will create a new file called “my_custom_pcd.txt” in our PCD directory (which is located at “/var/lib/pcds”). Now let’s open up this file and add some data to it:

#!/bin/bash # This line specifies the interpreter to be used for the script

pcd="/var/lib/pcds/my_custom_pcd.txt" # This line declares a variable "pcd" and assigns it the value "/var/lib/pcds/my_custom_pcd.txt"

echo "My custom PCD!" > "$pcd" # This line uses the "echo" command to print the string "My custom PCD!" and redirects the output to the file specified by the "pcd" variable

echo "Data added to $pcd" # This line prints a message indicating that data has been added to the file specified by the "pcd" variable

exit # This line exits the script

This will set our current working directory to “/var/lib/pcds” (where we created the new file), add some text to it, and then save and exit the shell. Pretty simple, right? Well hold on there, cowboy! Before you go off thinking this is all sunshine and rainbows, let me tell you about the dark side of PCDs…

First, they can be incredibly finicky when it comes to formatting. If you don’t follow their strict guidelines (which are outlined in the UEFI specification), your data may not be recognized by the system and all sorts of weird errors will start popping up left and right. And let me tell you, there is nothing more frustrating than trying to troubleshoot a PCD issue when you have no idea what’s going on or where to even begin looking for answers.

Secondly, they can be incredibly time-consuming to work with. If you need to make changes to multiple PCDs at once (which is often the case), it can take hours upon hours just to get everything set up properly. And let me tell you, there’s nothing more boring than staring at a screen for hours on end while your computer slowly churns through its calculations…

But hey, that’s life in the world of PCDs! And who knows? Maybe someday we’ll all look back on this time with fond memories, just like those annoying cousins who always show up unannounced but somehow manage to make us laugh anyway…

Until next time, Keep coding (or at least trying to) and remember: sometimes the best way to learn is by making mistakes.

SICORPS