r4786 - in developers/werner: . myroot myroot/restricted_bin

werner at docs.openmoko.org werner at docs.openmoko.org
Fri Nov 14 11:29:35 CET 2008


Author: werner
Date: 2008-11-14 11:29:34 +0100 (Fri, 14 Nov 2008)
New Revision: 4786

Added:
   developers/werner/myroot/
   developers/werner/myroot/README
   developers/werner/myroot/mkjffs2
   developers/werner/myroot/myroot
   developers/werner/myroot/restricted_bin/
   developers/werner/myroot/restricted_bin/update-alternatives
   developers/werner/myroot/werner.init
Log:
Customized rootfs image builder. (For development and such.)



Added: developers/werner/myroot/README
===================================================================
--- developers/werner/myroot/README	                        (rev 0)
+++ developers/werner/myroot/README	2008-11-14 10:29:34 UTC (rev 4786)
@@ -0,0 +1,125 @@
+*** WORK IN PROGRESS - USE AT YOUR OWN PERIL ! ***
+
+
+What does it do ?
+=================
+
+This root filesystem construction system builds a root filesystem from
+pre-compiled packages from the Openmoko feed. The goal is to be able to
+make highly customized systems with as little effort as possible.
+
+A high degree of customization is required in case like system
+development, where complex user space often interferes with tests and
+may alter the system's state in inexpected ways.
+
+Also, "dumbing down" an existing rootfs and then augmenting it with the
+special tools used during development is often very time-consuming, and
+since it usually takes the form of an ad-hoc job, most of the work has
+to be repeated when switching to a new base rootfs.
+
+
+How to use this
+===============
+
+Customization
+-------------
+
+The customization script is a shell script that specifies which packages
+get installed, sets up the system initialization process, and performs a
+number of adaptations and corrections.
+
+The script "werner" is an example of a relatively complex customization.
+It installs many development tools not normally part of a rootfs and
+reduces the system setup to the bare minimum, so that once can interact
+with a pristine system.
+
+The execution environment of this script is as follows:
+
+- the environment variable SVN points to the root of the Openmoko SVN
+  repository
+
+- the command "pkg" is equivalent to "opkg-target install ..."
+
+- the command "root" changes the current directory to the root of the
+  file system being populated
+
+- when using path names, be careful to avoid absolute paths for
+  destinations, e.g.,
+  echo 'user:...' >>/etc/passwd
+  will add it to the host's /etc/passwd, not the one in the rootfs.
+
+
+Plugging the holes
+------------------
+
+Some executables are currently missing. They are crudely provided by
+copying items from an existing rootfs image:
+
+wget http://downloads.openmoko.org/releases/Om2008.9/Om2008.9-gta02-20080916.rootfs.tar.gz
+mkdir rootfs
+tar xCfz rootfs Om2008.9-gta02-20080916.rootfs.tar.gz
+
+
+Making the filesystem hierarchy
+-------------------------------
+
+Just run
+
+./myroot <customization_script>
+
+myroot will print out a flurry of errors at the end when trying to run
+the postinstall scripts, but that's the way things are for now.
+
+The result is a directory "root" with contains the root filesystem
+hierarchy.
+
+myroot also has an interactive mode that can be invoked by setting the
+variable (in the myroot script) interactive=true. In interactive mode,
+which runs after the customization script is processed, all shell
+commands entered are interpreted as if they were part of the
+customization script.
+
+
+Making a filesystem image
+-------------------------
+
+A GTA02 JFFS2 image can be generated with
+
+./mkjffs2
+
+The result is a file root.jffs2 which can be copied to the GTA02 with
+the usual
+
+dfu-util -a rootfs -D root.jffs2 
+
+
+Bugs and future improvements
+============================
+
+Excessive downloads
+-------------------
+
+myroot currently refreshes the package database and downloads all the
+packages it installs over and over again in each run, which wastes quite
+a bit of time. Work is underway to make opkg cache this data.
+
+
+Missing files and packages
+--------------------------
+
+For some programs, we only have a busybox version, either because the
+packge with the regular version is not in our feed or because the
+program in question seems to be missing from the package.
+
+
+Postinstall scripts
+-------------------
+
+Postinstall scripts are run in a rather crude "sandbox" that only
+provides the update-alternatives command. As a consequence, the scripts
+produce lots of errors, some packages need further post-processing, and
+there's the risk of scripts still modifying files outside the "sandbox".
+
+Ideally, myroot would run a proper chroot'ed environment for the
+post-processing script, and maybe even enlist the help of something like
+qmu to run ARM binaries.

