r4803 - developers/werner/myroot
werner at docs.openmoko.org
werner at docs.openmoko.org
Thu Nov 20 00:41:20 CET 2008
Author: werner
Date: 2008-11-20 00:41:20 +0100 (Thu, 20 Nov 2008)
New Revision: 4803
Added:
developers/werner/myroot/mkext2
developers/werner/myroot/mksd
Modified:
developers/werner/myroot/README
developers/werner/myroot/myroot
developers/werner/myroot/werner.init
developers/werner/myroot/werner.myroot
Log:
Support for making a bootable SD card image.
- werner.init: remount root read-write, in case we booted from microSD
- myroot: create /etc/fstab, so that we can remount root
- mkext2: create an ext2 file system image
- mksd: make a bootable SD card image (u-boot and GTA02 only for now)
- README: added warnings that we require root and that this is currently for
GTA02 only
- README: described how to make a bootable SD card image
- werner.myroot: we had tcptraceroute and traceroute. Remove the latter.
Modified: developers/werner/myroot/README
===================================================================
--- developers/werner/myroot/README 2008-11-19 20:44:33 UTC (rev 4802)
+++ developers/werner/myroot/README 2008-11-19 23:41:20 UTC (rev 4803)
@@ -1,6 +1,8 @@
*** WORK IN PROGRESS - USE AT YOUR OWN PERIL ! ***
+*** GTA02 ONLY FOR NOW ! ***
+
What does it do ?
=================
@@ -21,6 +23,12 @@
How to use this
===============
+
+Note: all the scripts described below perform operations that require
+root privileges. It's best to operate them from a root shell, e.g.
+% sudo /bin/bash
+
+
Customization
-------------
@@ -28,10 +36,10 @@
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 script "werner.myroot" 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:
@@ -54,8 +62,12 @@
Just run
-./myroot <customization_script>
+# ./myroot <customization_script>
+Example:
+
+# ./myroot werner.myroot
+
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.
@@ -69,19 +81,45 @@
customization script.
-Making a filesystem image
--------------------------
+Making a JFFS2 filesystem image
+-------------------------------
A GTA02 JFFS2 image can be generated with
-./mkjffs2
+# ./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
+# dfu-util -a rootfs -D root.jffs2
+Making a bootable SD card image (u-boot)
+----------------------------------------
+
+First, we generate an ext2 image:
+
+# ./mkext2
+
+The image is placed in the file root.ext2
+
+Next, we make a bootable SD card. For this, we also need a kernel.
+Let's assume it is in /home/moko/uImage. Then the invocation would
+be as follows:
+
+# ./mksd -u uImage
+
+After a screenful of diagnostics, errors, and warnings, the result is
+in the file sd_image.
+
+It can be copied directly to an SD card in a card reader attached to
+the host, or it can be copied to the SD card in a Neo with
+
+% ssh neo 'umount /dev/mmcblk0p*'
+% ssh neo 'cat >/dev/mmcblk0' <sd_image
+% ssh neo blockdev --rereadpt /dev/mmcblk0
+
+
Bugs and future improvements
============================
Added: developers/werner/myroot/mkext2
===================================================================
--- developers/werner/myroot/mkext2 (rev 0)
+++ developers/werner/myroot/mkext2 2008-11-19 23:41:20 UTC (rev 4803)
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+dir=${1:-root}
+name="`basename $dir`"
+
+spare=${2:-0}
+
+if [ ! -d "$dir" ]; then
+ echo "usage: $0 [dirname [spare_MB]]" 1>&2
+ exit 1
+fi
+
+rm -f $name.ext2
+[ ! -d _mnt ] || umount _mnt
+
+#
+# We always leave 10% of empty space. In reality, the file system we create is
+# probably smaller than the original one, but better safe than sorry.
+#
+blocks=`du -sk "$dir" | awk '{ print $1 }'`
+blocks=`expr $blocks \* 11 / 10 + \( $spare + 999 \) / 1000`
+
+# create the FS
+
+>$name.ext2
+mke2fs -q -m 0 -F -b 1024 $name.ext2 $blocks
+tune2fs -c 0 -i 0 root.ext2
+
+# populate it
+
+mkdir -p _mnt
+mount -o loop $name.ext2 _mnt
+cp -a root/* _mnt/
+umount _mnt
+
+# clean up
+
+rmdir _mnt
Property changes on: developers/werner/myroot/mkext2
___________________________________________________________________
Name: svn:executable
+ *
Added: developers/werner/myroot/mksd
===================================================================
--- developers/werner/myroot/mksd (rev 0)
+++ developers/werner/myroot/mksd 2008-11-19 23:41:20 UTC (rev 4803)
@@ -0,0 +1,123 @@
+#!/bin/sh
+
+
+sd_image()
+{
+ heads=32
+ secs=63
+ cyl_kb=`expr $heads \* $secs / 2`
+ cyl_b=`expr $cyl_kb \* 1024`
+
+ # make the SD image
+
+ (
+ pos=512
+ dd if=/dev/zero bs=512 count=1
+ for n in "$@"; do
+ cat "$n"
+ size=`ls -l "$n" | awk '{ print $5 }'`
+ pos=`expr $pos + $size`
+ next=`expr \( $pos + $cyl_b - 1 \) / $cyl_b \* $cyl_b`
+ pad=`expr $next - $pos`
+ dd if=/dev/zero bs=$pad count=1
+ pos=$next
+ done
+ ) >"$sd"
+
+ first=512
+ for n in "$@"; do
+ size=`ls -l "$n" | awk '{ print $5 }'`
+ echo ,`expr \( $size + $first + $cyl_b - 1 \) / $cyl_b`
+ first=0
+ done | sfdisk --no-reread -q -H $heads -S $secs "$sd"
+}
+
+
+do_qi()
+{
+ # untested
+ # @@@ shouldn't we rather do this in mkext2 ?
+
+ mkdir -p _mount
+ mount -o loop "$fs" _mnt
+ mkdir -p _mnt/boot
+ cp "$kernel" _mnt/boot/uImage-GTA02.bin
+ umont _mnt
+ rm -f _mnt
+
+ sd_image "$fs"
+}
+
+
+do_uboot()
+{
+ # 100kB ought to be enough for FAT's meta-data
+
+ blocks=`ls -ks "$kernel" | awk '{ print $1 }'`
+ blocks=`expr $blocks + 100`
+
+ # create the FS
+
+ dd if=/dev/zero bs=1024 count=$blocks of=_p1
+ mkdosfs _p1
+
+ # populate it
+
+ mkdir -p _mnt
+ mount -o loop -t msdos _p1 _mnt
+ cp "$kernel" _mnt/uImage.bin
+ umount _mnt
+
+ # clean up
+
+ rmdir _mnt
+
+ sd_image _p1 "$fs"
+}
+
+
+usage()
+{
+ echo "usage: $0 [-u] [-o sd_image] kernel [ext2_image]" 1>&2
+ exit 1
+}
+
+
+qi=true
+sd=sd_image
+
+while true; do
+ case "$1" in
+ -u)
+ qi=false;;
+ -o)
+ shift
+ sd="$1";;
+ -*)
+ usage;;
+ *)
+ break;;
+ esac
+ shift
+done
+
+kernel=$1
+[ ! -z "$kernel" ] || usage
+fs=${2:-root.ext2}
+if [ ! -f "$kernel" ]; then
+ echo "$kernel: not found" 1>&2
+ exit 1
+fi
+if [ ! -f "$fs" ]; then
+ echo "$fs: not found" 1>&2
+ exit 1
+fi
+
+rm -f "$sd_image"
+[ ! -d _mnt ] || umount _mnt
+
+if $qi; then
+ do_iq
+else
+ do_uboot
+fi
Property changes on: developers/werner/myroot/mksd
___________________________________________________________________
Name: svn:executable
+ *
Modified: developers/werner/myroot/myroot
===================================================================
--- developers/werner/myroot/myroot 2008-11-19 20:44:33 UTC (rev 4802)
+++ developers/werner/myroot/myroot 2008-11-19 23:41:20 UTC (rev 4803)
@@ -133,6 +133,7 @@
mkdir -p "$root/home/root"
chmod 755 "$root/home" "$root/home/root"
+echo ROOT / auto defaults 0 0 >"$root/etc/fstab"
echo "root::0:0:root:/home/root:/bin/sh" >"$root/etc/passwd"
cp $CONF "$root/etc"
Modified: developers/werner/myroot/werner.init
===================================================================
--- developers/werner/myroot/werner.init 2008-11-19 20:44:33 UTC (rev 4802)
+++ developers/werner/myroot/werner.init 2008-11-19 23:41:20 UTC (rev 4803)
@@ -1,6 +1,9 @@
#!/bin/sh
PATH=/sbin:/bin/:/usr/bin:/usr/local/bin
+# if booting from microSD, rootfs may be read-only
+mount -n -o remount,rw /
+
ldconfig
mod_dir=/lib/modules/`uname -r`
mkdir -p $mod_dir
Modified: developers/werner/myroot/werner.myroot
===================================================================
--- developers/werner/myroot/werner.myroot 2008-11-19 20:44:33 UTC (rev 4802)
+++ developers/werner/myroot/werner.myroot 2008-11-19 23:41:20 UTC (rev 4803)
@@ -22,7 +22,7 @@
pkg udev procps module-init-tools
pkg coreutils grep sed gawk util-linux bash findutils debianutils psmisc
pkg mtd-utils sysfsutils apm
-pkg net-tools iproute2 iputils-ping tcptraceroute openssh ntpdate
+pkg net-tools iproute2 iputils-ping openssh ntpdate
pkg dhcp-client wireless-tools wpa-supplicant
pkg portmap ppp rsync
pkg alsa-state alsa-utils-alsamixer alsa-utils-alsactl alsa-utils-aplay
@@ -64,7 +64,7 @@
pkg tcpdump
-pkg traceroute
+pkg tcptraceroute
make -C $my/ttcp clean all
cp $my/ttcp/ttcp-1.12/ttcp usr/bin
More information about the commitlog
mailing list