WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Timing Boot Using Serial Cable and Powershell  (Read 290 times)

Offline sodface

  • Jr. Member
  • **
  • Posts: 82
Timing Boot Using Serial Cable and Powershell
« on: February 25, 2018, 07:34:34 PM »
I wanted a repeatable and hopefully fairly accurate method for timing the boot process from power on to some arbitrary point, like the login prompt being displayed.  Using a Pi A+, an Adafruit  USB Serial Cable and Windows Powershell seems to be working pretty well.  I have the Pi being powered from the 5v pin of the cable.  The first few lines of the powershell script register an event to detect the insertion of the USB cable and the script just waits until that event happens.  So I start the script with the cable unplugged and then plug it in, which sends 5v power to the Pi to power it up and triggers the event to start the stopwatch.  Then the script opens the serial port associated with the USB cable and loops through reading lines until it seems a line with whatever string you are looking for, below I have it set to "login".  Once it matches the string it displays the elapsed time and cleans up.

I started with just a fat partition, copied the piCore 9.0.3 fat partition contents to it and also the mydata.gz from the ext partition (into the root of the fat partition) - so no extensions at all, just a basic boot and default mydata restore.

Power on to login prompt is 10 seconds.

Code: [Select]
Register-WMIEvent -Query "SELECT * FROM Win32_DeviceChangeEvent WHERE EventType = 2"
Clear-Host
Wait-Event
$sw = [Diagnostics.Stopwatch]::StartNew()
Write-Host "Stopwatch Started at" (Get-Date -Format HH:mm.ss)
$port= new-Object System.IO.Ports.SerialPort COM3,115200,None,8,one
$port.open()
do
{
    $test = $port.ReadLine()
} until ($test.Contains("login"))
$sw.Stop()
Write-Host "Stopwatch Stopped at" (Get-Date -Format HH:mm.ss)
Write-Host $sw.Elapsed.Seconds "Seconds from power on to login prompt."
$port.close()
Unregister-Event *
Remove-Event *