Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#********************************************************************
# WARNING:: This whole exercise is performed while logged in as root.
# FOLLOW AT YOUR OWN RISK
#********************************************************************
# Setup a working directory anywhere you like. I'm using /vb/snakex.
mkdir /vb/snakex
cd /vb/snakex
export MYTOP=`pwd`
# Get the snakeos sdk
wget http://snake-os.googlecode.com/files/snakeos-sdk_1.1.tar.bz2
tar -xvjf *
# Set up your PATH for the toolchain.
# I found it helpful to keep this in a script.
vi /root/.bashrc
export MYTOP=/vb/snakex
PATH=$MYTOP/snakeos-sdk/tools/arm-uclibc-3.4.6/bin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin
# Logout & back in to get these settings. Or just execute the 2 previous commands.
# I spent quite a while trying to convert the existing config kernel file so that the kernel would work
# under QEMU, but could not make it happen.
# Finally, I just made one change to the "versatile_defconfig" config:
cd $MYTOP/snakeos-sdk/configs
mv str8132_defconfig_jffs2 str8132_defconfig_jffs2.orig
cd $MYTOP/snakeos-sdk/kernels/linux
make versatile_defconfig
vi .config
#Line 840: change "# CONFIG_TMPFS is not set" to "CONFIG_TMPFS=y"
cp .config ../../configs/str8132_defconfig_jffs2
cd $MYTOP/snakeos-sdk
vi mk_snakeos_image.sh
# change it so that it so that it exits after line 53. i.e. add new line 54 "exit".
# This may not be needed, but the script has done all I need by this point.
#Following the build SDK instructions (http://code.google.com/p/snake-os/wiki/FAQ), build twice, but record the output if interested.
./mk_snakeos_image.sh > /tmp/mk.log.1 2>&1
./mk_snakeos_image.sh > /tmp/mk.log.2 2>&1
#Make somewhere to keep the good stuff:
mkdir -p $MYTOP/runtime
cd $MYTOP/runtime
cp -a $MYTOP/snakeos-sdk/rootfs/target $MYTOP/runtime/
cp $MYTOP/snakeos-sdk/kernels/linux/arch/arm/boot/zImage $MYTOP/runtime/
# Set up the root file system ($MYTOP/runtime/target) so that it is accesible via NFS. (you need an NFS server on your machine).
vi /etc/exports
/vb/snakex/runtime/target -rw
# Permissions may be important here - don't know, so leave it wide open:
chmod 777 $MYTOP/runtime/target
# You may need to restart nfs to pickup the new config.
service netfs restart
# May be different on depending on you linux distro.
# Make sure that the ip we give snake is allowed access to this machine.
# Moy PC is on 192.168.1.50. I'm giving access to everything on my network...
vi /etc/hosts.allow
portmap: 192.168.1.0/255.255.255.0
lockd: 192.168.1.0/255.255.255.0
rquotad: 192.168.1.0/255.255.255.0
mountd: 192.168.1.0/255.255.255.0
statd: 192.168.1.0/255.255.255.0
# Note that we are going to run snake on 192.168.1.100.
# A small change to snake:
vi $MYTOP/runtime/target/etc/inittab
ttyAMA0::askfirst:/bin/sh
# This will give a command line directly onto snake from qemu. It is good.
# Force a static IP.
# This isn't nice at all, but I just want to get things working for now:
vi $MYTOP/runtime/target/usr/share/snake/rc.sysinit
# The entries start at lien 48
USE_DHCP_ADD=0
DEF_IP=192.168.1.100
DEF_MASK=255.255.255.0
DEF_GW=192.168.1.1
# Opendns name servers (I think)
DEF_DNS=208.67.222.222
DEF_DNS2=208.67.220.220
# Next we need to setup networking to play nice with qemu.
# Make a file called $MYTOP/runtime/net.sh
#-----------------------------------stat of file - don't include this line ----------------------------
#!/bin/bash
# Turn off the firewall & iptables to avoid possible issues I don't want to deal with right now:
service shorewall stop
service iptables stop
/usr/sbin/brctl addbr br0
routing=`/sbin/ip route | grep eth0`
# Get current eth0 address.
addr=`/sbin/ip addr | grep eth0 | grep inet | sed -e 's/eth0/dev br0/' -e 's/inet//'`
echo $addr
# Make eth0 promisc
/sbin/ifconfig eth0 promisc 0.0.0.0
/sbin/ifconfig br0 up
/sbin/ip addr add $addr
/usr/sbin/brctl addif br0 eth0
/usr/sbin/brctl stp br0 off
# Reset the routing
echo "$routing" | while read route
do
/sbin/ip route del $route
newroute=`echo $route | sed s/eth0/br0/ `
/sbin/ip route add $newroute
done
# Create a "tap" for the virtual machine.
tunctl -t tap1 -u admin
brctl addif br0 tap1
ifconfig tap1 up
#-----------------------------------end of file---------------------------------------------
# The above could be done better. Come back to it some time.
# WARNING:
# When you want to run snake under qemu, run net.sh *just once*.
# If you kill snake and want to start it again, don't re-run net.sh.
# If you do, unless you can figure out what's happening, you may need to reboot your PC
# to get networking back in order. After a reboot, run net.sh again (once).
# Execute it..
chmod +x $MYTOP/runtime/net.sh
$MYTOP/runtime/net.sh
#qemu seems to want a script to run when the tap is 'up'. I'm not sure how this should be used,
#but it needs a file anyway so give it an emply one:
echo '#!/bin/bash' > $MYTOP/runtime/tap-up
chmod +x $MYTOP/runtime/tap-up
#Feeling lucky?
qemu-system-arm -kernel $MYTOP/runtime/zImage -append "root=nfs nfsroot=192.168.1.50:$MYTOP/runtime/target,tcp wsize=4096 ip=192.168.1.100::192.168.1.1:255.255.255.0 console=ttyAMA0" -nographic -net nic -net tap,ifname=tap1,script=$MYTOP/runtime/tap-up -M versatilepb
#If all goes well you will see snake boot up.
#When it finishes, hit 'ENTER' and you will be at a snake shell command prompt.
#From your PC's web browser try:
http://192.168.1.100 (works, but something is not right - can't see any images). Come back to this.
#From your PCs shell try:
ssh ro...@192.168.1.100 (Works.)
#I kill the qemu snake system by running '
killall qemu-system-arm
#' from another prompt.
#Note that you can create a directory, say
cd $MYTOP/runtime/target/newdir
# .. and it will immediately appear in snake as /newdir. But its read only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.