Added: developers/werner/myroot/mkjffs2
===================================================================
--- developers/werner/myroot/mkjffs2	                        (rev 0)
+++ developers/werner/myroot/mkjffs2	2008-11-14 10:29:34 UTC (rev 4786)
@@ -0,0 +1,18 @@
+#!/bin/sh
+#
+# GTA02 !
+#
+
+dir=${1:-root}
+name="`basename $dir`"
+
+if [ ! -d "$dir" ]; then
+    echo "usage: $0 [dirname]" 1>&2
+    exit 1
+fi
+
+mkfs.jffs2 --eraseblock=0x20000 --pagesize=0x800 --no-cleanmarkers \
+  --little-endian --pad -o _tmp -d $dir
+sumtool --eraseblock=0x20000 --no-cleanmarkers \
+  --littleendian --pad -i _tmp -o $name.jffs2
+rm -f _tmp


Property changes on: developers/werner/myroot/mkjffs2
___________________________________________________________________
Name: svn:executable
   + *

Added: developers/werner/myroot/myroot
===================================================================
--- developers/werner/myroot/myroot	                        (rev 0)
+++ developers/werner/myroot/myroot	2008-11-14 10:29:34 UTC (rev 4786)
@@ -0,0 +1,206 @@
+#!/bin/sh
+
+#
+# Builds upon the Openmoko toolchain:
+# http://wiki.openmoko.org/wiki/Toolchain
+#
+
+PREFIX=/usr/local/openmoko/arm
+ARCH=arm-angstrom-linux-gnueabi
+CONF=$PREFIX/$ARCH/etc/opkg.conf
+LIB=$PREFIX/lib
+OPKG_CL=$PREFIX/bin/opkg-cl
+
+MAKE="`which make`"
+INSTALL="`which install`"
+
+CWD=$PWD
+restricted_bin=$PWD/restricted_bin
+root=$PWD/root
+
+remove_root=true
+interactive=false
+
+
+# ----- Find the Openmoko SVN repository --------------------------------------
+
+
+for base in $PWD $HOME /home; do
+    for dir in "" openmoko moko om; do
+	for svn in svn.openmoko.org svn.openmoko svn ""; do
+	    try=$base/$dir/$svn
+	    if [ -d $try/developers/werner ]; then
+		SVN=$try
+		break 3
+	    fi
+	done
+    done
+done
+
+echo "SVN=$SVN"
+if [ -z "$SVN" ]; then
+    echo svn checkout http://svn.openmoko.org/
+    exit 1
+fi
+
+
+# ----- Special commands in the build script ----------------------------------
+
+
+opkg()
+{
+    LD_LIBRARY_PATH=$LIB $OPKG_CL -f $CONF -o "$root" "$@"
+}
+
+
+pkg()
+{
+    LD_LIBRARY_PATH=$LIB $OPKG_CL -f $CONF -o "$root" -V 0 install "$@"
+}
+
+
+make()
+{
+    PATH=$PATH:$PREFIX/bin $MAKE -s CC=$ARCH-gcc "$@"
+}
+
+
+install()
+{
+    [ -e "$1" ]
+    [ -d "$2" ]
+    cp "$1" "$root/$2/"
+}
+
+
+root()
+{
+    cd $root
+}
+
+
+# ----- Set up the root directory ---------------------------------------------
+
+
+if [ "$root" = "${root#/}" ]; then
+    root="$PWD/$root"
+fi
+
+root="`echo \"$root\" | sed 's|/$||'`"
+root_base="`dirname \"$root\"`"
+
+if [ -d "$root" ]; then
+    if $remove_root; then
+	rm -rf "$root"
+    else
+	echo "$root: output directory already exists" 1>&2
+	exit 1
+    fi
+fi
+
+if [ -e "$root" ]; then
+    echo "$root: something is in the way" 1>&2
+    exit 1
+fi
+
+if [ ! -d "$root_base" ]; then
+    echo "$root: no parent directory" 1>&2
+    exit 1
+fi
+
+echo "Creating $root"
+mkdir "$root"
+
+
+# ----- set up the bare essentials --------------------------------------------
+
+
+mkdir -p "$root/dev"
+mkdir -p "$root/proc"
+mkdir -p "$root/sys"
+
+mknod "$root/dev/null" c 1 3
+mknod "$root/dev/tty" c 5 0
+mknod "$root/dev/console" c 5 1
+mknod "$root/dev/ttySAC2" c 204 66
+
+mkdir -p "$root/sbin"
+mkdir -p "$root/bin"
+mkdir -p "$root/etc"
+mkdir -p "$root/tmp"
+mkdir -p "$root/usr/local/bin"
+mkdir -p "$root/usr/lib/opkg"
+
+mkdir -p "$root/home/root"
+chmod 755 "$root/home" "$root/home/root"
+
+echo "root::0:0:root:/home/root:/bin/sh" >"$root/etc/passwd"
+
+cp $CONF "$root/etc"
+
+
+# ----- opkg environment ------------------------------------------------------
+
+
+PKG_CONFIG_SYSROOT_DIR="$root"
+PKG_CONFIG_PATH="/usr/lib/pkgconfig"
+CONFIG_SITE=/usr/local/openmoko/arm/site-config
+
+export PKG_CONFIG_SYSROOT_DIR PKG_CONFIG_PATH CONFIG_SITE
+
+
+# ----- opkg package database -------------------------------------------------
+
+# @@@ cache lists and packages
+
+update_cache()
+{
+    mkdir -p $PWD/cache
+    root=$PWD/cache opkg update
+}
+
+
+
+# -----
+
+
+
+opkg update
+custom=$1
+if [ ! -z "$custom" ]; then
+    if [ "${custom#/}" = "$custom" ]; then
+	custom="$PWD/$custom"
+    fi
+    . "$custom"
+fi
+
+
+if $interactive; then
+    while read -e -p "mkroot> " l; do
+	eval "$l"
+    done
+fi
+
+
+# ----- run postinstall scripts -----------------------------------------------
+
+
+#
+# The only thing we really need our post-install scripts to do is to rename the
+# alternatives. We accomplish this by executing them on the host, but giving
+# them a very limited PATH, containing only update-alternatives.
+#
+
+cd "$root/usr/lib/opkg/info"
+MYROOT_ROOT="$root"
+export MYROOT_ROOT
+for n in *.postinst; do
+    PATH=$restricted_bin ./$n
+done
+rm *.postinst
+
+
+# ----- Done ------------------------------------------------------------------
+
+
+exit


