UEFI Script Files (AN48): Difference between revisions
Adrianascher (talk | contribs) |
Piotrkorsak (talk | contribs) mNo edit summary |
||
| (11 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
{| | {{Affected products|Affected products=All products featuring UEFI}} | ||
==Preface== | ==Preface== | ||
This application note describes how to create a UEFI script file for automating the cBC firmware update and BIOS in a production line environment. It also shows how UEFI script files can be used with the congatec system utility CGUTIL. The scripts are suitable for all UEFI-enabled congatec x86 products. | This application note describes how to create a UEFI script file for automating the cBC firmware update and BIOS in a production line environment. It also shows how UEFI script files can be used with the congatec system utility CGUTIL. The scripts are suitable for all UEFI-enabled congatec x86 products. | ||
== Terminology == | |||
{| class="wikitable" | {| class="wikitable" | ||
! style="background-color: #555555; color: #FFFFFF;" |Term | ! style="background-color: #555555; color: #FFFFFF;" |Term | ||
| Line 16: | Line 13: | ||
|- | |- | ||
|BIOS | |BIOS | ||
|Basic Input Output System | |Basic Input Output System - Legacy boot firmware. Name still commonly used for UEFI firmware | ||
|- | |- | ||
|UEFI | |UEFI | ||
|Unified Extensible Firmware | |Unified Extensible Firmware Interface - New boot firmware | ||
|- | |- | ||
|COM | |COM | ||
| Line 29: | Line 26: | ||
==Introduction== | ==Introduction== | ||
A UEFI script is a series of statements that tell an application to perform certain tasks. The script is written as plain text file and saved with .nsh extension. With these scripts, customers can simplify the process of updating the BIOS and cBC firmware on congatec COMs in their production line. Generally, these scripts can run in a built-in UEFI shell or in a bootable USB flash drive compiled with UEFI shell. | A UEFI script is a series of statements that tell an application to perform certain tasks. The script is written as plain text file and saved with <code>.nsh</code> extension. With these scripts, customers can simplify the process of updating the BIOS and cBC firmware on congatec COMs in their production line. Generally, these scripts can run in a built-in UEFI shell or in a bootable USB flash drive compiled with UEFI shell. | ||
The congatec embedded BIOS however does not support the built-in UEFI shell because of security reasons. Having a built-in shell may allow users the possibility to bypass security mechanisms that are contained within the BIOS. | The congatec embedded BIOS however does not support the built-in UEFI shell because of security reasons. Having a built-in shell may allow users the possibility to bypass security mechanisms that are contained within the BIOS. | ||
To execute UEFI scripts on congatec COMs, you need to create a bootable USB flash drive with compiled UEFI shell. The procedure to create such a boot USB flash drive is explained in the application note | To execute UEFI scripts on congatec COMs, you need to create a bootable USB flash drive with compiled UEFI shell. The procedure to create such a boot USB flash drive is explained in the application note [[How to create a bootable USB stick with a UEFI shell (AN31)]]. You can download this document from: | ||
https://www.congatec.com/us/support/application-notes/article/an31-how-to-create-a-bootable-usb-stick-with-an-uefi-shell/ | |||
< | <span style="color: red;">'''Caution:'''</span> | ||
<span style="color: red;">'''''Ensure that there is no loss of power during the BIOS and cBC firmware update. The loss of power during the flash update will result in a non-bootable product that requires RMA. The cBC firmware update should especially be performed only in a safe production environment.'''''</span> | |||
'''Note:''' | |||
'''''There are two BIOS update procedures for the production line described in this document. The first procedure is for normal BIOS updates while the other procedure is for extended BIOS updates.''''' | |||
'''''Unlike normal BIOS updates, the extended update requires a reboot cycle to unlock the flash.''''' | |||
'''''Please refer to [[BIOS Update (AN01)#CGUTLCMD Command Line Parameters|section 3]] of [[BIOS Update (AN01)]] for more details on normal (UEFI firmware only) and extended BIOS update. You can download this document from the link below:''''' | |||
'''''https://www.congatec.com/en/support/application-notes/article/an01-bios-update/''''' | |||
==UEFI Script for Production Line== | ==UEFI Script for Production Line== | ||
| Line 53: | Line 60: | ||
|- | |- | ||
|startup.nsh | |startup.nsh | ||
|The first script that is | |The first script that is automatically executed when UEFI shell launches. This script is a container for other scripts (similar to autoexec.bat on old DOS system) | ||
|- | |- | ||
|flash_bios.nsh | |flash_bios.nsh | ||
|This script updates the congatec | |This script updates the congatec BIOS. Type the number “1” in startup script and press “Enter” to execute this script. | ||
|- | |- | ||
|eflash_bios.nsh | |eflash_bios.nsh | ||
| Line 62: | Line 69: | ||
|- | |- | ||
|flash_cbc.nsh | |flash_cbc.nsh | ||
|This script updates the congatec | |This script updates the congatec Board Controller (cBC). Type the number “3” in startup script and press “Enter” to execute this script. | ||
|- | |- | ||
|flash_both.nsh | |flash_both.nsh | ||
|This script updates both the BIOS | |This script updates both the BIOS and the cBC. Type the number “4” in startup script and press “Enter” to execute this script. | ||
|} | |} | ||
'''Note:''' | |||
'''''Use plain text editor such as Notepad when creating UEFI scripts. If you use a word processor, the scripts may execute with errors due to hidden embedded characters associated with word processors.''''' | |||
===Production-Line Script Files=== | ===Production-Line Script Files=== | ||
| Line 74: | Line 84: | ||
====startup.nsh==== | ====startup.nsh==== | ||
Follow the steps below to create the startup.nsh script. | Follow the steps below to create the <code>startup.nsh</code> script. | ||
{{Continue Numbered List|1|Open Notepad.}} | {{Continue Numbered List|1|Open Notepad.}} | ||
{{Continue Numbered List|2|Type the following texts below | {{Continue Numbered List|2|Type the following texts below. The comment lines (#) will be ignored during execution.}} | ||
<pre> | <pre> | ||
| Line 101: | Line 111: | ||
# keyboard, the aliases 1, 2, 3 correspond to the names of | # keyboard, the aliases 1, 2, 3 correspond to the names of | ||
# script files and can be entered at the keyboard and executed | # script files and can be entered at the keyboard and executed | ||
# as commands, to get around this UEFI limitation. | |||
# as commands, to get around this UEFI limitation. | # as commands, to get around this UEFI limitation. | ||
echo " " | echo " " | ||
echo "Enter choice number below followed by the enter key" | echo "Enter choice number below followed by the enter key" | ||
echo "1 | echo "1 for a normal BIOS update" | ||
echo "2 | echo "2 for an extended BIOS update" | ||
echo "3 to update | echo "3 to update the cBC firmware" | ||
echo "4 to update the BIOS and the cBC firmware" | echo "4 to update the BIOS and the cBC firmware" | ||
# The above echo commands are sent to the display | |||
# The above echo commands are sent to the display to offer the | # The above echo commands are sent to the display to offer the | ||
# user a menu. | # user a menu. | ||
| Line 118: | Line 130: | ||
</pre> | </pre> | ||
{{Continue Numbered List|3|Save the script as startup.nsh file.}} | {{Continue Numbered List|3|Save the script as <code>startup.nsh</code> file.}} | ||
====flash_bios.nsh==== | ====flash_bios.nsh==== | ||
Follow the steps below to create the script for updating the congatec BIOS. | Follow the steps below to create the script for updating the congatec BIOS (UEFI firmware only). | ||
#Open Notepad. | #Open Notepad. | ||
| Line 143: | Line 155: | ||
</pre> | </pre> | ||
{{Continue Numbered List|3|Save the script as flash_bios.nsh file.}} | {{Continue Numbered List|3|Save the script as <code>flash_bios.nsh</code> file.}} | ||
====eflash_bios.nsh ==== | ====eflash_bios.nsh ==== | ||
| Line 169: | Line 181: | ||
echo -on | echo -on | ||
</pre> | </pre> | ||
{{Continue Numbered List|3|Save the script as eflash_bios.nsh file.}} | {{Continue Numbered List|3|Save the script as <code>eflash_bios.nsh</code> file.}} | ||
====flash_cbc.nsh==== | ====flash_cbc.nsh==== | ||
| Line 193: | Line 205: | ||
</pre> | </pre> | ||
{{Continue Numbered List|3|Save the script as flash_cbc.nsh file.}} | {{Continue Numbered List|3|Save the script as <code>flash_cbc.nsh</code> file.}} | ||
====flash_both-nsh==== | ====flash_both-nsh==== | ||
| Line 205: | Line 217: | ||
cls | cls | ||
cgutlcmd bcprog CGBCP440.DAT | cgutlcmd bcprog CGBCP440.DAT | ||
# command to update cBC firmware | # command to update cBC firmware | ||
cgutlcmd bflash SA50R061.BIN | cgutlcmd bflash SA50R061.BIN | ||
# command to update BIOS | # command to update BIOS | ||
echo " " | echo " | ||
echo "If the cBC firmware | " echo "If the BIOS and cBC firmware were updated successfully, turn the power off and then back on (G3 cycle)." | ||
echo "Then verify on the main setup menu that the cBC firmware shown | echo "Then verify on the main setup menu that the BIOS name and cBC firmware shown are correct." | ||
echo " " | echo " | ||
echo "Press 5 followed by the enter key to return to the main menu | " echo "Press 5 followed by the enter key to return to the main menu" | ||
# displays instructions to the user after the cBC | # displays instructions to the user after the BIOS and cBC FW | ||
# been updated. | # have been updated. | ||
echo -on | echo -on | ||
</pre> | </pre> | ||
{{Continue Numbered List|3|Save the script as | {{Continue Numbered List|3|Save the script as <code>flash_both.nsh</code> file.}} | ||
=== Dynamic Detection of Correct File System === | === Dynamic Detection of Correct File System === | ||
| Line 235: | Line 247: | ||
Follow this procedure to add the required files to the bootable USB stick: | Follow this procedure to add the required files to the bootable USB stick: | ||
#Create a bootable USB stick with compiled UEFI shell as described in congatec | #Create a bootable USB stick with compiled UEFI shell as described in congatec Application Note [[How to create a bootable USB stick with a UEFI shell (AN31)]] | ||
#Download '''cgutil_V159.zip''' from congatec | #Download '''<code>cgutil_V159.zip</code>''' from congatec at https://www.congatec.com | ||
*To download this file, click the "Products" menu on congatec website and select any of the x86 modules. | |||
*Click on the software tab and navigate to Windows 10 section | |||
* Locate the <code>cgutil_V159.zip</code> file and download it. | |||
{{Continue Numbered List|3|Unzip the cgutil_V159.zip file. | {{Continue Numbered List|3|Unzip the <code>cgutil_V159.zip</code> file. | ||
#Copy the cgutlcmd.efi file from cgutil/uefi/X64 directory to the root directory of the UEFI Shell USB stick. | #Copy the <code>cgutlcmd.efi</code> file from cgutil/uefi/X64 directory to the root directory of the UEFI Shell USB stick. | ||
#Copy also the previously created script files startup.nsh, flash_bios.nsh, flash_cbc.nsh and flash_both.nsh to the root directory of the UEFI Shell USB stick. | #Copy also the previously created script files <code>startup.nsh</code>, <code>flash_bios.nsh</code>, <code>flash_cbc.nsh</code> and <code>flash_both.nsh</code> to the root directory of the UEFI Shell USB stick. | ||
#Copy the BIOS file you want to update to the root directory of the UEFI Shell USB stick. You can have several BIOS files on the USB stick. However, the UEFI script will update only the BIOS file that is indicated with the <code>cgutlcmd bflash biosfile.bin</code> command in the flash_bios.nsh and flash_both.nsh script files. | #Copy the BIOS file you want to update to the root directory of the UEFI Shell USB stick. You can have several BIOS files on the USB stick. However, the UEFI script will update only the BIOS file that is indicated with the <code>cgutlcmd bflash biosfile.bin</code> command in the <code>flash_bios.nsh</code> and <code>flash_both.nsh</code> script files. | ||
#Copy the cBC Firmware file you want to update to the root directory of the UEFI Shell USB stick. You can have several cBC firmware files on the USB stick. However, the UEFI script will update only the cBC firmware that is indicated with the <code>cgutlcmd bcprog cgbcpxxx.dat</code> command in the flash_cbc.nsh and flash_both.nsh script files.}} | #Copy the cBC Firmware file you want to update to the root directory of the UEFI Shell USB stick. You can have several cBC firmware files on the USB stick. However, the UEFI script will update only the cBC firmware that is indicated with the <code>cgutlcmd bcprog cgbcpxxx.dat</code> command in the <code>flash_cbc.nsh</code> and <code>flash_both.nsh</code> script files.}} | ||
| Line 251: | Line 263: | ||
Follow the steps below to apply the UEFI script files in production-line programming of the congatec BIOS or cBC firmware. | Follow the steps below to apply the UEFI script files in production-line programming of the congatec BIOS or cBC firmware. | ||
<span style="color: red;">'''Caution:'''</span> | |||
<span style="color: red;">'''''Do not use a dedicated programming station on the production line to update the BIOS or cBC firmware or both. Using dedicated programming station will wear out connectors that mate with the dedicated programming station such as the COM Express connectors due to multiple insertion.</br></br>Once these connectors wear out, the BIOS or cBC firmware or both will get corrupted, thereby requiring the module to be repaired.</br></br>Instead, update the BIOS or cBC firmware or both with the production carrier board that these modules are to be assembled into. Doing this will ensure that a module is inserted only once into each carrier board in the production line. This action eliminates the wear out of connectors.'''''</span> | |||
#Shut down the system containing the carrier board and congatec module. | #Shut down the system containing the carrier board and congatec module. | ||
#Insert bootable UEFI shell USB stick into a USB slot on the carrier board. | #Insert bootable UEFI shell USB stick into a USB slot on the carrier board. | ||
#Power on the system containing the carrier board and congatec module. | #Power on the system containing the carrier board and congatec module. | ||
* The system boots. The display shows that it has booted into UEFI shell. | |||
* A 5-second countdown begins at the bottom of the screen. | |||
* The <code>startup.nsh</code> script executes automatically when countdown reaches 0 second. | |||
* The <code>startup.nsh</code> script clears the screen and displays the following: | |||
<pre> | <pre> | ||
congatec System Configuration Utility --- Version 1.5.9 | congatec System Configuration Utility --- Version 1.5.9 | ||
© Copyright 2005-2021 congatec GmbH | © Copyright 2005-2021 congatec GmbH | ||
Board/BIOS Information Module | |||
System BIOS Version: BIOSNAME | |||
System BIOS Version: | OEM BIOS Version: OEMNAME | ||
OEM BIOS Version: | BC Firmware Version: CGBCPxxx | ||
BC Firmware Version: | |||
Enter choice number below followed by the enter key | Enter choice number below followed by the enter key | ||
1 to update production BIOS | 1 to update production BIOS | ||
2 to update production BC Firmware | 2 to update production BC Firmware | ||
3 to update both the production BIOS and production BC Firmware | 3 to update both the production BIOS and production BC Firmware | ||
FS0:\> | |||
</pre> | </pre> | ||
{{Continue Numbered List|4|Type one of the choice numbers and press Enter. The script executes and at completion, displays an instruction to check if the update is successful and to restart the system. | {{Continue Numbered List|4|Type one of the choice numbers and press Enter.</br>The script executes and at completion, displays an instruction to check if the update is successful and to restart the system. | ||
#Shutdown the system. You can now remove the carrier board and module, and then attach the next carrier board with module. Follow the steps above to update each system. | #Shutdown the system.</br>You can now remove the carrier board and module, and then attach the next carrier board with module. Follow the steps above to update each system.}} | ||
==UEFI Script Files for CGUTIL Lab Usage== | ==UEFI Script Files for CGUTIL Lab Usage== | ||
| Line 281: | Line 300: | ||
With the UEFI script, the user can do the following: | With the UEFI script, the user can do the following: | ||
*Type in any CGUTIL command at the file system prompt <code>FS0:\></code> | |||
*List all BIOS files on the USB stick when using the BIOS update menu. The list also shows the format of the BIOS update command. | |||
*List all cBC firmware files on the USB stick when using the cBC firmware update menu. The list also shows the format of the cBC firmware update command. | |||
*Display all the board information data when the board information menu is selected. | |||
===Prepare the USB Stick for Lab=== | ===Prepare the USB Stick for Lab=== | ||
Follow the steps below to create the bootable USB stick with UEFI script for lab environment. | Follow the steps below to create the bootable USB stick with UEFI script for lab environment. | ||
#Create a bootable UEFI shell USB stick as described in congatec Application Note | '''Note:''' | ||
#Follow steps 1 to 4 of section | |||
#Create the UEFI scripts as described in section | '''''Do not use one UEFI shell USB stick for both the production line scripts and the laboratory scripts. Use a separate UEFI shell USB stick for each environment.''''' | ||
#Create a bootable UEFI shell USB stick as described in congatec Application Note [[How to create a bootable USB stick with a UEFI shell (AN31)]] | |||
#Follow steps 1 to 4 of section [[UEFI Script Files (AN48)#Prepare USB Stick for Production Line|Prepare USB Stick for Production Line]] to add the <code>cgutlcmd.efi</code> file. | |||
#Create the UEFI scripts as described in section [[UEFI Script Files (AN48)#Lab Script Files|Lab Script Files]] below. | |||
#Copy the UEFI scripts to the root directory of the bootable USB stick. | #Copy the UEFI scripts to the root directory of the bootable USB stick. | ||
#Copy the BIOS or the cBC firmware or both to the root directory of the bootable USB stick. You can also copy several BIOS and cBC firmware files of different congatec products to the root directory of the bootable USB stick. This allows you to use the bootable USB stick on different congatec platforms. You must type the full CGUTIL command. This allows you to enter any CGUTIL command any time the file system displays the <code>FS0:\> </code> prompt. You can also enter any UEFI Shell command at either the <code>Shell:> </code> prompt or at the <code>FS0:\></code> prompt | #Copy the BIOS or the cBC firmware or both to the root directory of the bootable USB stick. You can also copy several BIOS and cBC firmware files of different congatec products to the root directory of the bootable USB stick. This allows you to use the bootable USB stick on different congatec platforms. You must type the full CGUTIL command. This allows you to enter any CGUTIL command any time the file system displays the <code>FS0:\></code> prompt. You can also enter any UEFI Shell command at either the <code>Shell:></code> prompt or at the <code>FS0:\></code> prompt | ||
'''Note:''' | |||
'''''Unlike the production-line script files, the lab script files do not update the firmware automatically. Instead, it lists only the files on the USB stick that can be used with the command:''''' | |||
<code>cgutlcmd bflash</code> or <code>cgutlcmd bcprog</code> | |||
'''''It also shows the most used formats of these commands.''''' | '''''It also shows the most used formats of these commands.''''' | ||
===Lab Script Files=== | ===Lab Script Files=== | ||
The startup.nsh script file | The <code>startup.nsh</code> script file starts automatically on power up. It enters the correct file system on the USB stick and displays a menu followed by the file system prompt <code>FS0:\>.</code> | ||
====startup.nsh==== | ====startup.nsh==== | ||
Follow the steps below to create the startup.nsh script. | Follow the steps below to create the <code>startup.nsh</code> script. | ||
#Open Notepad: | #Open Notepad: | ||
#Type the following texts and save the script as startup.nsh file: | #Type the following texts and save the script as <code>startup.nsh</code> file: | ||
<pre> | <pre> | ||
| Line 336: | Line 362: | ||
Follow the steps below to create the script for BIOS update. | Follow the steps below to create the script for BIOS update. | ||
#Open Notepad. | #Open Notepad. | ||
#Type the following texts and save the script as bios.nsh file. | #Type the following texts and save the script as <code>bios.nsh</code> file. | ||
<pre> | <pre> | ||
| Line 366: | Line 392: | ||
#Open Notepad. | #Open Notepad. | ||
#Type the following texts and save the script as | #Type the following texts and save the script as <code>bc.nsh</code> file. | ||
<pre> | <pre> | ||
| Line 394: | Line 420: | ||
#Open Notepad. | #Open Notepad. | ||
#Type the following texts and save the script as bbi.nsh file. | #Type the following texts and save the script as <code>bbi.nsh</code> file. | ||
<pre> | <pre> | ||
| Line 415: | Line 441: | ||
==Sample UEFI Shell Commands == | ==Sample UEFI Shell Commands == | ||
The following section describes some UEFI shell commands. The UEFI shell commands can be used at the UEFI Shell prompt <code>Shell></code> or at the file system prompt <code>FS0:\></code>. Refer to the UEFI Shell Specification for detailed description of all available description of all available commands. | The following section describes some UEFI shell commands. The UEFI shell commands can be used at the UEFI Shell prompt <code>Shell></code> or at the file system prompt <code>FS0:\></code>. Refer to the UEFI Shell Specification for detailed description of all available description of all available commands. The specification can be downloaded at https://uefi.org/specifications | ||
===Help Command=== | ===Help Command=== | ||
will parse and pause on each screen, giving verbose description of the <code>pci</code> command. | * The <code>help -b</code> command lists all the UEFI Shell commands. | ||
* The <code>-b</code> parameter displays the output one screen at a time. | |||
* The <code>-verbose</code> parameter displays the details of each UEFI shell command. It also shows an example of how to use the command. For example, the command <code>help -b -verbose pci</code> will parse and pause on each screen, giving verbose description of the <code>pci</code> command. | |||
===Mode Command=== | ===Mode Command=== | ||
| Line 434: | Line 455: | ||
Typical modes supported by an HD display are: | Typical modes supported by an HD display are: | ||
{| class="wikitable" | |||
|+ | |||
|Col 80 | |||
Col | |Row 25 | ||
|- | |||
|Col 80 | |||
|Row 50 | |||
Col | |- | ||
|Col 100 | |||
|Row 31 | |||
|- | |||
|Col 240 | |||
|Row 56 | |||
|} | |||
For example, to change the display mode to 100 characters per line and 31 lines, use: | For example, to change the display mode to 100 characters per line and 31 lines, use: | ||
<code>mode 100 31</code> | <code>mode 100 31</code> | ||
===Cls Command=== | ===Cls Command=== | ||
The <code>cls</code> command can be used to clear the screen and to change the background color of the display. For more details about the <code>cls</code> command, use: | The <code>cls</code> command can be used to clear the screen and to change the background color of the display. For more details about the <code>cls</code> command, use: | ||
<code>help -b cls</code> | <code>help -b cls</code> | ||
===Set Command=== | ===Set Command=== | ||
With the set command, you can display, create, change or delete a UEFI Shell environment variable. Such variables are often necessary in more complex scripts. Refer to section | With the set command, you can display, create, change or delete a UEFI Shell environment variable. Such variables are often necessary in more complex scripts. Refer to section [[UEFI Script Files (AN48)#Dynamic Detection of Correct File System|Dynamic Detection of Correct File System]] above, for an example of how to use the set command: | ||
<code>set TEMP_PATH fs"%i":\startup. | <code>set TEMP_PATH fs"%i":\startup.nsh</code> | ||
In this example, <code>TEMP_PATH</code> is the variable name and <code>fs"%i":\startup.nsh</code> is the variable value. | In this example, <code>TEMP_PATH</code> is the variable name and <code>fs"%i":\startup.nsh</code> is the variable value. | ||
The general syntax of the set | The general syntax of the set command is: | ||
<code>set vname vvalue</code> | <code>set vname vvalue</code> | ||
where vname is the variable name and vvalue is the new value. | where <code>vname</code> is the variable name and <code>vvalue</code> is the new value. | ||
The <code>command set -d vname</code> can be used to delete a previously created variable. | The <code>command set -d vname</code> can be used to delete a previously created variable. | ||
Use the set command without any parameter to display all environment variables. | Use the <code>set</code> command without any parameter to display all environment variables. | ||
=== Pause Command === | === Pause Command === | ||
The <code>pause</code> command displays the message <code>“Enter 'q' to quit, any other key to continue:”</code>and then suspends the script file execution and waits for keyboard input. When you press any key except <code>q</code> or <code>Q</code>, the execution resumes and continues with the next line after the <code>pause</code> command. If q or Q is pressed, script processing terminates. With <code>-q</code> parameter, the pause command waits for user input without displaying a message | The <code>pause</code> command displays the message <code>“Enter 'q' to quit, any other key to continue:”</code>and then suspends the script file execution and waits for keyboard input. When you press any key except <code>q</code> or <code>Q</code>, the execution resumes and continues with the next line after the <code>pause</code> command. If <code>q</code> or <code>Q</code> is pressed, script processing terminates. | ||
With <code>-q</code> parameter, the pause command waits for user input without displaying a message | |||
=== Stall Command === | === Stall Command === | ||
The <code>stall</code> command can be used to delay the script operation for a specified number of microseconds. To delay the script operation for one second (1000000 microseconds), use the example below: <code>stall 1000000</code> | The <code>stall</code> command can be used to delay the script operation for a specified number of microseconds. | ||
To delay the script operation for one second (1000000 microseconds), use the example below: | |||
<code>stall 1000000</code> | |||
==Conclusion== | ==Conclusion== | ||
Latest revision as of 16:44, 22 November 2024
| Affected Products | All products featuring UEFI |
|---|
Preface
This application note describes how to create a UEFI script file for automating the cBC firmware update and BIOS in a production line environment. It also shows how UEFI script files can be used with the congatec system utility CGUTIL. The scripts are suitable for all UEFI-enabled congatec x86 products.
Terminology
| Term | Description |
|---|---|
| cBC | congatec Board Controller |
| BIOS | Basic Input Output System - Legacy boot firmware. Name still commonly used for UEFI firmware |
| UEFI | Unified Extensible Firmware Interface - New boot firmware |
| COM | Computer on Module |
| CGUTIL | congatec System Utility |
Introduction
A UEFI script is a series of statements that tell an application to perform certain tasks. The script is written as plain text file and saved with .nsh extension. With these scripts, customers can simplify the process of updating the BIOS and cBC firmware on congatec COMs in their production line. Generally, these scripts can run in a built-in UEFI shell or in a bootable USB flash drive compiled with UEFI shell.
The congatec embedded BIOS however does not support the built-in UEFI shell because of security reasons. Having a built-in shell may allow users the possibility to bypass security mechanisms that are contained within the BIOS.
To execute UEFI scripts on congatec COMs, you need to create a bootable USB flash drive with compiled UEFI shell. The procedure to create such a boot USB flash drive is explained in the application note How to create a bootable USB stick with a UEFI shell (AN31). You can download this document from:
Caution:
Ensure that there is no loss of power during the BIOS and cBC firmware update. The loss of power during the flash update will result in a non-bootable product that requires RMA. The cBC firmware update should especially be performed only in a safe production environment.
Note:
There are two BIOS update procedures for the production line described in this document. The first procedure is for normal BIOS updates while the other procedure is for extended BIOS updates.
Unlike normal BIOS updates, the extended update requires a reboot cycle to unlock the flash.
Please refer to section 3 of BIOS Update (AN01) for more details on normal (UEFI firmware only) and extended BIOS update. You can download this document from the link below:
https://www.congatec.com/en/support/application-notes/article/an01-bios-update/
UEFI Script for Production Line
This section describes the UEFI scripts for automating production-line programming of the congatec BIOS or cBC firmware.
The table below describes the function of each UEFI script.
| Script Name | Description |
|---|---|
| startup.nsh | The first script that is automatically executed when UEFI shell launches. This script is a container for other scripts (similar to autoexec.bat on old DOS system) |
| flash_bios.nsh | This script updates the congatec BIOS. Type the number “1” in startup script and press “Enter” to execute this script. |
| eflash_bios.nsh | This script updates the full BIOS flash (UEFI firmware + extended area). Type the number “2” in startup script and press “Enter” to execute this script. |
| flash_cbc.nsh | This script updates the congatec Board Controller (cBC). Type the number “3” in startup script and press “Enter” to execute this script. |
| flash_both.nsh | This script updates both the BIOS and the cBC. Type the number “4” in startup script and press “Enter” to execute this script. |
Note:
Use plain text editor such as Notepad when creating UEFI scripts. If you use a word processor, the scripts may execute with errors due to hidden embedded characters associated with word processors.
Production-Line Script Files
The following are the UEFI script files required for production-line programming of the congatec BIOS or cBC firmware.
startup.nsh
Follow the steps below to create the startup.nsh script.
- Open Notepad.
- Type the following texts below. The comment lines (#) will be ignored during execution.
echo -off # echo -off inhibits the display of the command line. # This prevents the user from seeing the script commands. cls # cls will present a blank screen. FS0: # FS0: Is the file system on the bootable UEFI USB stick where # the files are stored. Make sure to use the correct FSx # nomination, if your files are on a different file system. cgutlcmd cginfo /ot:board /dump /bios /bcfw # The above command line will display the current BIOS and cBC # firmware installed on the module. alias -v 1 "flash_bios" alias -v 2 "flash_cbc" alias -v 3 "flash_both" alias -v 4 "startup" # The alias -v command will temporarily create an alternative # name for the script file that it corresponds to. Because UEFI # script files do not have an input command to read the # keyboard, the aliases 1, 2, 3 correspond to the names of # script files and can be entered at the keyboard and executed # as commands, to get around this UEFI limitation. # as commands, to get around this UEFI limitation. echo " " echo "Enter choice number below followed by the enter key" echo "1 for a normal BIOS update" echo "2 for an extended BIOS update" echo "3 to update the cBC firmware" echo "4 to update the BIOS and the cBC firmware" # The above echo commands are sent to the display # The above echo commands are sent to the display to offer the # user a menu. echo -on # Turning echo -on will force the script to wait for input and # prevents a blinking display. # The standard inputs are 1, 2 or 3. # However, any UEFI command or .efi executable can be called as # well.
- Save the script as
startup.nshfile.
flash_bios.nsh
Follow the steps below to create the script for updating the congatec BIOS (UEFI firmware only).
- Open Notepad.
- Type the following texts:
echo -off cls cgutlcmd bflash SA50R061.BIN # This command line is used to update the BIOS with the file # SA50R061.BIN. To flash a different BIOS file, simply replace # SA50R061.BIN with its name. echo " " echo "If the BIOS was updated successfully, reset or repower the system." echo "Then verify on the main setup menu that the BIOS name shown is correct." echo " " echo "Press 5 followed by the enter key to return to the main menu" # displays instructions to the user after the BIOS has been # updated. echo -on
- Save the script as
flash_bios.nshfile.
eflash_bios.nsh
Follow the steps below to create the script for extended BIOS update.
- Open Notepad.
- Type the following texts:
echo -off cls cgutlcmd bflash /eil # The above command checks the status of the extended BIOS flash lock # and returns 0x00 if the flash is still locked. # and returns 0x00 if the flash is still locked. if %lasterror% eq 0x0 then echo "Extended flash is locked" cgutlcmd bflash /eu # The command to unlock the extended flash. The system will reboot # automatically after completion. endif echo "Extended flash is unlocked" cgutlcmd bflash SA50R061.BIN /e # With the /e parameter, cgutlcmd will perform an extended BIOS # update and automatically reboot the system after completion. echo -on
- Save the script as
eflash_bios.nshfile.
flash_cbc.nsh
Follow the steps below to create the script for updating the congatec cBC firmware.
- Open Notepad.
- Type the following texts:
echo -off cls cgutlcmd bcprog CGBCP440.DAT #command to update cBC firmware. # To flash a different cBC firmware file, simply replace # CGBCP440.DAT with its name. echo " " echo "If the cBC firmware was updated successfully, turn the power off and then back on (G3 cycle)." echo "Then verify on the main setup menu that the cBC firmware shown is correct." echo " " echo "Press 5 followed by the enter key to return to the main menu." # displays instructions to the user after the cBC firmware has # been updated. echo -on
- Save the script as
flash_cbc.nshfile.
flash_both-nsh
Follow the steps below to create the script for updating both congatec BIOS and the cBC firmware.
- Open Notepad.
- Type the following texts:
echo -off cls cgutlcmd bcprog CGBCP440.DAT # command to update cBC firmware cgutlcmd bflash SA50R061.BIN # command to update BIOS echo " " echo "If the BIOS and cBC firmware were updated successfully, turn the power off and then back on (G3 cycle)." echo "Then verify on the main setup menu that the BIOS name and cBC firmware shown are correct." echo " " echo "Press 5 followed by the enter key to return to the main menu" # displays instructions to the user after the BIOS and cBC FW # have been updated. echo -on
- Save the script as
flash_both.nshfile.
Dynamic Detection of Correct File System
If storage devices with file systems on it are connected to or disconnected from the system, the file system with the EFI shell might change. The script code below can be used instead of the fix FS0: command to dynamically detect the EFI Shell file system number:
for %i run (0 9)
set TEMP_PATH fs"%i":\startup.nsh
if exist %TEMP_PATH% then
fs"%i":
endif
endfor
Prepare USB Stick for Production Line
Follow this procedure to add the required files to the bootable USB stick:
- Create a bootable USB stick with compiled UEFI shell as described in congatec Application Note How to create a bootable USB stick with a UEFI shell (AN31)
- Download
cgutil_V159.zipfrom congatec at https://www.congatec.com
- To download this file, click the "Products" menu on congatec website and select any of the x86 modules.
- Click on the software tab and navigate to Windows 10 section
- Locate the
cgutil_V159.zipfile and download it.
- Unzip the
cgutil_V159.zipfile. - Copy the
cgutlcmd.efifile from cgutil/uefi/X64 directory to the root directory of the UEFI Shell USB stick. - Copy also the previously created script files
startup.nsh,flash_bios.nsh,flash_cbc.nshandflash_both.nshto the root directory of the UEFI Shell USB stick. - Copy the BIOS file you want to update to the root directory of the UEFI Shell USB stick. You can have several BIOS files on the USB stick. However, the UEFI script will update only the BIOS file that is indicated with the
cgutlcmd bflash biosfile.bincommand in theflash_bios.nshandflash_both.nshscript files. - Copy the cBC Firmware file you want to update to the root directory of the UEFI Shell USB stick. You can have several cBC firmware files on the USB stick. However, the UEFI script will update only the cBC firmware that is indicated with the
cgutlcmd bcprog cgbcpxxx.datcommand in theflash_cbc.nshandflash_both.nshscript files.
How to Use the Script Files
Follow the steps below to apply the UEFI script files in production-line programming of the congatec BIOS or cBC firmware.
Caution:
Do not use a dedicated programming station on the production line to update the BIOS or cBC firmware or both. Using dedicated programming station will wear out connectors that mate with the dedicated programming station such as the COM Express connectors due to multiple insertion.
Once these connectors wear out, the BIOS or cBC firmware or both will get corrupted, thereby requiring the module to be repaired.
Instead, update the BIOS or cBC firmware or both with the production carrier board that these modules are to be assembled into. Doing this will ensure that a module is inserted only once into each carrier board in the production line. This action eliminates the wear out of connectors.
- Shut down the system containing the carrier board and congatec module.
- Insert bootable UEFI shell USB stick into a USB slot on the carrier board.
- Power on the system containing the carrier board and congatec module.
- The system boots. The display shows that it has booted into UEFI shell.
- A 5-second countdown begins at the bottom of the screen.
- The
startup.nshscript executes automatically when countdown reaches 0 second. - The
startup.nshscript clears the screen and displays the following:
congatec System Configuration Utility --- Version 1.5.9 © Copyright 2005-2021 congatec GmbH Board/BIOS Information Module System BIOS Version: BIOSNAME OEM BIOS Version: OEMNAME BC Firmware Version: CGBCPxxx Enter choice number below followed by the enter key 1 to update production BIOS 2 to update production BC Firmware 3 to update both the production BIOS and production BC Firmware FS0:\>
- Type one of the choice numbers and press Enter.
The script executes and at completion, displays an instruction to check if the update is successful and to restart the system. - Shutdown the system.
You can now remove the carrier board and module, and then attach the next carrier board with module. Follow the steps above to update each system.
UEFI Script Files for CGUTIL Lab Usage
In the laboratory, the UEFI script helps simplify the process of testing and verification. On one UEFI shell USB stick, the engineer can save various BIOS and cBC firmware versions for different congatec products. This allows the UEFI shell USB stick to be used on different congatec platforms.
With the UEFI script, the user can do the following:
- Type in any CGUTIL command at the file system prompt
FS0:\> - List all BIOS files on the USB stick when using the BIOS update menu. The list also shows the format of the BIOS update command.
- List all cBC firmware files on the USB stick when using the cBC firmware update menu. The list also shows the format of the cBC firmware update command.
- Display all the board information data when the board information menu is selected.
Prepare the USB Stick for Lab
Follow the steps below to create the bootable USB stick with UEFI script for lab environment.
Note:
Do not use one UEFI shell USB stick for both the production line scripts and the laboratory scripts. Use a separate UEFI shell USB stick for each environment.
- Create a bootable UEFI shell USB stick as described in congatec Application Note How to create a bootable USB stick with a UEFI shell (AN31)
- Follow steps 1 to 4 of section Prepare USB Stick for Production Line to add the
cgutlcmd.efifile. - Create the UEFI scripts as described in section Lab Script Files below.
- Copy the UEFI scripts to the root directory of the bootable USB stick.
- Copy the BIOS or the cBC firmware or both to the root directory of the bootable USB stick. You can also copy several BIOS and cBC firmware files of different congatec products to the root directory of the bootable USB stick. This allows you to use the bootable USB stick on different congatec platforms. You must type the full CGUTIL command. This allows you to enter any CGUTIL command any time the file system displays the
FS0:\>prompt. You can also enter any UEFI Shell command at either theShell:>prompt or at theFS0:\>prompt
Note:
Unlike the production-line script files, the lab script files do not update the firmware automatically. Instead, it lists only the files on the USB stick that can be used with the command:
cgutlcmd bflash or cgutlcmd bcprog
It also shows the most used formats of these commands.
Lab Script Files
The startup.nsh script file starts automatically on power up. It enters the correct file system on the USB stick and displays a menu followed by the file system prompt FS0:\>.
startup.nsh
Follow the steps below to create the startup.nsh script.
- Open Notepad:
- Type the following texts and save the script as
startup.nshfile:
echo -off cls FS0: # FS0: directs the UEFI shell to the file system on the bootable # UEFI Shell USB stick alias -v 1 "bios" alias -v 2 "cbc" alias -v 3 "bbi" # alias -v commands assign a temporary name (1, 2 or 3) to the # other script files so that 1, 2 or 3 can be used as a menu # selection echo " " echo "Press number from menu below, followed by the enter key" echo "or enter any cgutil command" echo " " echo "1 to update BIOS" echo "2 to update cBC Firmware" echo "3 to list board and BIOS information" # the above echo commands are used to display the menu echo -on
bios.nsh
Follow the steps below to create the script for BIOS update.
- Open Notepad.
- Type the following texts and save the script as
bios.nshfile.
echo -off cls ls *.bin # lists all files in the directory that have the extension .bin # (BIOS files) echo " " echo "BIOS update command format is:" echo "cgutlcmd bflash filename.bin normal BIOS Update" echo "cgutlcmd bflash filename.bin /e extended BIOS Update" # Displays the cgutil format for updating the BIOS # Reference to AN1 echo " " echo "Enter the BIOS Update Command in the format shown above,” echo "or press a number from menu below, followed by the enter key" echo " " echo "1 to update BIOS" echo "2 to update cBC firmware" echo "3 to list board and BIOS information" # displays the menu and allows the user to enter any cgutil # command, including the BIOS update command shown above echo -on
cbc.nsh
Follow the steps below to create the script for cBC firmware update.
- Open Notepad.
- Type the following texts and save the script as
bc.nshfile.
echo -off cls ls *.dat # lists all files in the directory that have the extension .dat # (cBC firmware files) echo " " echo "cBC update command format is:" echo "cgutlcmd bcprog filename.dat" # displays the cgutil format for updating the cBC firmware echo " " echo "Enter the cBC update command in the format shown above,” echo "or press a number from menu below, followed by the enter key" echo " " echo "1 to update BIOS" echo "2 to update cBC firmware" echo "3 to list board and BIOS information" # displays the menu and allows the user to enter any cgutil # command,including the cBC firmware update command shown above echo -on
bbi.nsh
Follow the steps below to create the script that displays the board and firmware information.
- Open Notepad.
- Type the following texts and save the script as
bbi.nshfile.
echo -off cls cgutlcmd cginfo /ot:board /dump /bios /bcfw /cgos /manu /bcnt /rtim # displays the board information including the System and OEM # BIOS versions, cBC firmware version, CGOS driver version, # manufacturing data, boot counter and running time meter echo " " echo "Press number from menu below, followed by the enter key" echo "or enter any cgutil command" echo " " echo "1 to update BIOS" echo "2 to update BC Firmware" echo "3 to list board and BIOS information" # displays the menu and allows the user to enter any cgutil command echo -on
Sample UEFI Shell Commands
The following section describes some UEFI shell commands. The UEFI shell commands can be used at the UEFI Shell prompt Shell> or at the file system prompt FS0:\>. Refer to the UEFI Shell Specification for detailed description of all available description of all available commands. The specification can be downloaded at https://uefi.org/specifications
Help Command
- The
help -bcommand lists all the UEFI Shell commands. - The
-bparameter displays the output one screen at a time. - The
-verboseparameter displays the details of each UEFI shell command. It also shows an example of how to use the command. For example, the commandhelp -b -verbose pciwill parse and pause on each screen, giving verbose description of thepcicommand.
Mode Command
The mode command can change the number of characters per line and the number of lines that can be displayed. You can check the assigned mode for your display by typing the command:
mode
Typical modes supported by an HD display are:
| Col 80 | Row 25 |
| Col 80 | Row 50 |
| Col 100 | Row 31 |
| Col 240 | Row 56 |
For example, to change the display mode to 100 characters per line and 31 lines, use:
mode 100 31
Cls Command
The cls command can be used to clear the screen and to change the background color of the display. For more details about the cls command, use:
help -b cls
Set Command
With the set command, you can display, create, change or delete a UEFI Shell environment variable. Such variables are often necessary in more complex scripts. Refer to section Dynamic Detection of Correct File System above, for an example of how to use the set command:
set TEMP_PATH fs"%i":\startup.nsh
In this example, TEMP_PATH is the variable name and fs"%i":\startup.nsh is the variable value.
The general syntax of the set command is:
set vname vvalue
where vname is the variable name and vvalue is the new value.
The command set -d vname can be used to delete a previously created variable.
Use the set command without any parameter to display all environment variables.
Pause Command
The pause command displays the message “Enter 'q' to quit, any other key to continue:”and then suspends the script file execution and waits for keyboard input. When you press any key except q or Q, the execution resumes and continues with the next line after the pause command. If q or Q is pressed, script processing terminates.
With -q parameter, the pause command waits for user input without displaying a message
Stall Command
The stall command can be used to delay the script operation for a specified number of microseconds.
To delay the script operation for one second (1000000 microseconds), use the example below:
stall 1000000
Conclusion
The UEFI scripts help simplify the process of updating the BIOS and cBC firmware both in production line and in the lab.