summaryrefslogtreecommitdiff
path: root/i/pc104
diff options
context:
space:
mode:
authordufourj2006-02-04 21:34:07 +0000
committerdufourj2006-02-04 21:34:07 +0000
commit831e13eea8edbe4fbb6693628607b14bfd4f1aa8 (patch)
tree242bfe110cde987c895ecd37024244bc5ccbfc0a /i/pc104
parentd730013d29570d1669ea242927f197e05147f6e4 (diff)
PC104 :
- suppression du pivot_root (chroot convient mieux aux besoins) ; - script de mise à jour du programme sur l'initrd PC104 en autonome quasi-fonctionnel (quelques amélioriation à faire) ; - impossibilité de démarrer un binaire créé sur lampion sans provoquer un kill du kernel (certains supports noyau manquant ? Lib ou autres programmes manquant ?). - l'initrd compressé c'est rapide à booter mais long à mettre à jour...
Diffstat (limited to 'i/pc104')
-rw-r--r--i/pc104/initrd/conf/busybox/config30
-rwxr-xr-xi/pc104/initrd/conf/rcS13
-rwxr-xr-xi/pc104/initrd/conf/update_initrd.sh36
-rwxr-xr-xi/pc104/initrd/create.sh2
-rwxr-xr-xi/pc104/initrd/update.sh112
5 files changed, 130 insertions, 63 deletions
diff --git a/i/pc104/initrd/conf/busybox/config b/i/pc104/initrd/conf/busybox/config
index 28d373d..5373116 100644
--- a/i/pc104/initrd/conf/busybox/config
+++ b/i/pc104/initrd/conf/busybox/config
@@ -75,7 +75,7 @@ PREFIX="./_install"
#
# CONFIG_BASENAME is not set
# CONFIG_CAL is not set
-# CONFIG_CAT is not set
+CONFIG_CAT=y
# CONFIG_CHGRP is not set
# CONFIG_CHMOD is not set
# CONFIG_CHOWN is not set
@@ -107,15 +107,15 @@ CONFIG_FEATURE_FANCY_ECHO=y
# CONFIG_LENGTH is not set
# CONFIG_LN is not set
# CONFIG_LOGNAME is not set
-# CONFIG_LS is not set
-# CONFIG_FEATURE_LS_FILETYPES is not set
-# CONFIG_FEATURE_LS_FOLLOWLINKS is not set
-# CONFIG_FEATURE_LS_RECURSIVE is not set
-# CONFIG_FEATURE_LS_SORTFILES is not set
-# CONFIG_FEATURE_LS_TIMESTAMPS is not set
-# CONFIG_FEATURE_LS_USERNAME is not set
-# CONFIG_FEATURE_LS_COLOR is not set
-# CONFIG_FEATURE_LS_COLOR_IS_DEFAULT is not set
+CONFIG_LS=y
+CONFIG_FEATURE_LS_FILETYPES=y
+CONFIG_FEATURE_LS_FOLLOWLINKS=y
+CONFIG_FEATURE_LS_RECURSIVE=y
+CONFIG_FEATURE_LS_SORTFILES=y
+CONFIG_FEATURE_LS_TIMESTAMPS=y
+CONFIG_FEATURE_LS_USERNAME=y
+CONFIG_FEATURE_LS_COLOR=y
+CONFIG_FEATURE_LS_COLOR_IS_DEFAULT=y
# CONFIG_MD5SUM is not set
# CONFIG_MKDIR is not set
# CONFIG_MKFIFO is not set
@@ -168,7 +168,15 @@ CONFIG_TRUE=y
# CONFIG_WHOAMI is not set
# CONFIG_YES is not set
# CONFIG_FEATURE_PRESERVE_HARDLINKS is not set
-# CONFIG_FEATURE_AUTOWIDTH is not set
+
+#
+# Common options for ls and more
+#
+CONFIG_FEATURE_AUTOWIDTH=y
+
+#
+# Common options for df, du, ls
+#
# CONFIG_FEATURE_HUMAN_READABLE is not set
# CONFIG_FEATURE_MD5_SHA1_SUM_CHECK is not set
diff --git a/i/pc104/initrd/conf/rcS b/i/pc104/initrd/conf/rcS
index 2b1b486..0c1012c 100755
--- a/i/pc104/initrd/conf/rcS
+++ b/i/pc104/initrd/conf/rcS
@@ -14,6 +14,13 @@ mount /proc
# Launch update script in background
./etc/robot/update_initrd.sh &
-# TODO Export variables (LD...)
-# Launch the program
-# . /robot/start.sh
+# Launch the program ! Go Go Go !
+# For the library
+export LD_LIBRARY_PATH="./lib/;/robot/lib/"
+# Go to the directory where everything is
+cd /robot/
+# According to some scripts I have seen, it is quicker because it removes a
+# fork...
+# FIXME This does not work with ash busybox shell
+# . start.sh
+./start.sh
diff --git a/i/pc104/initrd/conf/update_initrd.sh b/i/pc104/initrd/conf/update_initrd.sh
index 4a76956..1f99519 100755
--- a/i/pc104/initrd/conf/update_initrd.sh
+++ b/i/pc104/initrd/conf/update_initrd.sh
@@ -1,37 +1,33 @@
#!/bin/sh
# The purpose of this script is to provide a system to update the PC104 in
# autonomous mode via the network.
-# It is called by the linuxrc and should not be called by hand.
+# It is called by the linuxrc/init at boot in another process so it can be
+# blocking. It should not be called by hand.
# PATH is not correctly set...
PATH=$PATH:/usr/sbin/
# Bring eth0 up
ifconfig eth0 up
# Get the configuration of the network via dhcp
+# TODO Check life time of this program and that it does not do stupid things
+# after a while...
udhcpc -i eth0 -s /etc/udhcpc.script
# Wait here for a connection. I do not know if it is a feature or a bug, but
# when nc receive a connection, it is end here. Maybe it is because of the
# missing library (warmed by gcc at compiled time)
nc -l -p 1234
-# Mount the real system
-mount /mnt/localsys
-# Pivot root to the new_root.
-# XXX It is a good idea to pivot_root ? Chroot is better ?
+# From here, someone has connected to the 1234 port, we mount the real linux
+# inside of the PC104 and start a ssh daemon, it is easier to use
+#
+# Mount the real system read only (security reason in case of hard reboot)
+mount -r /mnt/localsys
+# Chroot to the new_root
cd /mnt/localsys
-pivot_root . old_root
-# FIXME: I do not sure this is the good solution... Why make a exec and a
-# chroot ? I am not sure it is a good idea...
-exec chroot . sh -c '/etc/init.d/mountvirtfs; /etc/init.d/ssh start;' \
+# For the moment, I have seen it is compulsary to put the redirection
+chroot . sh -c '/etc/init.d/mountvirtfs; /etc/init.d/ssh start; exit' \
<dev/console >dev/console 2>&1
-# This part sux : what's about the old process ?
-# Kill them ?
-#umount /old_root
-# We should call all the script
-# TODO : find a better way to call it.
-#/etc/init.d/mountvirtfs start
-##/etc/init.d/mountall.sh start
-#/etc/init.d/networking start
-#/etc/init.d/ssh start
-# XXX And for the end ?
-# The FS has enough errors so do it well ! Umount everything !
+# XXX I would like the previous command to end, and give back the hand to the
+# next one. This way, I could have still a way to comunicate with the PC104 by
+# the initrd and not by the chrooted mode.
+# read 5
diff --git a/i/pc104/initrd/create.sh b/i/pc104/initrd/create.sh
index e6cc64f..342ddf8 100755
--- a/i/pc104/initrd/create.sh
+++ b/i/pc104/initrd/create.sh
@@ -50,7 +50,7 @@ mount_initrd ()
create_empty_struct ()
{
# Create an empty root structure
- mkdir -p $INITRD_TEMPDIR/{bin,dev,etc/{robot,init.d},proc,sbin,usr/{sbin,bin},var/lock,robot,initrd,mnt/localsys}
+ mkdir -p $INITRD_TEMPDIR/{bin,dev,etc/{robot,init.d},proc,sbin,usr/{sbin,bin},robot,initrd,mnt/localsys}
# Create all the devices files we need
create_dev
# Install the inittab
diff --git a/i/pc104/initrd/update.sh b/i/pc104/initrd/update.sh
index 9cb9059..ae7b0cf 100755
--- a/i/pc104/initrd/update.sh
+++ b/i/pc104/initrd/update.sh
@@ -1,6 +1,9 @@
#!/bin/bash
# Script for updating the marvin program in the initrd.
+set -e
+set -u
+
# Variables - Default values
# Local directory name containing the representation for the initrd
ROBOT_LOCAL_DIR="./robot"
@@ -12,8 +15,12 @@ ROBOT_START_SCRIPT="start.sh"
ROBOT_BUILD_DIR="."
# Config directory
ROBOT_CONF_DIR="$ROBOT_BUILD_DIR/../runtime"
-# Max size of the config directory
-ROBOT_CONF_MAX_SIZE="3000"
+# Max size of the config directory (in bytes)
+ROBOT_CONF_MAX_SIZE="100000"
+# Hostname of the robot
+ROBOT_HOST="nenuphar"
+# In autonomous mode, wait time for bringing up the ssh deamon
+ROBOT_WAIT_TIME="3s"
check_rsync ()
{
@@ -29,17 +36,19 @@ check_create_structure ()
# Check the local directory exist
if [[ ! -d $ROBOT_LOCAL_DIR ]]
then
- mkdir $ROBOT_LOCAL_DIR
+ mkdir -p $ROBOT_LOCAL_DIR/lib
fi
# Check we have a start script
- if [[ ! -f $ROBOT_LOCAL_DIR/$ROBOT_START_SCRIPT ]]
+ if [[ ! -x $ROBOT_LOCAL_DIR/$ROBOT_START_SCRIPT ]]
then
# Create a default one
- echo -e \
- "# Startup script launched when the PC104 boot.\n\
-# It will be sourced by other script.\n\
-# Example : \n\
-# ./test_ai -z" > $ROBOT_LOCAL_DIR/$ROBOT_START_SCRIPT
+ cat <<EOF > $ROBOT_LOCAL_DIR/$ROBOT_START_SCRIPT
+# Startup script launched when the PC104 boot.
+# It will be sourced by other script.
+# Example :
+# ./test_ai -z
+EOF
+ chmod +x $ROBOT_LOCAL_DIR/$ROBOT_START_SCRIPT
# Need to tune it by the user
echo "Please tune your $ROBOT_LOCAL_DIR/$ROBOT_START_SCRIPT."
# XXX vim it ?
@@ -51,12 +60,12 @@ check_create_structure ()
# a binary existing
check_install_binary ()
{
- if [[ $(grep -cv "^#" $ROBOT_LOCAL_DIR/$ROBOT_START_SCRIPT) -eq 0 ]]
+ if [[ $(grep -c "^\\./" $ROBOT_LOCAL_DIR/$ROBOT_START_SCRIPT) -eq 0 ]]
then
echo "No command found in your $ROBOT_LOCAL_DIR/$ROBOT_START_SCRIPT."
exit 3
fi
- for line in "$(grep -v "^#" $ROBOT_LOCAL_DIR/$ROBOT_START_SCRIPT)"
+ for line in "$(grep "^\\./" $ROBOT_LOCAL_DIR/$ROBOT_START_SCRIPT)"
do
bin="$(echo "$line" | cut -d ' ' -f 1)"
if [[ ! -x $ROBOT_BUILD_DIR/$bin ]]
@@ -65,9 +74,14 @@ check_install_binary ()
exit 4
else
# Copy the binary to the local dir
- install -m 777 $ROBOT_BUILD_DIR/$bin $ROBOT_LOCAL_DIR/
+ cp -p $ROBOT_BUILD_DIR/$bin $ROBOT_LOCAL_DIR/
# Remove useless symbol
- strip $ROBOT_LOCAL_DIR/$bin
+ strip -p $ROBOT_LOCAL_DIR/$bin
+ # Copy needed libraries
+ for lib in "$(ldd $ROBOT_BUILD_DIR/$bin | cut -d ' ' -f 3)"
+ do
+ cp -p $lib $ROBOT_LOCAL_DIR/lib
+ done
fi
done
}
@@ -76,28 +90,69 @@ check_install_binary ()
check_install_config ()
{
# First we check the size
- if [[ $(du -bs $ROBOT_CONF_DIR | cut -f 1) -gt $ROBOT_CONF_MAX_SIZE ]]
+ if [[ $(du -bs --exclude=.svn $ROBOT_CONF_DIR | cut -f 1) -gt $ROBOT_CONF_MAX_SIZE ]]
then
echo "Config directory ($ROBOT_CONF_DIR) is too big."
exit 5
fi
# There is no way to know the files needed, so we rsync everything
- rsync -aq $ROBOT_CONF_DIR/ $ROBOT_LOCAL_DIR/rc
+ rsync -aq --exclude=.svn $ROBOT_CONF_DIR/ $ROBOT_LOCAL_DIR
}
-# TODO Send it to the initrd
-# Guiding steps :
-# 1. Try netcat on the robot
-# 1.a If it responding, we are in autonomous mode, wait that the PC104 mount
-# the real system for ssh
-# 2. Try ssh
-# 2.a Not responding, wrong robot/dns ? Too quick from 1 ?
-# 3. Backuper/rotater l'initrd
-# 4. Dcomprss l'initrd
-# 5. Le monter
-# 6. rsyncer
-# 7. Dmonter
-# 8. Re-compresser
+upload_data ()
+{
+ # Check if host exist and is up
+ echo "Ping"
+ ping -c 1 -w 1 -q $ROBOT_HOST > /dev/null
+ case $? in
+ 0)
+ # Robot is online !
+ ;;
+ 1)
+ # Host exist but is offline
+ echo "$ROBOT_HOST is currently down."
+ exit 6
+ ;;
+ 2)
+ # Host does not exist
+ echo "$ROBOT_HOST does not exist."
+ exit 7
+ ;;
+ *)
+ # Unknown error...
+ echo "ping failed, unknown error."
+ exit 8
+ ;;
+ esac
+ echo "nc"
+ # Are we in automous mode ?
+ if [[ $(nc -w 1 $ROBOT_HOST 1234) -eq 0 ]]
+ then
+ sleep $ROBOT_WAIT_TIME
+ fi
+ # Mount the initrd
+ echo "Mounting"
+ # TODO Best manage compressed initrd or not
+# && gunzip -c /initrd/last > /tmp/initrd_cur \
+ ssh -o "ConnectTimeout 1" root@$ROBOT_HOST "mount -oremount,rw / \
+ && cp /initrd/last /tmp/initrd_cur \
+ && mount -o loop /tmp/initrd_cur /mnt/initrd"
+ # Rsyncer
+ echo "rsync"
+ # TODO Remove old files !
+ rsync -av $ROBOT_LOCAL_DIR/ root@$ROBOT_HOST:/mnt/initrd/$ROBOT_REMOTE_DIR/
+ echo "umount"
+ # Dmonter et recompresser l'initrd voir rotater tout
+ # TODO Best manage compressed initrd or not
+ # TODO Backup, rotation, et less cp !
+# && gzip -f -9 -c /tmp/initrd_cur > /initrd/initrd1.gz\
+ ssh -o "ConnectTimeout 1" root@$ROBOT_HOST "umount /mnt/initrd \
+ && cp /tmp/initrd_cur /initrd/initrd1.gz \
+ && sync \
+ && mount -oremount,ro /"
+# TODO Change between NFS/Autonomous...
+# && kill -SIGTERM 1"
+}
# TODO Parameter
@@ -105,3 +160,4 @@ check_rsync
check_create_structure
check_install_binary
check_install_config
+upload_data