Property changes on: developers/werner/myroot/myroot
___________________________________________________________________
Name: svn:executable
   + *

Added: developers/werner/myroot/restricted_bin/update-alternatives
===================================================================
--- developers/werner/myroot/restricted_bin/update-alternatives	                        (rev 0)
+++ developers/werner/myroot/restricted_bin/update-alternatives	2008-11-14 10:29:34 UTC (rev 4786)
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+#
+# Invocation example:
+#
+# update-alternatives --install /bin/more more more.util-linux 100
+#
+# $1 is always --install
+# $2 is the absolute path under which the file will be used
+# $3 seems to be the file's canonical name (basename $2 ?)
+# $4 is the relative or absolute (!) path to the file installed by opkg so far
+# $5 is a priority value, in case there are alternatives
+#
+
+PATH=/bin:/usr/bin
+
+if [ "$1" != "--install" ]; then
+    echo "expected --install" 1>&2
+    exit 1
+fi
+
+if [ -e "$MYROOT_ROOT/$2" ]; then
+    echo "$2: exists" 1>&2
+    exit 1
+fi
+
+if [ "${4#/}" = "$4" ]; then
+    src="`dirname \"$2\"`/$4"
+else
+    src="$4"
+fi
+
+if [ ! -e "$MYROOT_ROOT/$src" ]; then
+    echo "$src: not found" 1>&2
+    exit 1
+fi
+
+ln -sf "$4" "$MYROOT_ROOT/$2"


Property changes on: developers/werner/myroot/restricted_bin/update-alternatives
___________________________________________________________________
Name: svn:executable
   + *

Added: developers/werner/myroot/werner.init
===================================================================
--- developers/werner/myroot/werner.init	                        (rev 0)
+++ developers/werner/myroot/werner.init	2008-11-14 10:29:34 UTC (rev 4786)
@@ -0,0 +1,37 @@
+#!/bin/sh
+PATH=/sbin:/bin/:/usr/bin:/usr/local/bin
+
+ldconfig
+mod_dir=/lib/modules/`uname -r`
+mkdir -p $mod_dir
+touch $mod_dir/modules.dep
+
+# mounts
+>/etc/fstab
+mount -t proc none /proc
+mount -t sysfs none /sys
+mount -t tmpfs none /tmp
+
+# devices and sshd
+mount -t tmpfs none /dev
+mknod /dev/null c 1 3
+mknod /dev/tty c 5 0
+mknod /dev/ttySAC2 c 204 66
+mkdir /dev/pts
+mount -t devpts none /dev/pts
+( udevd --daemon; udevtrigger && udevsettle && /usr/sbin/sshd ) &
+
+# network
+ifconfig usb0 192.168.0.202 up
+route add default gw 192.168.0.200
+
+# X
+TSLIB_TSDEVICE=/dev/input/touchscreen0
+export TSLIB_TSDEVICE
+
+# shell
+PS1='con:\w\$ '
+HOME=/home/root
+cd $HOME
+export PS1 HOME
+exec setsid /bin/bash -l </dev/ttySAC2 >/dev/ttySAC2 2>&1


Property changes on: developers/werner/myroot/werner.init
___________________________________________________________________
Name: svn:executable
   + *




More information about the commitlog mailing list