Posts by fs-support_KF

    The first step when optimizing boot time is to accurately measure it. Both u-boot and EDK II provide tools to achive this.


    Note: These steps were performed on an armstoneMX8MP running F&S u-boot 2020.04-fsimx8mp-Y2023.03, F&S UEFI based on NXPs i.MX Windows 10 IoT v1.5.0 release

    Measuring boot time in U-Boot

    A simple way to measure boot time in U-Boot is by using BOOTSTAGE mechanism.

    To enable it, U-Boot needs to be built with BOOTSTAGE enabled.


    When building enable these options:

    Code: .config
    1. BOOTSTAGE=y
    2. BOOTSTAGE_REPORT=y
    3. CMD_BOOTSTAGE=y
    4. # To get BOOTSTAGE information from SPL and TPL:
    5. BOOTSTAGE_STASH=y
    6. SPL_BOOTSTAGE=y
    7. TPL_BOOTSTAGE=y
    8. # pick a free memory address, where BOOTSTAGE_STASH can be placed:
    9. BOOTSTAGE_STASH_ADDR=0x65500000

    Flash BOOSTAGE-enabled u-boot to the board and reboot/reset.


    To see the BOOSTAGE-report enter u-boot command prompt. Type

    bootstage report and hit enter.


    You should be presented with a report like this one:

    Tip: utilise fakegocmd to automatically output the bootstage report

    1. In the u-boot prompt enter editenv fakegocmd
    2. add ; bootstage report to the end of the line
    3. hit enter to apply
    4. enter saveenv to save your changes

    For further information refer to the U-Boot TRACE documentation.


    Measuring boot time in EDK II/UEFI

    EDK II provides some mechanisms to measure and read out boot time


    To enable Performance Recording, add or change theses PCDs in the .dsc file of your platform:

    Code: armstoneMX8MP.dsc
    1. gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x01
    2. gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|0x01
    3. #Enable DpApp to visualize UEFI Performance
    4. ShellPkg/DynamicCommand/DpDynamicCommand/DpApp.inf
    5. #Enable ReportStatusCodeRouterRuntimeDxe & FirmwarePerformanceDxe for UEFI Performance reporting
    6. MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf
    7. MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.inf

    DpApp, ReportStatusCodeRouterRuntimeDxe and FirmwarePerformanceDxe also need to be included in your platforms .fdf file.

    Code: armstoneMX8MP.fdf
    1. #Enable ReportStatusCodeRouterRuntimeDxe & FirmwarePerformanceDxe for UEFI Performance reporting
    2. INF MdeModulePkg/Universal/ReportStatusCodeRouter/RuntimeDxe/ReportStatusCodeRouterRuntimeDxe.inf
    3. INF MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.inf
    4. # DP shell command Support
    5. #Enable DpApp to visualize UEFI Performance
    6. INF ShellPkg/DynamicCommand/DpDynamicCommand/DpApp.inf

    Rebuild and flash EDK II to your board.


    The simplest way to view the Performance Record is to boot into UEFI-Shell and entering the command dp to get a report like this one:

    For more information refer to the official EDK II "Performance Infrastructure" wiki entry.

    How to debug SBC/SoM using WinDbg

    This guide assumes you already have WinDbg installed. For instructions on how to install windbg see: https://learn.microsoft.com/en…ardware/drivers/debugger/

    Connecting to the SBC/SoM via Serial

    1) Locate the correct serial-port

    Boot messages are usually output on COM1:. COM1: is normally assigned to Serial_A.

    Connect a ttl-serial cable to the serial port.

    2) Verify the Debug Serial Port

    On your computer use a serial terminal application like Tera Term to connect to the serial port on the computer side.

    Use these settings to set up the serial connection:

    • 115200Baud
    • 8 Data bits
    • no parity bit
    • 1 stop bit

    Or in short: 115200 8n1

    The COM1: will output boot messages, which will show up in Tera Term if configured correctly. Apply power to the board and observe the serial output.

    Uboot should output boot messages starting with a line similar to the following:

    Code
    1. U-Boot SPL 2020.04-00327-g5c97678d5-dirty (Aug 24 2023 - 11:37:21 +0200)

    After a while the Windows 10 IoT kernel should attempt to initiate a debugging session by sending cryptic text via serial:


    If you see these messages (or similar ones) you have successfully located the serial debug port.

    Setting up WinDbg

    1) Enable debug messages

    Connect to your SBC/SoM via RemoteDesktop. Open regedit by right clicking on the "Start" button and selecting "Run" from the menu. Enter regedit and click on OK.

    Navigate to (you can paste this into the address bar of regedit:

    Code
    1. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager


    Right click on the right window pane and select "New -> Key"


    Name the Key Debug Print Filter.



    Open the key and create a "New -> DWORD (32-bit) Value". Name it DEFAULT and set "Base" to Hexadecimal and "Value data" to f.


    Shut down and power off the SBC/SoM.


    For additional information refer to the blog entry "Where Are My DbgPrints?" from OSR


    2) Prepare WinDbg

    Open WinDbg. Select File -> Kernel Debug. Select COM and enter the Baud Rate 115200.

    Do not click OK yet.


    3) Connecting WinDbg
    To connect WinDbg to to board successfully,

    correct timing is essential

    . Connecting too early when U-Boot is still running will interrupt the boot process. If this happens power cycle the SBC/SoM.

    When connecting too late, Windows IoT KD will not answer. In this case shut down the SBC/SoM via RemoteDesktop.


    Connect a display to your SBC/SoM.


    Power on the SBC/SoM and wait for the Windows logo to appear:


    Now click on OK in the WinDbg window.

    WinDbg should now connect successfully.

    How to automatically deploy drivers for Debugging

    To facilitate Driver development for for your F&S Single Board Computer (SBC) / System on Module (SoM) running Windows 10 IoT, fast deployment is essential. When using VisualStudio 2019 for driver development, the official Guide for Provisioning a target computer recommends using WDK Test Target Setup (WDK-TTS).
    This guide provides a workaround if WDK-TTS does not run on your SBC or SOM.


    From here on the guide will refer to the SBC or SOM that drivers are developed for as 'board'.


    Creating a shared folder on the board

    If you have not already, follow the steps outlined in "Configuration of SBC/SoM" in our "Deploying & Debugging Visual Studio applications over Ethernet"-Guide


    After following the steps from above, you should have a folder accessible via network on your board. This guide uses \\DESKTOP-1234567\debug located at C:\debug as an example.


    Setting up the board

    1) Download Microsoft's "devcon"-tool

    Download Devcon.exe directly from Microsoft. See https://learn.microsoft.com/en…re/drivers/devtest/devcon for instructions.
    Copy devcon.exe to your shared folder.


    2) Download auto-driver-installer.zip
    Download auto-driver-installer.zip from here: auto-driver-installer-V1.zip. Extract its contents and place them in the shared folder.


    Your shared folder should now contain

    • devcon.exe
    • auto-driver-reinstaller.ps1
    • run-auto-driver-installer.lnk


    3) Configure auto-driver-reinstaller.ps1 for your driver

    Open auto-driver-reinstaller.ps1 in an editor and find these lines:

    Code: auto-driver-reinstaller.ps1
    1. # USER: Adjust these parameters to fit your Driver!
    2. $drivername = "KFKMDFHelloWorldDriver.inf"
    3. $driverpath = "Root\KFKMDFHelloWorldDriver"
    4. $watchpath = "C:\debug"
    • $watchpath is the path of your shared folder, where your driver-files will be copied to
    • $drivername is the name of the .inf-file of your driver
    • and $driverpath is the HardwareID of the device your driver is targeting. See HardwareID on learn.microsoft.com

    Edit these Lines to fit your driver and shared folder path.

    4) Edit run-auto-driver-installer.lnk

    Right click on the run-auto-driver-installer.lnk-file and ensure it points to auto-driver-reinstaller.ps1. Also check that the working directory is set to the shared folder.

    Refer to this image for an example.


    Enabling deployment from Visual Studio

    1) Configure VisualStudio to copy driver files to your board

    In VisualStudio select your Project in "Solution Explorer".

    Right click, then select "Properties". Navigate to "Configuration Properties" -> "Build Events" -> "Post-Build Event".


    Change Command Line to: xcopy /y "$(PackageDir)" "\\DESKTOP-1234567\debug"
    Confirm by clicking on "OK".


    If no/incorrect driver files are copied try changing the command above to: xcopy /y "$(OutDir)" "\\DESKTOP-1234567\debug"

    This will cause VisualStudio to execute the xcopy command at the end of each build.

    Note: this is only run when a build is executed. Using the "Deploy Project" options provided by VisualStudio is independent of this and will not work.

    2) (Optional) Disable deployment build step

    In VisualStudio select your Solution in "Solution Explorer". Right click, then select "Properties".

    Select "Configuration Properties", then in the "Project"-Pane find your Project.

    Click on the checkbox in the "Deploy" column to remove the checkmark.




    This disables VisualStudios builtin deployment which would require a working "WDK Test Target Setup".

    3) Verify that the files are actually copied to the board

    In VisualStudio click on "Build Solution" to build and copy your driver. The output windows will show a line at the end saying: "3 file(s) copied."

    Check if your shared folder contains the driver files. Look for .sys, .cat and .inf files:


    4) Run auto-driver-reinstaller.ps1 on your board

    Connect to your board via Remote Desktop. Open file explorer, navigate to your shared folder and double click run-auto-driver-installer.lnk.

    Confirm the administrator prompt.

    A Powershell window will open.

    Wait a few seconds for some text to appear inside the powershell window.

    You can now Select Build from VisualStudio and the powershell script will detect that the driver files were changed. It will then reinstall your driver.

    With these steps completed you should now be able to develop your drivers more efficiently. Well Done:thumbsup: