summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--env.bash2
-rw-r--r--env.csh2
-rwxr-xr-xsrc/build/tools/cpfiles.pl245
-rwxr-xr-xsrc/build/tools/exthbdump.pl330
-rwxr-xr-xsrc/build/trace/traceHB.py72
5 files changed, 643 insertions, 8 deletions
diff --git a/env.bash b/env.bash
index c5c2c43e3..d3ce5817e 100644
--- a/env.bash
+++ b/env.bash
@@ -4,4 +4,4 @@ if [ -e /esw/fakeroot/ ]; then
export MCP_PATH=/esw/fakeroot
fi
-export PATH=${PATH}:${MCP_PATH}/opt/mcp/bin:${MCP_PATH}/usr/bin:`pwd`/src/build/lids:`pwd`/src/build/trace
+export PATH=${PATH}:${MCP_PATH}/opt/mcp/bin:${MCP_PATH}/usr/bin:`pwd`/src/build/lids:`pwd`/src/build/trace:`pwd`/src/build/tools
diff --git a/env.csh b/env.csh
index 827f52812..99fcb8857 100644
--- a/env.csh
+++ b/env.csh
@@ -4,4 +4,4 @@ if (-e /esw/fakeroot/) then
endif
-setenv PATH ${PATH}:${MCP_PATH}/opt/mcp/bin:${MCP_PATH}/usr/bin:`pwd`/src/build/lids:`pwd`/src/build/trace
+setenv PATH ${PATH}:${MCP_PATH}/opt/mcp/bin:${MCP_PATH}/usr/bin:`pwd`/src/build/lids:`pwd`/src/build/trace:`pwd`/src/build/tools
diff --git a/src/build/tools/cpfiles.pl b/src/build/tools/cpfiles.pl
new file mode 100755
index 000000000..da313c2b9
--- /dev/null
+++ b/src/build/tools/cpfiles.pl
@@ -0,0 +1,245 @@
+#!/usr/bin/perl
+
+#
+# Purpose: This perl script needs to be executed from the
+# git repository. It will copy all relevant files, including
+# scripts, hbotStringFile, .list, .syms and .bin files needed for debug
+# to the user specified directory.
+#
+# Author: CamVan Nguyen 07/07/2011
+#
+
+#
+# Usage:
+# cpFiles.pl <path>
+
+
+#------------------------------------------------------------------------------
+# Specify perl modules to use
+#------------------------------------------------------------------------------
+use strict;
+use warnings;
+use Cwd;
+use File::Basename;
+use File::Spec;
+
+#------------------------------------------------------------------------------
+# Forward Declaration
+#------------------------------------------------------------------------------
+sub printUsage;
+
+#------------------------------------------------------------------------------
+# Global arrays
+#------------------------------------------------------------------------------
+
+#List of files to copy. Path is relative to git repository.
+my @files = ("src/build/tools/exthbdump.pl",
+ "src/build/trace/traceHB.py",
+ "img/hbotStringFile",
+ "img/hbicore.syms",
+ "img/hbicore_test.syms",
+ "img/hbicore.bin",
+ "img/hbicore_test.bin",
+ "img/hbicore.list",
+ "img/hbicore_test.list");
+
+#Directories in base git repository
+my @gitRepoDirs = ("img",
+ "obj",
+ "src");
+
+
+#==============================================================================
+# MAIN
+#==============================================================================
+
+#------------------------------------------------------------------------------
+# Parse optional input argument
+#------------------------------------------------------------------------------
+my $numArgs = $#ARGV + 1;
+#print "num args = $numArgs\n";
+
+my $test = 0; #Flag to overwrite hbicore.<syms|bin|list> with the test versions
+my $inDir = ""; #User specified directory to copy files to
+
+if ($numArgs > 2)
+{
+ #Print command line help
+ print ("ERROR: Too many arguments entered.\n");
+ printUsage();
+ exit (1);
+}
+else
+{
+ foreach (@ARGV)
+ {
+ if ($_ eq "-help")
+ {
+ #Print command line help
+ printUsage();
+ exit (0);
+ }
+ elsif ($_ eq "-test")
+ {
+ #Set flag to copy hbicore_test.<syms|bin> to hbcore_test.<syms|bin>
+ $test = 1;
+ }
+ else
+ {
+ #Save user specified directory
+ $inDir = $_;
+ }
+ }
+}
+
+#------------------------------------------------------------------------------
+# Initialize the paths to copy files to
+#------------------------------------------------------------------------------
+my $simicsDir = "";
+my $imgDir = "";
+
+my $sandbox = $ENV{'SANDBOXBASE'};
+
+if ($inDir ne "")
+{
+ $simicsDir = $inDir;
+ $imgDir = $inDir;
+ print "input dir = $inDir\n";
+
+ #If simics directory specified
+ if (basename($inDir) eq "simics")
+ {
+ #Check if img dir exists else will copy .bin files to simics dir
+ $imgDir = File::Spec->catdir($inDir, "../img");
+ unless (-d ($inDir."/../img"))
+ {
+ $imgDir = $inDir;
+ print "No img directory found in sandbox. Copying .bin files";
+ print " to simics directory\n";
+ }
+ }
+}
+elsif (defined ($sandbox))
+{
+ unless ($sandbox ne "")
+ {
+ die ('ERROR: No path specified and env $SANBOXBASE = NULL'."\n");
+ }
+
+ print "sandbox = $sandbox\n";
+
+ #Check if simics and img dirs exist, else exit
+ $simicsDir = File::Spec->catdir($sandbox, "simics");
+ $imgDir = File::Spec->catdir($sandbox, "img");
+ print "simics dir = $simicsDir\n img dir = $imgDir\n";
+
+ unless ((-d $simicsDir) && (-d $imgDir))
+ {
+ die ("ERROR: simics and/or img directories not found in sandbox\n");
+ }
+}
+else
+{
+ print 'ERROR: No path specified and env $SANDBBOXBASE not set.'."\n";
+ printUsage();
+ exit(1);
+}
+
+#------------------------------------------------------------------------------
+# Get the base dir of the git repository
+#------------------------------------------------------------------------------
+my $cwd = getcwd();
+my @paths = File::Spec->splitdir($cwd);
+#print "@paths\n";
+
+my @list;
+my $data;
+foreach $data (@paths)
+{
+ last if grep { $_ eq $data } @gitRepoDirs;
+ push @list, $data;
+}
+#print "@list\n";
+
+my $gitRepo = File::Spec->catdir(@list);
+#print "$gitRepo\n";
+
+#------------------------------------------------------------------------------
+# Copy files to user specified directory or to sandbox
+# Use unix command vs perl's File::Copy to preserve file attributes
+#------------------------------------------------------------------------------
+my $command = "";
+my $copyDir = "";
+
+chdir $gitRepo;
+#print "cwd: ", getcwd()."\n";
+
+foreach (@files)
+{
+ $command = "";
+
+ my($filename, $directories, $suffix) = fileparse($_, qr{\..*});
+ #print "$filename, $directories, $suffix\n";
+
+ #Copy .bin to the img dir
+ if ($suffix eq ".bin")
+ {
+ $copyDir = $imgDir;
+ }
+ else
+ {
+ $copyDir = $simicsDir;
+ }
+
+ #Check if user wants to copy test versions to hbicore.<syms|bin|list>
+ if ($test == 1)
+ {
+ #Copy test versions to hbicore.<syms|bin|list>
+ if ($filename eq "hbicore_test")
+ {
+ $command = sprintf("cp %s %s", $_, $copyDir."/hbicore".$suffix);
+ }
+ elsif ($filename ne "hbicore")
+ {
+ $command = sprintf("cp %s %s", $_, $copyDir);
+ }
+ }
+ else
+ {
+ $command = sprintf("cp %s %s", $_, $copyDir);
+ }
+
+ # Copy the file
+ if ($command ne "")
+ {
+ print "$command\n";
+ `$command`;
+ }
+}
+
+chdir $cwd;
+#print "cwd: ", getcwd()."\n";
+
+
+#==============================================================================
+# SUBROUTINES
+#==============================================================================
+
+#------------------------------------------------------------------------------
+# Print command line help
+#------------------------------------------------------------------------------
+sub printUsage()
+{
+ print ("\nUsage: cpFiles.pl [-help] | [<path>] [-test]\n\n");
+ print (" This program needs to be executed from the git repository.\n");
+ print (" It will copy all relevant files, scripts, hbotStringFile,\n");
+ print (" .list, .syms and .bin files needed for debug to one of two\n");
+ print (" locations:\n");
+ print (" 1. <path> if one is specified by the user\n");
+ print (" 2. if <path> is not specified, then the files will be\n");
+ print (' copied to the path specified by env variable $SANDBOXBASE'."\n");
+ print (" if it is defined.\n\n");
+ print (" -help: prints usage information\n");
+ print (" -test: Copy hbicore_test.<syms|bin|list> to hbicore.<syms|bin|list>\n");
+}
+
diff --git a/src/build/tools/exthbdump.pl b/src/build/tools/exthbdump.pl
new file mode 100755
index 000000000..ef0ae0864
--- /dev/null
+++ b/src/build/tools/exthbdump.pl
@@ -0,0 +1,330 @@
+#!/usr/bin/perl
+
+#
+# Purpose: This perl script will parse a hostboot dump file and extract
+# the code version, kernel printk buffer and components traces.
+#
+# Author: CamVan Nguyen
+# Last Updated: 07/06/2011
+#
+
+#
+# Usage:
+# exthbdump.pl <path/hbDumpFile> <path/symsFile>
+
+
+#------------------------------------------------------------------------------
+# Specify perl modules to use
+#------------------------------------------------------------------------------
+use strict;
+use warnings;
+use Cwd;
+use File::Basename;
+use File::Copy;
+
+#------------------------------------------------------------------------------
+# Constants
+#------------------------------------------------------------------------------
+use constant SIZE_HBI_IMAGE_ID => 19;
+use constant MAX_NUM_TRACE_BUFFERS => 24;
+use constant DESC_ARRAY_ENTRY_SIZE => 24;
+use constant DESC_ARRAY_ENTRY_ADDR_SIZE => 8;
+use constant DESC_ARRAY_ENTRY_COMP_NAME_SIZE => 16;
+use constant MAX_NUM_TRACE_BUFFERs => 24;
+use constant TRAC_DEFAULT_BUFFER_SIZE => 0x0800;
+
+
+#------------------------------------------------------------------------------
+# Forward Declaration
+#------------------------------------------------------------------------------
+sub getAddrNSize;
+sub readBinFile;
+sub readStringBinFile;
+sub writeBinFile;
+sub appendBinFile;
+
+
+#==============================================================================
+# MAIN
+#==============================================================================
+
+
+#------------------------------------------------------------------------------
+# Print Command Line Help
+#------------------------------------------------------------------------------
+my $numArgs = $#ARGV + 1;
+if ($numArgs < 1)
+{
+ print ("\nUsage: exthbdump.pl <dumpfile> [<symsfile>]\n\n");
+ print (" This program will parse the hostboot dump file specified\n");
+ print (" and extract the code version, kernel printk buffer and traces\n");
+ print (" to the current directory.\n");
+ print (" If no symsfile is specified, this program will use the default\n");
+ print (" hbicore.syms file found in the current working directory.\n");
+ print ("\nNOTE: User should run cpfiles.pl from the git repository to\n");
+ print (" copy all files needed to parse the hostboot dump to the current\n");
+ print (" directory prior to running this program.\n");
+ exit(1);
+}
+
+#------------------------------------------------------------------------------
+# Parse the input argument(s)
+#------------------------------------------------------------------------------
+
+# Save the user specifed dump file
+my $hbDumpFile = $ARGV[0];
+my $hbDumpFileBase = basename($hbDumpFile);
+
+my $hbSymsFile = "hbicore.syms";
+
+# Save the optional user specified syms file
+if ($numArgs > 1)
+{
+ $hbSymsFile = $ARGV[1];
+}
+
+print "hostboot dump file: $hbDumpFile\n";
+print "hostboot syms file: $hbSymsFile\n";
+
+
+#------------------------------------------------------------------------------
+# Create dumpout subdir for extracted dump
+#------------------------------------------------------------------------------
+#print getcwd()."\n";
+my $extDir = "dumpout.$hbDumpFileBase";
+if (-d $extDir)
+{
+ print "ERROR: directory $extDir exists.\n";
+ exit (1);
+}
+
+mkdir $extDir;
+
+
+#------------------------------------------------------------------------------
+# Open and read the .syms file
+#------------------------------------------------------------------------------
+open SYMSFILE, $hbSymsFile or die "ERROR: $hbSymsFile not found : $!";
+my @symslines = <SYMSFILE>; # Read it into an array
+close(SYMSFILE); # Close the file
+
+unless (@symslines)
+{
+ print "ERROR: $hbSymsFile is empty\n";
+ exit (1);
+}
+
+
+#------------------------------------------------------------------------------
+# Extract the code version / image id
+#------------------------------------------------------------------------------
+#Find address and size of the hbi_ImageId from the .syms file
+my $string = 'hbi_ImageId';
+my $buffer = 0;
+my ($addr, $size) = getAddrNSize($string, \@symslines);
+
+if (0 != $addr)
+{
+ #Read the hbi_ImageId from dump file and save to file
+ $buffer = readStringBinFile($hbDumpFile, $addr);
+
+ chdir "$extDir";
+ writeBinFile($string, $buffer);
+ chdir "../";
+}
+
+
+#------------------------------------------------------------------------------
+# Extract the kernel printk buffer
+#------------------------------------------------------------------------------
+#Find address and size of the kernel_printk_buffer from the .syms file
+$string = 'kernel_printk_buffer';
+($addr, $size) = getAddrNSize($string, \@symslines);
+
+if ((0 != $addr) && (0 != $size))
+{
+ #Read the kernel printk buffer from dump file and save to file
+ $buffer = readBinFile($hbDumpFile, $addr, $size);
+ chdir "$extDir";
+ writeBinFile($string, $buffer);
+ chdir "../";
+}
+
+
+#------------------------------------------------------------------------------
+# Extract the component traces
+#------------------------------------------------------------------------------
+#Find address and size of the g_desc_array from the .syms file
+$string = 'g_desc_array';
+($addr, $size) = getAddrNSize($string, \@symslines);
+
+if ((0 != $addr) && (0 != $size))
+{
+ #make subdir component_traces to store all traces
+ my $traceDir = $extDir.'/component_traces';
+ mkdir $traceDir;
+
+ #Read the g_desc_array from dump file and save the trace buffers
+ for (my $i = 0; $i < MAX_NUM_TRACE_BUFFERS; $i++)
+ {
+ #get the component name
+ my $compName = readStringBinFile($hbDumpFile, $addr);
+ chomp $compName;
+ last if ($compName eq "");
+
+ #get the component trace buffer address
+ $addr += DESC_ARRAY_ENTRY_COMP_NAME_SIZE;
+ $buffer = readBinFile($hbDumpFile, $addr, DESC_ARRAY_ENTRY_ADDR_SIZE);
+ my $compBufAddr= unpack('H*',$buffer);
+ $compBufAddr = hex $compBufAddr;
+ #print "Component: $compName, $buffer, $compBufAddr\n";
+ $addr += DESC_ARRAY_ENTRY_ADDR_SIZE;
+
+ #read the component trace buffer and save to file
+ $buffer = readBinFile($hbDumpFile, $compBufAddr, TRAC_DEFAULT_BUFFER_SIZE);
+
+ chdir "$traceDir";
+
+ writeBinFile($compName, $buffer);
+
+ #also append to tracBIN
+ appendBinFile('tracBIN', $buffer);
+
+ chdir "../../";
+ }
+
+ #check if file exists and is not empty
+ if (-s $traceDir.'/tracBIN')
+ {
+ #create tracMERG file
+ $string = sprintf ("fsp-trace -s hbotStringFile %s/tracBIN > %s/tracMERG",
+ $traceDir, $traceDir);
+ #print "$string\n";
+ `$string`;
+
+ #delete tracBIN file
+ unlink $traceDir.'/tracBIN';
+ }
+}
+
+#------------------------------------------------------------------------------
+# Save dump file to dumpout dir
+#------------------------------------------------------------------------------
+copy ($hbDumpFile, $extDir) or die "Copy failed: $!";
+
+#------------------------------------------------------------------------------
+# Print location of dumpout dir
+#------------------------------------------------------------------------------
+print "Dump extracted to ./$extDir\n";
+
+
+#==============================================================================
+# SUBROUTINES
+#==============================================================================
+
+#------------------------------------------------------------------------------
+# Parse the .syms data to find the relevant address and size for the data
+# requested.
+#------------------------------------------------------------------------------
+sub getAddrNSize($\@)
+{
+ my $addr = 0;
+ my $size = 0;
+
+ my $string = $_[0];
+ my (@array) = @{$_[1]};
+ #print "$string\n";
+ #print "@array\n";
+
+ #search for string in array
+ my @line = grep /$string/,@array;
+ #print "@line\n";
+
+ #if found string
+ if (@line)
+ {
+ my @list = split(/,+/,$line[0]);
+ #print "@list\n";
+
+ $addr = hex $list[1];
+ $size = hex $list[3];
+ #print "$addr\n";
+ #print "$size\n";
+ }
+
+ return($addr, $size);
+}
+
+#------------------------------------------------------------------------------
+# Read a block of data from a binary file.
+#------------------------------------------------------------------------------
+sub readBinFile($$$)
+{
+ my ($file, $addr, $size) = @_;
+ #print "$file, $addr, $size\n";
+
+ #Open the dump file for reading
+ open FILE, $file or die "ERROR: $file not found : $!";
+ binmode FILE;
+
+ seek FILE, $addr, 0 or die "Couldn't seek to $addr in $file: $!\n";
+ #print tell FILE; print "\n";
+ my $bytesRead = read(FILE, my $buffer, $size);
+ #print tell FILE; print "\n";
+ #print "#bytes read: $bytesRead\n";
+ #print "buffer: $buffer\n";
+
+ close (FILE);
+ return ($buffer);
+}
+
+#------------------------------------------------------------------------------
+# Read a NULL terminated string from a binary file.
+#------------------------------------------------------------------------------
+sub readStringBinFile($$)
+{
+ my ($file, $addr) = @_;
+ #print "$file, $addr\n";
+
+ #Open the dump file for reading
+ open FILE, $file or die "ERROR: $file not found : $!";
+ binmode FILE;
+
+ local $/ = "\0"; #Set to NULL termination
+ #my $tmp = $/;
+ #$/ = "\0"; #Set to NULL termination
+ seek FILE, $addr, 0 or die "Couldn't seek to $addr in $file: $!\n";
+ #print tell FILE; print "\n";
+ my $string = <FILE>;
+ #print tell FILE; print "\n";
+ chomp $string; #Remove NULL termination
+ #print "$string\n";
+ #$/ = $tmp; #Restore $/
+
+ close (FILE);
+ return ($string);
+}
+
+#------------------------------------------------------------------------------
+# Write a block of data to a binary file.
+#------------------------------------------------------------------------------
+sub writeBinFile($$)
+{
+ my ($file, $buffer) = @_;
+ open (FILE, ">$file") or die "ERROR: $file cannot be opened: $!";
+ binmode FILE;
+ print FILE $buffer;
+ close (FILE);
+}
+
+#------------------------------------------------------------------------------
+# Append a block of data to a binary file.
+#------------------------------------------------------------------------------
+sub appendBinFile($$)
+{
+ my ($file, $buffer) = @_;
+ open (FILE, ">>$file") or die "ERROR: $file cannot be opened: $!";
+ binmode FILE;
+ print FILE $buffer;
+ close (FILE);
+}
diff --git a/src/build/trace/traceHB.py b/src/build/trace/traceHB.py
index 47ed1125b..bf1d46a46 100755
--- a/src/build/trace/traceHB.py
+++ b/src/build/trace/traceHB.py
@@ -17,8 +17,11 @@ import conf
import configuration
import cli
import binascii
+import datetime
-# Function to dump the global trace buffer
+#------------------------------------------------------------------------------
+# Function to dump the trace buffers
+#------------------------------------------------------------------------------
def traceHB(compStr, symsFile, stringFile):
# "constants"
@@ -125,17 +128,17 @@ def traceHB(compStr, symsFile, stringFile):
#print addr_str
addr_trace_buffer = int(addr_str,16)
- #save trace buffer to <sandbox>/simics/trace.out
+ #save trace buffer to <sandbox>/simics/tracebin.out
string = "memory_image_ln0.save tmp.out 0x%x 0x800"%(addr_trace_buffer)
#print string
result = run_command(string)
#print result
if (buffer_found == 0):
- fd1 = open('trace.out','wb')
+ fd1 = open('tracebin.out','wb')
buffer_found = 1
else:
- fd1 = open('trace.out','ab')
+ fd1 = open('tracebin.out','ab')
fd2 = open('tmp.out', 'rb')
fd1.write(fd2.read())
fd1.close()
@@ -148,17 +151,21 @@ def traceHB(compStr, symsFile, stringFile):
entry_addr += DESC_ARRAY_ENTRY_SIZE
if (buffer_found == 1):
- #display formatted trace
- string = 'fsp-trace -s %s trace.out'%(stringFile)
+ #display formatted trace & save it to <sandbox>/simics/trace.out
+ string = 'fsp-trace -s %s tracebin.out | tee trace.out'%(stringFile)
#print string
os.system(string)
+ #remove tmp.out & tracebin.out
+ os.system('rm tmp.out tracebin.out')
print
break
return
+#------------------------------------------------------------------------------
# Function to dump the kernel printk buffer
+#------------------------------------------------------------------------------
def printkHB(symsFile):
print
@@ -187,9 +194,41 @@ def printkHB(symsFile):
#print file.read()
os.system('cat printk.out')
+ print
break
return
+
+#------------------------------------------------------------------------------
+# Function to dump L3
+#------------------------------------------------------------------------------
+def dumpL3():
+
+ # "constants"
+ L3_SIZE = 0x800000;
+
+ print
+
+ # Get a timestamp on when dump was collected
+ t = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
+ #print t
+
+ #dump L3 to hbdump.<timestamp>
+ string = "memory_image_ln0.save hbdump.%s 0 0x%x"%(t, L3_SIZE)
+ #print string
+ result = run_command(string)
+ #print result
+
+ print "HostBoot dump saved to hbdump.%s in simics directory."%(t)
+
+ return
+
+
+#------------------------------------------------------------------------------
+# Function to dump L3
+#------------------------------------------------------------------------------
+
+
#===============================================================================
# HOSTBOOT Commands
#===============================================================================
@@ -283,3 +322,24 @@ Examples: \n
hb-printk ../hbicore.syms \n
""")
+#------------------------------------------------
+#------------------------------------------------
+def hb_dump():
+ dumpL3()
+ return None
+
+new_command("hb-dump",
+ hb_dump,
+ #alias = "hbt",
+ type = ["hostboot-commands"],
+ #see_also = ["hb-trace"],
+ see_also = [ ],
+ short = "Dumps L3 to hbdump.<timestamp>",
+ doc = """
+Parameters: \n
+
+Defaults: \n
+
+Examples: \n
+ hb-dump \n
+ """)
OpenPOWER on IntegriCloud