#!/bin/bash
# Coreboot system information gathering script
# This is very Linux-specific right now.
#
# This script is Copyright (C) 2008 Carl-Daniel Hailfinger
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

parentdir=`pwd`

ACPIDUMP=`which acpidump 2>/dev/null`
test -z "$ACPIDUMP" && for a in /usr/bin /bin /usr/local/bin /usr/sbin /sbin /usr/local/sbin; do
	test -f $a/acpidump && IASL="$a/acpidump"
done
test -z "$ACPIDUMP" && { echo acpidump not found.; exit 1; }

LSPCI=`which lspci 2>/dev/null`
test -z "$LSPCI" && for a in /usr/bin /bin /usr/local/bin /usr/sbin /sbin /usr/local/sbin; do
	test -f $a/lspci && LSPCI="$a/lspci"
done
test -z "$LSPCI" && { echo lspci not found.; exit 1; }

DMIDECODE=`which dmidecode 2>/dev/null`
test -z "$DMIDECODE" && for a in /usr/bin /bin /usr/local/bin /usr/sbin /sbin /usr/local/sbin; do
	test -f $a/dmidecode && IASL="$a/dmidecode"
done
test -z "$DMIDECODE" && { echo dmidecode not found.; exit 1; }

mkdir coreboot_data
cd coreboot_data
mkdir utils

# Warning: The following commands should be run as a normal, but trusted, user.
{
svn co svn://linuxbios.org/repos/trunk/util/flashrom
cd flashrom
make
cp -a flashrom ../utils
cd $parentdir/coreboot_data
rm -rf flashrom
}
{
svn co svn://linuxbios.org/repos/trunk/util/superiotool
cd superiotool
make
cp -a superiotool ../utils
cd $parentdir/coreboot_data
rm -rf superiotool
}
# as needed only
{
wget http://ftp.kernel.org/pub/linux/kernel/people/lenb/acpi/utils/pmtools-20071116.tar.bz2
tar xjvf pmtools-20071116.tar.bz2
cd pmtools-20071116/acpidump/
make
cp -a acpidump ../../utils
cd $parentdir/coreboot_data
rm -rf pmtools-20071116
}


cat /proc/ioports >ioports.txt
cat /proc/iomem >iomem.txt
cat /proc/interrupts >interrupts.txt
cat /proc/cpuinfo >cpuinfo.txt
$LSPCI -vvvnnxxx >lspci-vvvnnxxx.txt
$LSPCI -t >lspci-t.txt
$DMIDECODE >dmidecode.txt
$ACPIDUMP >acpidump.txt
./utils/flashrom -V >flashrom.txt
./utils/superiotool -d -e -V >superiotool.txt
rm -rf utils

cd $parentdir
tar cjf coreboot_data.tar.bz2 coreboot_data/
echo
echo All done. Please send coreboot_data.tar.bz2 to dumps@coreboot.org. Thanks.
