While I was trying to get linux on my LITEKIT I developed the script below. You will need
to run it.
In the first few lines you can tune network stuff and some names. The DO_DOWNLOADS can be set to 'yes' if you want fresh downloads, setting it to 'no' will do an initial download and then use that when re-invoking the script. (maybe "FRESH_DOWNLOADS" would be a better name )
This is in no way meant to be a fail safe script. It is merely a way for me to get a reproduceable and formal way of bringing up linux. I thought I'd share it with you. Any improvements/corrections/comments are welcome.
As you may have read in an earlier post, my LITEKIT is still stuck with a irq-90 problem.
BASE=$(cd "$(dirname `echo $0`)";pwd)
DO_DOWNLOADS=no
MY_IP=`ifconfig eth0|sed -n -e 's/.*inet addr:\([^ ]*\).*/\1/p'`
THE_MASK=`ifconfig eth0|sed -n -e 's/.*Mask:\([^ ]*\).*/\1/p'`
THE_BROADCAST=`ifconfig eth0|sed -n -e 's/.*Bcast:\([^ ]*\).*/\1/p'`
THE_IP=192.168.3.250
THE_GATEWAY=192.168.3.1
THE_NAMESERVER=192.168.1.1
THE_TTY=/dev/ttyS0
LTIB_ISO=imx31_ads_20071008-rel5b-ltib.iso
ARM_BIN=/opt/freescale/usr/local/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi/bin
LTIB=$BASE/ltib-imx31ads-20071008
DOWN=$BASE/downloads
LOG=$BASE/log
MNT=$BASE/mnt
ROOT=$BASE/tftpboot
echo "$(date +'%H:%M:%S') ==== building in $BASE ===="
cd "$BASE"
echo "$(date +'%H:%M:%S') ==== sudo needed for subsequent actions ===="
sudo -v
echo "$(date +'%H:%M:%S') ==== removing previous left-overs ===="
if [ "`df|grep $MNT`" ]; then
sudo umount mnt
if [ "`df|grep $MNT`" ]; then
echo ERROR: could not unmount $MNT
exit
fi
fi
rm -rf $LOG
rm -rf $ROOT
rm -rf bootloader
rm -rf exports-backup
rm -rf .*.swp
rm -rf kick.sh
rmdir $MNT 2> /dev/null
sudo rm -rf $LTIB
sudo rm -rf /opt/freescale/pkgs
sudo rm -rf /opt/freescale/ltib
sudo rm -rf /opt/freescale/usr
if [ "$DO_DOWNLOADS" == yes ]; then
echo "$(date +'%H:%M:%S') ==== removing downloaded files ===="
rm -rf "$DOWN"
fi
echo "Hit ^C within one second to stop with a clean directory..."
sleep 1
mkdir -p $MNT
mkdir -p $LOG
mkdir -p $DOWN
mkdir -p $ROOT
if [ ! -f $LTIB_ISO ]; then
cat <
$(date +'%H:%M:%S') =========================================================
Download of Board Support Package from FreeScale needed.
==================================================================
There are two ways to get the BSP from FreeScale:
1. The Royal way:
- Goto
http://www.freescale.com/"
- Login with the 'login' link at the top right (go through registration when new here).
- Click the 'Support' tab in the menu bar.
- Click the 'Linux Board Support Packages' link at the right.
- Click the 'BSPs for ARM Architectures' link at the bottom.
- Click the 'download' link of 'Linux BSP for Freescale i.MX31ADS' in the list.
- Save the file (called $LTIB_ISO) in $BASE
2. The Shortcut:
- Goto https://www.freescale.com/webapp/Download?colCode=CWF-IMX31ADSLTIB&nodeId=0127260061033202A7&location=overview
- Login to the presented login screen (go through registration when new here)
- Save the file (called $LTIB_ISO) in $BASE
==================================================================
EOF
read -p "Hit return when done: "
while [ ! -f $LTIB_ISO ]; do
read -p "Sorry, BSP file not found, try again. Hit return when done: "
done
fi
echo "$(date +'%H:%M:%S') ==== downloading bits and pieces ===="
for i in \
"(bootloader.tar.gz
http://mx31.lbox.ca/download/bootloader.tar.gz '157877857 3217' )" \
"(mach-types
http://www.arm.linux.org....achines/download.php '1875853266 65031' )" \
"(litekit.config
http://www.lysator.liu.se...10-19/litekit.config '3844885236 33173' )" \
"(iMX31_litekit_disable_usb.patch
http://www.lysator.liu.se...it_disable_usb.patch '2735393505 495' )" \
"(iMX31_litekit_support.patch
http://www.lysator.liu.se...itekit_support.patch '3064199057 76350' )" \
"(smsc_911x_vendor_driver.patch
http://www.lysator.liu.se..._vendor_driver.patch '3850927224 76198' )" \
"(linux-2.6.22.6.tar.bz2
http://www.kernel.org/pub...nux-2.6.22.6.tar.bz2 '1275820199 45109498' )" \
"(linux-2.6.19.2.tar.bz2
http://www.kernel.org/pub...nux-2.6.19.2.tar.bz2 '2180975117 42729366' )" \
; do
eval i=$i
name=${i[0]}
url=${i[1]}
crc=${i[2]}
if [ ! -f $DOWN/$name ]; then
wget -a $LOG/wget.log -O $DOWN/$name $url
fi
if [ ! -f $DOWN/$name ]; then
echo "ERROR: could not download $name from $url"
exit 999
fi
sum=`cat $DOWN/$name|cksum`
if [ "$crc" != "$sum" ]; then
#echo " \"($name $url '$sum')\" \\"
echo "WARNING: downloaded file is different from expected: $url"
echo " cksum='$sum' expected='$crc'"
fi
done
echo "$(date +'%H:%M:%S') ==== installing the BSP ===="
sudo mount -o loop -t iso9660 -o ro $LTIB_ISO $MNT
$MNT/install > $LOG/install.log <
y
yes
EOF
if [ ! -d $LTIB ]; then
echo ERROR: the BSP should have been installed in $LTIB, but it did not.
exit -99
fi
( cd $LTIB/config/platform/imx31ads
cp defconfig tom-defconfig
patch -s tom-defconfig <
--- defconfig 2007-09-27 17:18:58.000000000 +0000
+++ defconfig.dev 2008-03-19 13:21:18.000000000 +0000
@@ -56,10 +56,10 @@
# CONFIG_KERNEL_DIR_BUILD is not set
# CONFIG_KERNEL_NONE is not set
CONFIG_PKG_KERNEL="kernel-2.6.22-mx"
-CONFIG_PKG_KERNEL_PRECONFIG="linux-2.6.22-mx31ads.config"
+CONFIG_PKG_KERNEL_PRECONFIG="linux-2.6.22-mx31ads.config"
# CONFIG_PKG_KERNEL_WANT_HEADERS is not set
# CONFIG_PKG_KERNEL_WANT_CF is not set
-# CONFIG_PKG_KERNEL_LEAVESRC is not set
+CONFIG_PKG_KERNEL_LEAVESRC=y
CONFIG_DEPLOYMENT_ERASE_BLOCK_SIZE="128"
CONFIG_DISTRO="dist/lfs-5.1"
@@ -298,11 +298,11 @@
CONFIG_SYSCFG_IFACE0=y
CONFIG_SYSCFG_NET_INTERFACE0="eth0"
# CONFIG_SYSCFG_DHCPC0 is not set
-CONFIG_SYSCFG_IPADDR0="172.27.161.13"
-CONFIG_SYSCFG_NET_MASK0="255.255.0.0"
-CONFIG_SYSCFG_NET_BROADCAST0="172.27.255.255"
-CONFIG_SYSCFG_NET_GATEWAY0="172.27.255.254"
-CONFIG_SYSCFG_NAMESERVER0="172.27.0.1"
+CONFIG_SYSCFG_IPADDR0="192.168.3.250"
+CONFIG_SYSCFG_NET_MASK0="255.255.255.0"
+CONFIG_SYSCFG_NET_BROADCAST0="192.168.3.255"
+CONFIG_SYSCFG_NET_GATEWAY0="192.168.3.1"
+CONFIG_SYSCFG_NAMESERVER0="192.168.1.1"
#
#
EOF
)
echo "$(date +'%H:%M:%S') ==== Doing ltib ===="
if [ $EXPLAIN ]; then
echo " - in dialog:"
echo " - [*] Leave sources after building"
echo "$(date +'%H:%M:%S') =========================================================="
fi
(cd $LTIB;./ltib -b --preconfig $LTIB/config/platform/imx31ads/tom-defconfig > $LOG/ltib-pass1.log 2>&1)
if [ ! "`tail $LOG/ltib-pass1.log|fgrep 'Build Succeeded'`" ]; then
echo "ERROR: ltib build did not succeed. (see $LOG/ltib-pass1.log)"
exit -99
fi
echo "$(date +'%H:%M:%S') ==== Patching for LiteKit ===="
( cd $LTIB/rpm/BUILD/linux
patch -s -p1 < $DOWN/iMX31_litekit_disable_usb.patch
patch -s -p1 < $DOWN/iMX31_litekit_support.patch
patch -s -p1 < $DOWN/smsc_911x_vendor_driver.patch
cp .config .config-orig
cp $DOWN/litekit.config .config
cp arch/arm/tools/mach-types arch/arm/tools/mach-types-orig
cp $DOWN/mach-types arch/arm/tools
)
( cd $LTIB/config/platform/imx31ads
cp defconfig tom-defconfig
cp linux-2.6.22-mx31ads.config tom-linux-2.6.22-mx31ads.config
patch -s tom-defconfig <
--- defconfig 2007-09-27 17:18:58.000000000 +0000
+++ defconfig.dev 2008-03-19 13:21:18.000000000 +0000
@@ -56,10 +56,10 @@
# CONFIG_KERNEL_DIR_BUILD is not set
# CONFIG_KERNEL_NONE is not set
CONFIG_PKG_KERNEL="kernel-2.6.22-mx"
-CONFIG_PKG_KERNEL_PRECONFIG="linux-2.6.22-mx31ads.config"
+CONFIG_PKG_KERNEL_PRECONFIG="tom-linux-2.6.22-mx31ads.config"
# CONFIG_PKG_KERNEL_WANT_HEADERS is not set
# CONFIG_PKG_KERNEL_WANT_CF is not set
-# CONFIG_PKG_KERNEL_LEAVESRC is not set
+CONFIG_PKG_KERNEL_LEAVESRC=y
CONFIG_DEPLOYMENT_ERASE_BLOCK_SIZE="128"
CONFIG_DISTRO="dist/lfs-5.1"
@@ -298,11 +298,11 @@
CONFIG_SYSCFG_IFACE0=y
CONFIG_SYSCFG_NET_INTERFACE0="eth0"
# CONFIG_SYSCFG_DHCPC0 is not set
-CONFIG_SYSCFG_IPADDR0="172.27.161.13"
-CONFIG_SYSCFG_NET_MASK0="255.255.0.0"
-CONFIG_SYSCFG_NET_BROADCAST0="172.27.255.255"
-CONFIG_SYSCFG_NET_GATEWAY0="172.27.255.254"
-CONFIG_SYSCFG_NAMESERVER0="172.27.0.1"
+CONFIG_SYSCFG_IPADDR0="192.168.3.250"
+CONFIG_SYSCFG_NET_MASK0="255.255.255.0"
+CONFIG_SYSCFG_NET_BROADCAST0="192.168.3.255"
+CONFIG_SYSCFG_NET_GATEWAY0="192.168.3.1"
+CONFIG_SYSCFG_NAMESERVER0="192.168.1.1"
#
#
EOF
patch -s tom-linux-2.6.22-mx31ads.config <
--- linux-2.6.22-mx31ads.config 2007-09-28 22:55:35.000000000 +0000
+++ linux-2.6.22-mx31ads.config.dev 2008-03-19 10:46:02.000000000 +0000
@@ -160,7 +160,8 @@
#
# MX3 Options
#
-CONFIG_MACH_MX31ADS=y
+CONFIG_MACH_MX31LITE=y
+# CONFIG_MACH_MX31ADS is not set
# CONFIG_MX3_DOZE_DURING_IDLE is not set
CONFIG_MXC_SDMA_API=y
CONFIG_ARCH_MXC_HAS_NFC_V2=y
@@ -342,54 +343,7 @@
#
# CONFIG_NET_PKTGEN is not set
# CONFIG_HAMRADIO is not set
-CONFIG_IRDA=m
-
-#
-# IrDA protocols
-#
-CONFIG_IRLAN=m
-CONFIG_IRNET=m
-CONFIG_IRCOMM=m
-# CONFIG_IRDA_ULTRA is not set
-
-#
-# IrDA options
-#
-CONFIG_IRDA_CACHE_LAST_LSAP=y
-CONFIG_IRDA_FAST_RR=y
-# CONFIG_IRDA_DEBUG is not set
-
-#
-# Infrared-port device drivers
-#
-
-#
-# SIR device drivers
-#
-CONFIG_IRTTY_SIR=m
-
-#
-# Dongle support
-#
-# CONFIG_DONGLE is not set
-# CONFIG_KINGSUN_DONGLE is not set
-
-#
-# Old SIR device drivers
-#
-# CONFIG_IRPORT_SIR is not set
-
-#
-# Old Serial dongle support
-#
-
-#
-# FIR device drivers
-#
-# CONFIG_USB_IRDA is not set
-# CONFIG_SIGMATEL_FIR is not set
-# CONFIG_MCS_FIR is not set
-CONFIG_MXC_FIR=m
+# CONFIG_IRDA is not set
# CONFIG_BT is not set
# CONFIG_AF_RXRPC is not set
@@ -658,6 +612,7 @@
# CONFIG_NET_VENDOR_3COM is not set
# CONFIG_NET_VENDOR_SMC is not set
# CONFIG_SMC91X is not set
+CONFIG_SMSC911X=y
# CONFIG_DM9000 is not set
# CONFIG_NET_VENDOR_RACAL is not set
# CONFIG_AT1700 is not set
@@ -667,7 +622,7 @@
CONFIG_NET_PCI=y
# CONFIG_AC3200 is not set
# CONFIG_APRICOT is not set
-CONFIG_CS89x0=y
+# CONFIG_CS89x0 is not set
# CONFIG_NETDEV_1000 is not set
# CONFIG_NETDEV_10000 is not set
# CONFIG_TR is not set
@@ -1034,8 +989,6 @@
# CONFIG_LOGO_LINUX_MONO is not set
# CONFIG_LOGO_LINUX_VGA16 is not set
CONFIG_LOGO_LINUX_CLUT224=y
-CONFIG_LOGO_MX31ADS_CLUT224=y
-# CONFIG_LOGO_MX32ADS_CLUT224 is not set
#
# Sound
EOF
)
echo "$(date +'%H:%M:%S') ==== Doing ltib again (on patched sources) ===="
if [ $EXPLAIN ]; then
echo " - in first dialog: "
echo " - [*] Configure the kernel"
echo " - [*] Leave sources after building"
echo " - Target System Configuration"
echo " Options --->"
echo " Network setup --->"
echo " ($THE_IP) IP address"
echo " ($THE_MASK) netmask"
echo " ($THE_BROADCAST) broadcast address"
echo " ($THE_GATEWAY) gateway address"
echo " ($THE_NAMESERVER) nameserver IP address"
echo " - in second dialog: "
echo " - System Type --->"
echo " Freescale MXC Implementations --->"
echo " MX3 Options --->"
echo " [*] Support MX31LITE platforms"
echo " [ ] Support MX31ADS platforms"
echo " - Device Drivers ---> "
echo " Network device support --->"
echo " Ethernet (10 or 100Mbit) --->"
echo " <*> SMSC LAN911x/LAN921x families embedded ethernet support"
echo " < > CS89x0 support"
echo " - Networking --->"
echo " < > IrDA (infrared) subsystem support --->"
echo "$(date +'%H:%M:%S') =========================================================="
fi
(cd $LTIB;./ltib -b --preconfig $LTIB/config/platform/imx31ads/tom-defconfig > $LOG/ltib-pass2.log 2>&1)
if [ ! "`tail $LOG/ltib-pass1.log|fgrep 'Build Succeeded'`" ]; then
echo "ERROR: ltib build did not succeed. (see $LOG/ltib-pass2.log)"
exit -99
fi
echo "$(date +'%H:%M:%S') ==== Making Second Stage Bootloader ===="
tar -xf $DOWN/bootloader.tar.gz
( cd bootloader
cp Makefile Makefile.orig
cp bootloaderstg2.c bootloaderstg2.c.orig
sed -i -e 's+^CC=+CC='"$ARM_BIN"'/+' Makefile
sed -i -e 's+^LD=+LD='"$ARM_BIN"'/+' Makefile
sed -i -e 's+^AS=+AS='"$ARM_BIN"'/+' Makefile
sed -i -e 's+^LIBGCC=.*+LIBGCC=/opt/freescale/usr/local/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi/arm-none-linux-gnueabi/sysroot/usr/lib+' Makefile
sed -i -e 's+#define COMMAND_LINE[^_].*+#define COMMAND_LINE "console=ttymxc0 root=/dev/nfs nfsroot='"$MY_IP:$ROOT"'/rootfs rw init=/linuxrc ip='"$THE_IP::$THE_GATEWAY:$THE_MASK"' noalign"+' bootloaderstg2.c
make loader > $LOG/make-bootloader.log 2>&1
)
echo "$(date +'%H:%M:%S') ==== Preparing network publish ===="
sudo apt-get install tftp-hpa tftpd-hpa > /dev/null
ln -s $BASE/bootloader/loader $ROOT/loader
ln -s $LTIB/rootfs $ROOT/rootfs
( cd "$LTIB/rootfs/boot"
for i in *; do
ln -s "$LTIB/rootfs/boot/$i" "$ROOT/$i"
done
)
cp /etc/exports exports-backup
sudo sed -i -e '\+$ROOT+d' /etc/exports
sudo sed -i -e '$a'"$ROOT"'/rootfs '"$THE_IP"'(rw,no_root_squash,async)' /etc/exports
if [ -f /etc/xinetd.d/tftp ]; then
if [ "`fgrep 'service' /etc/xinetd.d/tftp|wc -l`" -ge 2 ]; then
echo ERROR: /etc/xinetd.d/tftp contains more then one service
exit 999
elif [ "`fgrep 'server_args' /etc/xinetd.d/tftp`" != "server_args = $ROOT" ]; then
echo ERROR: /etc/xinetd.d/tftp contains another service
exit 999
else
sudo rm /etc/xinetd.d/tftp
fi
fi
sudo -s <
cat >> /etc/xinetd.d/tftp <
service tftp
{
disable = no
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = $ROOT
}
EOF2
EOF
sudo /etc/init.d/xinetd restart
sudo /usr/sbin/exportfs -a
echo "$(date +'%H:%M:%S') ==== Preparing LITEKIT board ===="
echo "=================================================================="
echo " Connect the LITEKIT board to $THE_TTY"
echo "=================================================================="
read -p "Hit return when ready: "
echo "=================================================================="
cat > kick.sh <
KICK=\`$ARM_BIN/arm-none-linux-gnueabi-objdump -t bootloader/loader|sed -n -e 's/\([0-9a-f]*\).* main/\1/p'\`
START_Z=0x81000000
LEN=\`cat $LTIB/rootfs/boot/zImage|wc -c\`
for i in \\
"('ifconfig sm0 $THE_IP $THE_MASK $THE_GATEWAY' 12)" \\
"('load elf /tftp/$MY_IP:$ROOT/loader' 3)" \\
"('load raw \$START_Z \$LEN /tftp/$MY_IP:$ROOT/zImage' 5)" \\
"('exec 0x\$KICK -' 0)" \\
; do
eval "i=\$i"
cmd="\${i[0]}"
slp="\${i[1]}"
echo "\$cmd"
echo "\$cmd" > $THE_TTY
sleep \$slp
done
EOF
chmod +x kick.sh
./kick.sh
echo "possibly zap the root password from rootfs/etc/shadow"