r1172 - trunk/src/host/devirginator
werner at sita.openmoko.org
werner at sita.openmoko.org
Thu Mar 1 11:01:59 CET 2007
Author: werner
Date: 2007-03-01 11:01:03 +0100 (Thu, 01 Mar 2007)
New Revision: 1172
Added:
trunk/src/host/devirginator/config.werner
trunk/src/host/devirginator/crc32.pl
trunk/src/host/devirginator/envedit.pl
trunk/src/host/devirginator/environment.in
trunk/src/host/devirginator/openocd.in
trunk/src/host/devirginator/openocdcmd.pl
Modified:
trunk/src/host/devirginator/README
trunk/src/host/devirginator/config.example
trunk/src/host/devirginator/scriptify.pl
trunk/src/host/devirginator/setup.sh
trunk/src/host/devirginator/u-boot.in
Log:
Next iteration. Stage 0 and stage 1 should work. Documentation is still
incomplete. Needs OpenOCD delay patch.
Modified: trunk/src/host/devirginator/README
===================================================================
--- trunk/src/host/devirginator/README 2007-03-01 09:12:51 UTC (rev 1171)
+++ trunk/src/host/devirginator/README 2007-03-01 10:01:03 UTC (rev 1172)
@@ -1,18 +1,95 @@
Devirginator
============
-This collection of scripts initializes a "virgin" device. At the moment, this
-goes as far as allowing it to boot into u-boot, from where the rest will be
-done with DFU.
+This collection of scripts initializes a "virgin" device. It erases the
+NAND and installs u-boot, the Linux kernel, and the root file system.
+
+Quick start
+===========
+
First,
% cp config.example config
-and may changes as needed. Then
+and may changes as needed. In particular, you must set SNAPSHOT.
+Then
% make
This requires Netpbm and transfig. Finally, make sure that openocd runs,
-power device up and run
+power the device up and run
% ./devirginate
+
+Files
+=====
+
+
+Scripts
+-------
+
+- openocdcmd.pl
+- scriptify.pl
+- crc32.pl
+- envedit.pl
+- setup.sh
+
+User configuration
+------------------
+
+Static configuration files
+--------------------------
+
+The following files contain scripts and other "static" configuration
+information that is used in the devirgination process. In general,
+it is only necessary to edit these files when changing functionality
+of the setup process.
+
+Each of these files is converted in some way by setup.sh. Below, we
+indicate the name of the respective resulting file after the arrow.
+
+- openocd.in -> tmp/script.ocd
+ Commands to execute by OpenOCD in phase 0. To perform variable
+ expansion, each line of this file is processed by the shell with
+ eval "echo $line". Due to this, shell meta-characters should be
+ avoided.
+
+ If changing any addresses in openocd.in, you also need to update
+ u-boot.in.
+
+- u-boot.in -> tmp/u-boot.out
+ Commands to execute in u-boot during stage 0. This file is converted
+ to an image understood by u-boot, and then executed from memory with
+ u-boot's "autoscr" command.
+
+- environment.in -> tmp/environment
+ Environment settings for the regular u-boot environment. Note that
+ the changes in this file are made on top of the interim environment
+ produced in stage 0. In particular, the "mtdparts" variable is
+ retained from that stage.
+
+- smiley.fig -> tmp/smiley.gz
+ The stage 0 splash screen, a smiling face on a green background.
+
+
+Download cache
+--------------
+
+- tmp/System_boot.png -> tmp/splash.gz
+- tmp/openmoko-devel-image-*.rootfs.jffs2
+- tmp/lowlevel_foo-*.bin
+- tmp/u-boot-*.bin
+- tmp/uImage-*.bin
+
+- tmp/env.old
+- tmp/env.new
+- tmp/preboot_override
+- tmp/preboot_override.noscrub
+- tmp/preboot_override.scrub
+
+
+Scripts
+-------
+
+
+
The first few messages should look like this:
Open On-Chip Debugger
> script /home/moko/om/trunk/src/host/devirginator/tmp/script.ocd
@@ -32,10 +109,64 @@
- pull and then replace the USB plug of the JTAGkey or debug v2 board
- start openocd
-The whole procedure takes a bit longer than two minutes. Rough timeline
-(numbers are guessed and may be off by some 30 seconds):
-00:00 screen goes dark
-00:35 small tux logo with superimposed u-boot version string appears
-02:00 screen briefly goes dark
-02:02 smiley on green background appears
+Stages
+======
+
+
+Stage 0
+-------
+
+If the NAND bad block table is invalid, it can be erased at the beginning
+of stage 1. We call this "stage 0".
+
+In general, this is not a desirable option, because if the last NAND blocks
+are defective, this information will be lost, and unreliable operation may
+result. By default, stage 0 is not performed.
+
+
+Stage 1
+-------
+
+Immediately after starting, the screen lights up, showing random junk.
+This is an indication that the setup process has started. Note that the
+screen content may change ("decay") during all this. This is normal.
+
+After 10-30 seconds, the screen will go dark. This indicates that we
+now a have u-boot running on the device.
+
+About 60-90 seconds later, the screen will light up again and show a
+smiling face on a green background. This indicates that the first stage
+has completed. The smiling face will appear each time you activate the
+device.
+
+The device now contains:
+- a bad block table (BBT)
+- u-boot, with DFU capability
+- a basic set of u-boot environment variables
+- the interim splash screen
+
+What is still missing:
+- the Linux kernel
+- the root file system
+- the final environment
+- the final splash screen
+
+
+Stage 2
+-------
+
+To begin phase 2, activate the device. The stage 1 smiley will show.
+
+Phase 2 can take several minutes. Progress of the download procedure
+is indicated by hash signs (#) printed on the terminal where
+"devirginate" runs.
+
+At the end of phase 2, the device turns off. When you switch it on
+again, it will show the OpenMoko splash screen and boot into Linux.
+
+
+Stage 3
+-------
+
+TBD.
Modified: trunk/src/host/devirginator/config.example
===================================================================
--- trunk/src/host/devirginator/config.example 2007-03-01 09:12:51 UTC (rev 1171)
+++ trunk/src/host/devirginator/config.example 2007-03-01 10:01:03 UTC (rev 1172)
@@ -1,9 +1,94 @@
#
-# config - devirginator configuration
+# config.example - Devirginator configuration example
#
# This is a shell script sourced by "setup.sh".
#
+# WARNING: you must run setup.sh each time this configuration changes !
+#
-OPENOCD_HOST=fs
-LOWLEVEL=$OMDIR/u-boot/board/neo1973/lowlevel_foo.bin
-UBOOT=$OMDIR/u-boot/u-boot.bin
+#
+# Note: you some configuration is required. At the very minimum, you MUST set
+# the SNAPSHOT variable.
+#
+
+### SYSTEM ENVIRONMENT ######################################################
+
+# OPENOCD_HOST: the host on which the OpenOCD daemon runs.
+# Default:
+# OPENOCD_HOST=localhost
+
+# OPENOCD_PORT: the port on which we connect to to the OpenOCD daemon.
+# Default:
+# OPENOCD_PORT=4444
+
+# DFU_UTIL: command that invokes the DFU utility.
+# Default:
+# DFU_UTIL=dfu-util
+
+
+### TARGET PLATFORM #########################################################
+
+# PLATFORM: name of the platform we're flashing.
+# Valid names:
+# gta01 The Neo1973
+# Default:
+# PLATFORM=gta01
+
+# BOARD: the hardware version of the device we're flashing.
+# Valid names:
+# bv2 Unreleased development version
+# bv3 Phase 0 ?
+# v3 Phase 0 ?
+# v4 Phase 1 ?
+# Default:
+# BOARD=bv3
+
+
+### DOWNLOAD LOCATION #######################################################
+
+# SNAPSHOT: date code of the snapshot. This is usually a string of eight
+# decimal digits of the form yyyymmdd. There is no default value for this.
+# Example:
+# SNAPSHOT=20070226
+
+# RELEASE_DIR: directory containing all the files pertaining to the snapshot.
+# The definition of RELEASE_DIR can include variables, but note that they must
+# be set _before_ defining RELEASE_DIR.
+# Default:
+# RELEASE_DIR=http://buildhost.openmoko.org/releases/${PLATFORM}-${SNAPSHOT}/tmp/deploy/images
+
+
+### FINE-TUNING #############################################################
+
+# The location of each item can be explicitly set. If they point to a file, we
+# will use just that file (without making a copy). If they are URLs, setup.sh
+# will download the file to tmp/ and we will use that copy. If no location is
+# set for an item, setup.sh will get it from the RELEASE_DIR above.
+
+# LOWLEVEL: the lowlevel_foo.bin file (initializes the hardware for loading
+# the u-boot boot loader via JTAG)
+# Example:
+# LOWLEVEL=$OMDIR/u-boot/board/neo1973/lowlevel_foo.bin
+
+# UBOOT: the boot loader
+# Example:
+# UBOOT=$OMDIR/u-boot/u-boot.bin
+
+# UIMAGE: the kernel image, with an image header recognized by u-boot.
+# Example:
+# UIMAGE=$OMDIR/build/tmp/deploy/images/uImage-2.6-200702241944-fic-gta01-20070224194345.bin
+
+# MODULES: the kernel modules, as gzip'ed tar file.
+# Example:
+# MODULES=$OMDIR/build/tmp/deploy/images/modules-2.6-200702241944-fic-gta01.tgz
+
+# ROOTFS: the root file system, in jffs2 format.
+# Example:
+# ROOTFS=$OMDIR/build/tmp/deploy/images/openmoko-devel-image-fic-gta01-20070212015815.rootfs.jffs2
+
+# SPLASH: the splash screen, in 480x640 PNG format.
+# Default:
+# SPLASH=http://wiki.openmoko.org/images/c/c2/System_boot.png
+
+
+### END #####################################################################
Added: trunk/src/host/devirginator/config.werner
===================================================================
--- trunk/src/host/devirginator/config.werner 2007-03-01 09:12:51 UTC (rev 1171)
+++ trunk/src/host/devirginator/config.werner 2007-03-01 10:01:03 UTC (rev 1172)
@@ -0,0 +1,27 @@
+#
+# config.werner - Werner's devirginator configuration
+#
+# This is a shell script sourced by "setup.sh".
+#
+
+OPENOCD_HOST=fs
+SNAPSHOT=20070226
+BOARD=bv2
+DFU_UTIL=$OMDIR/openmoko/trunk/src/host/dfu-util/src/dfu-util
+UBOOT=$OMDIR/u-boot/u-boot.bin
+
+#
+# This is a developer's setup, thus only items I don't want to change are taken
+# from the snapshot, while the rest is local. Explanations:
+#
+# OPENOCD_HOST: I sometimes run "devirginate" from a different host, thus I
+# need to specify where OpenOCD is running.
+#
+# SNAPSHOT: mandatory choice of the snapshot version.
+#
+# BOARD: still doing most of my testing on bv2.
+#
+# DFU_UTIL: local copy from SVN.
+#
+# UBOOT: from my local tree.
+#
Added: trunk/src/host/devirginator/crc32.pl
===================================================================
--- trunk/src/host/devirginator/crc32.pl 2007-03-01 09:12:51 UTC (rev 1171)
+++ trunk/src/host/devirginator/crc32.pl 2007-03-01 10:01:03 UTC (rev 1172)
@@ -0,0 +1,46 @@
+#!/usr/bin/perl
+#
+# crc32.pl - Straightforward and very slow CRC32 implementation
+#
+# Copyright (C) 2006-2007 by OpenMoko, Inc.
+# Written by Werner Almesberger <werner at openmoko.org>
+# All Rights Reserved
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+#
+# For details, see
+# http://en.wikipedia.org/w/index.php?title=Cyclic_redundancy_check&oldid=110823112
+#
+
+sub crc32
+{
+ local ($s) = @_;
+ local ($poly, $crc) = (0xedb88320, ~0);
+ local ($i, $j);
+
+ for ($i = 0; $i != length $s; $i++) {
+ for ($j = 0; $j != 8; $j++) {
+ if (($crc ^ (unpack("C", substr($s, $i, 1)) >> $j)) & 1) {
+ $crc = ($crc >> 1) ^ $poly;
+ }
+ else {
+ $crc = $crc >> 1;
+ }
+ }
+ }
+ return ~$crc;
+}
Added: trunk/src/host/devirginator/envedit.pl
===================================================================
--- trunk/src/host/devirginator/envedit.pl 2007-03-01 09:12:51 UTC (rev 1171)
+++ trunk/src/host/devirginator/envedit.pl 2007-03-01 10:01:03 UTC (rev 1172)
@@ -0,0 +1,190 @@
+#!/usr/bin/perl
+#
+# envedit.pl - U-Boot environment editor
+#
+# Copyright (C) 2006-2007 by OpenMoko, Inc.
+# Written by Werner Almesberger <werner at openmoko.org>
+# All Rights Reserved
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+
+do 'crc32.pl';
+
+
+$ENV_SIZE = 0x4000;
+
+
+sub usage
+{
+ print STDERR
+"usage: $0 [-i file] [-o file|-p] [-f env_file] [var=[value] ...]\n".
+" -i file read environment from file (default: use empty environment)\n".
+" -o file write environment to file (default: write to stdout)\n".
+" -p print environment in human-readable form to stdout\n".
+" -f env_file read changes from env_file\n".
+" var= remove the specified variable\n".
+" var=value set the specified variable\n";
+ exit(1);
+}
+
+
+sub readenv
+{
+ local ($file) = @_;
+ local ($crc, $env, $want);
+
+ open(FILE, $file) || die "$file: $!";
+ $env = join("", <FILE>);
+ close FILE;
+ if (length $env != $ENV_SIZE) {
+ print STDERR sprintf("warning: environment is %d bytes, expected %d\n",
+ length $env, $ENV_SIZE);
+ $env = substr($env, 0, $ENV_SIZE);
+ $env .= '\000' x ($ENV_SIZE-length $env);
+ }
+ ($crc, $env) = unpack("Va*", $env);
+ $want = &crc32($env);
+ if ($crc != $want) {
+ print STDERR sprintf("CRC error: expected 0x%08x, got 0x%08x\n",
+ $want, $crc);
+ exit(1);
+ }
+ foreach (split(/\000/, $env)) {
+ last if $_ eq "";
+ if (/^([^=]+)=/) {
+ if ($' eq "") {
+ print STDERR "warning: skipping empty entry for \"$_\"\n";
+ }
+ else {
+ $env{$1} = $';
+ }
+ }
+ else {
+ print STDERR
+ "warning: ignoring invalid environment entry \"$_\"\n";
+ }
+ }
+}
+
+
+sub set
+{
+ return 0 unless $_[0] =~ /^([^=]+)=\s*(.+)?$/;
+
+ local ($var, $value) = ($1, $2);
+
+ if ($value ne "") {
+ $env{$var} = $value;
+ }
+ else {
+ undef $env{$var};
+ }
+ print STDERR
+ "warning: variable name \"$var\" contains invalid characters\n"
+ unless $var =~ /^\w+$/;
+}
+
+
+sub set_err
+{
+ if (!&set($_[0])) {
+ print STDERR "invalid setting \"$_[0]\"\n";
+ exit(1);
+ }
+}
+
+
+while (@ARGV) {
+ if ($ARGV[0] eq "-i") {
+ &usage unless defined $ARGV[1];
+ &readenv($ARGV[1]);
+ shift(@ARGV);
+ shift(@ARGV);
+ }
+ elsif ($ARGV[0] eq "-o") {
+ &usage if defined $printenv;
+ &usage unless defined $ARGV[1];
+ shift(@ARGV);
+ $outfile = shift(@ARGV);
+ }
+ elsif ($ARGV[0] eq "-p") {
+ &usage if defined $outfile;
+ $printenv = 1;
+ shift(@ARGV);
+ }
+ elsif ($ARGV[0] eq "-f") {
+ &usage unless defined $ARGV[1];
+ shift(@ARGV);
+ $file = shift(@ARGV);
+ undef $line;
+ open(FILE, $file) || die "$file: $!";
+ while (<FILE>) {
+ chop;
+ s/#.*//;
+ s/\s*$//;
+ next if /^\s*$/;
+ if (/^\s+/) {
+ if (!defined $line) {
+ print STDERR "first line cannot be a continuation\n";
+ exit(1);
+ }
+ $line .= " ".$';
+ }
+ else {
+ &set_err($line) if defined $line;
+ $line = $_;
+ }
+ }
+ close FILE;
+ &set_err($line) if defined $line;
+ }
+ elsif (&set($_)) {
+ shift(@ARGV);
+ }
+ else {
+ &usage;
+ }
+}
+
+
+if ($printenv) {
+ foreach (sort { $a cmp $b } keys %env) {
+ print "$_=$env{$_}\n" if defined $env{$_};
+ }
+}
+else {
+ foreach (sort { $a cmp $b } keys %env) {
+ $env .= "$_=$env{$_}\0" if defined $env{$_};
+ }
+ if (length $env > $ENV_SIZE-5) {
+ # leave room for CRC and terminating \000
+ print STDERR sprintf("environment too big (%d > %d)\n",
+ length $env, $ENV_SIZE-5);
+ exit(1);
+ }
+ $env .= "\000" x ($ENV_SIZE-4-length $env);
+ $crc = &crc32($env);
+ $env = pack("V", $crc).$env;
+ if (defined $outfile) {
+ open(FILE, ">$outfile") || die "$outfile: $!";
+ print FILE $env || die "$outfile: $!";
+ close(FILE) || die "$outfile: $!";
+ }
+ else {
+ print $env || die "print: $!";
+ }
+}
Property changes on: trunk/src/host/devirginator/envedit.pl
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/src/host/devirginator/environment.in
===================================================================
--- trunk/src/host/devirginator/environment.in 2007-03-01 09:12:51 UTC (rev 1171)
+++ trunk/src/host/devirginator/environment.in 2007-03-01 10:01:03 UTC (rev 1172)
@@ -0,0 +1,47 @@
+#
+# environment - The default environment
+#
+
+bootargs_base=
+ rootfstype=jffs2
+ root=/dev/mtdblock4
+ console=ttySAC0,115200
+ console=tty0
+ loglevel=8
+ mtdids=nand0=neo1973-nand
+
+bootcmd=
+ setenv bootargs ${bootargs_base} ${mtdparts};
+ nand read.e 0x32000000 kernel;
+ bootm 0x32000000
+
+bootdelay=1
+
+splashimage=
+ nand read.e 0x32000000 splash 0x5000;
+ unzip 0x32000000 0x33d00000 0x96000
+
+#menu_1=
+# Boot from microSD:
+# setenv bootargs rootfstype=
+# mmcinit;
+# ext2load mmc 0 0x32000000 uImage;
+# bootm 0x32000000
+
+menu_1=
+ Set console to USB:
+ setenv stdin usbtty;
+ setenv stdout usbtty;
+ setenv stderr usbtty;
+ saveenv
+
+menu_2=
+ Set console to serial:
+ setenv stdin serial;
+ setenv stdout serial;
+ setenv stderr serial;
+ saveenv
+
+menu_3=
+ Power off:
+ neo1973 power-off
Added: trunk/src/host/devirginator/openocd.in
===================================================================
--- trunk/src/host/devirginator/openocd.in 2007-03-01 09:12:51 UTC (rev 1171)
+++ trunk/src/host/devirginator/openocd.in 2007-03-01 10:01:03 UTC (rev 1172)
@@ -0,0 +1,49 @@
+#
+# openocd.in - Commands to load and run u-boot and companion files for setup
+#
+
+#
+# Memory map:
+#
+# 0x33FFFFFF end of RAM
+# 0x33F80000 u-boot
+# 0x33D00000 frame buffer
+# 0x32300000 interim logo
+# 0x32200000 u-boot command script
+# 0x32100000 preboot_override command string
+# 0x32000000 u-boot load area
+# 0x30000000 start of RAM
+# 0x00000000 lowlevel_foo.bin load area
+#
+
+# reset and wait until the target responds
+reset halt
+wait_halt
+sleep 2000
+
+# turn on the backlight
+mww 0x56000010 0x1
+mww 0x56000014 1
+
+# load and run the low-level hardware setup
+load_binary $LOWLEVEL 0
+bp 0x33f80000 4 hw
+resume
+wait_halt
+rbp 0x33f80000
+
+# load u-boot, the initial command, the command script, and the smiley
+load_binary $UBOOT 0x32000000
+load_binary $PWD/tmp/preboot_override 0x32100000
+load_binary $PWD/tmp/u-boot.out 0x32200000
+load_binary $PWD/tmp/smiley.gz 0x32300000
+
+# enable the initial command
+mww 0x32000040 0x32100000
+
+# run
+bp 0 4 hw
+resume 0x32000000
+wait_halt
+rbp 0
+resume
Added: trunk/src/host/devirginator/openocdcmd.pl
===================================================================
--- trunk/src/host/devirginator/openocdcmd.pl 2007-03-01 09:12:51 UTC (rev 1171)
+++ trunk/src/host/devirginator/openocdcmd.pl 2007-03-01 10:01:03 UTC (rev 1172)
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+#
+# openocdcmd.pl - Send commands to OpenOCD through the telnet interface
+#
+# Copyright (C) 2006-2007 by OpenMoko, Inc.
+# Written by Werner Almesberger <werner at openmoko.org>
+# All Rights Reserved
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+
+sub usage
+{
+ print STDERR "usage: $0 host port command ...\n";
+ exit(1);
+}
+
+
+&usage unless $#ARGV >= 2;
+
+$host = shift @ARGV;
+$port = shift @ARGV;
+
+open(PIPE,"| telnet $host $port") || die "telnet: $!";
+
+# make the pipe unbuffered
+
+$old = select PIPE;
+$| = 1;
+select $old;
+
+while (defined $ARGV[0]) {
+ print PIPE "$ARGV[0]\n";
+ shift @ARGV;
+}
+
+# wait until telnet closes the pipe
+
+vec($ein, fileno(PIPE), 1) = 1;
+$n = select($ein, undef, $ein, undef);
+if ($n < 0) {
+ print "select: $!";
+ exit(1);
+}
+
+close PIPE;
Property changes on: trunk/src/host/devirginator/openocdcmd.pl
___________________________________________________________________
Name: svn:executable
+ *
Modified: trunk/src/host/devirginator/scriptify.pl
===================================================================
--- trunk/src/host/devirginator/scriptify.pl 2007-03-01 09:12:51 UTC (rev 1171)
+++ trunk/src/host/devirginator/scriptify.pl 2007-03-01 10:01:03 UTC (rev 1172)
@@ -21,8 +21,10 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
-use Archive::Zip;
+do 'crc32.pl';
+
+
while (<>) {
s/#.*//;
next if /^\s*$/;
@@ -32,7 +34,7 @@
$cmd .= pack("c",0);
$cmd = pack("NN",length $cmd,0).$cmd;
-$crc = Archive::Zip::computeCRC32($cmd,0);
+$crc = &crc32($cmd);
$hdr = pack("NNNNNNNcccca32",
0x27051956, # ih_magic (IH_MAGIC)
@@ -48,7 +50,7 @@
0, # ih_comp (IH_COMP_NONE)
"script"); # ih_name
-$crc = Archive::Zip::computeCRC32($hdr,0);
+$crc = &crc32($hdr);
substr($hdr,4,4) = pack("N",$crc);
Modified: trunk/src/host/devirginator/setup.sh
===================================================================
--- trunk/src/host/devirginator/setup.sh 2007-03-01 09:12:51 UTC (rev 1171)
+++ trunk/src/host/devirginator/setup.sh 2007-03-01 10:01:03 UTC (rev 1172)
@@ -21,54 +21,265 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
+
+mkdir -p tmp
+
+
+# --- Functions ---------------------------------------------------------------
+
+
+download()
+{
+ index=tmp/index-${SNAPSHOT}.html
+ if [ ! -f $index ]; then
+ wget -O tmp/index "`dirname \"$2\"`/"
+ mv tmp/index $index
+ fi
+ n="`basename \"$2\" | sed 's/*/[-a-zA-Z0-9_.]*/g'`"
+ sed '/^.*[^-a-zA-Z0-9_.]\('"$n"'\)[^-a-zA-Z0-9_.].*$/s//\1/p;d' \
+ <$index >tmp/files
+ case `grep -c '' tmp/files` in
+ 0) echo "not found: $2" 1>&2
+ exit 1;;
+ 1) n="`dirname \"$2\"`/`cat tmp/files`";;
+ *) echo "too many files: $2" 2>&1
+ exit 1;;
+ esac
+ rm -f $index tmp/files
+ base="`basename \"$n\"`"
+ cd tmp
+ wget -N "$n" || { rm -f $base; exit 1; }
+ eval $1=\"$PWD/$base\"
+ cd ..
+}
+
+
+# --- Configuration defaults --------------------------------------------------
+
+
+# System environment
OPENOCD_HOST=localhost
OPENOCD_PORT=4444
-UBOOTDIR=${OMDIR:-/home/moko}/u-boot
-LOWLEVEL=$UBOOTDIR/board/neo1973/lowlevel_foo.bin
-UBOOT=$UBOOTDIR/u-boot.bin
+DFU_UTIL=dfu-util
+# Target platform
+PLATFORM=gta01
+BOARD=bv3
+
+# Locations
+SPLASH=http://wiki.openmoko.org/images/c/c2/System_boot.png
+
+for n in "$@"; do
+ eval "$n"
+done
+
+
+# --- Read config file --------------------------------------------------------
+
+
. config
-cat <<EOF >tmp/script.ocd
-reset halt
-wait_halt
-load_binary $LOWLEVEL 0
-bp 0x33f80000 4 hw
-resume
-wait_halt
-rbp 0x33f80000
-load_binary $UBOOT 0x32000000
-load_binary $PWD/tmp/preboot_override 0x32100000
-load_binary $PWD/tmp/u-boot.out 0x32200000
-load_binary $PWD/tmp/smiley.gz 0x32300000
-mww 0x32000040 0x32100000
-resume 0x32000000
-exit
+
+# --- Post configuration ------------------------------------------------------
+
+
+if [ -z "$RELEASE_DIR" ]; then
+ RELEASE_DIR=http://buildhost.openmoko.org/releases/
+ RELEASE_DIR=${RELEASE_DIR}/${PLATFORM}-${SNAPSHOT}/tmp/deploy/images
+fi
+
+# lowlevel_foo.bin
+
+if [ -z "$LOWLEVEL" ]; then
+ LOWLEVEL=${RELEASE_DIR}/lowlevel_foo-${PLATFORM}${BOARD}-'*'.bin
+fi
+if [ ! -f "$LOWLEVEL" ]; then
+ download LOWLEVEL "$LOWLEVEL"
+fi
+
+# u-boot.bin
+
+if [ -z "$UBOOT" ]; then
+ UBOOT=${RELEASE_DIR}/u-boot-${PLATFORM}${BOARD}-'*'.bin
+fi
+if [ ! -f "$UBOOT" ]; then
+ download UBOOT "$UBOOT"
+fi
+
+# uImage.bin
+
+if [ -z "$UIMAGE" ]; then
+ UIMAGE=${RELEASE_DIR}/uImage-2.6-'*'-fic-${PLATFORM}-'*'.bin
+fi
+if [ ! -f "$UIMAGE" ]; then
+ download UIMAGE "$UIMAGE"
+fi
+
+## # modules.tar.gz
+##
+## if [ -z "$MODULES" ]; then
+## MODULES=${RELEASE_DIR}/modules-2.6-'*'-fic-${PLATFORM}.tgz
+## fi
+## if [ ! -f "$MODULES" ]; then
+## download MODULES "$MODULES"
+## fi
+##
+## # rootfs.tar.gz
+##
+## if [ -z "$ROOTFS" ]; then
+## ROOTFS=${RELEASE_DIR}/openmoko-devel-image-fic-${PLATFORM}-'*'.rootfs.tar.gz
+## fi
+## if [ ! -f "$ROOTFS" ]; then
+## download ROOTFS "$ROOTFS"
+## fi
+
+# rootfs.jffs2
+
+if [ -z "$ROOTFS" ]; then
+ ROOTFS=${RELEASE_DIR}/openmoko-devel-image-fic-${PLATFORM}-'*'.rootfs.jffs2
+fi
+if [ ! -f "$ROOTFS" ]; then
+ download ROOTFS "$ROOTFS"
+fi
+
+
+# Splash screen
+
+if [ ! -f "$SPLASH" ]; then
+ download SPLASH "$SPLASH"
+fi
+
+
+# --- Stage 1: OpenOCD script -------------------------------------------------
+
+
+{
+ while read l; do
+ eval "echo $l"
+ done
+} <openocd.in >tmp/script.ocd
+
+
+# --- Stage 1: First u-boot command(s) ----------------------------------------
+
+
+sed 's/#.*//;/^ *$/d' <<EOF | tr '\n' ';' | tr '!' '\000' \
+ >tmp/preboot_override.scrub
+setenv scrub true; autoscr 0x32200000!
EOF
-sed 's/#.*//;/^ *$/d' <<EOF | tr '\n' ';' | tr '!' '\000' >tmp/preboot_override
+
+sed 's/#.*//;/^ *$/d' <<EOF | tr '\n' ';' | tr '!' '\000' \
+ >tmp/preboot_override.noscrub
autoscr 0x32200000!
EOF
+
+# --- Stage 1: u-boot script --------------------------------------------------
+
+
perl ./scriptify.pl u-boot.in >tmp/u-boot.out
+
+# --- Stage 1: smiley splash screen -------------------------------------------
+
export OMDIR
make smiley.gz
mv smiley.gz tmp/
rm -f smiley.png smiley.ppm
+
+# --- Stage 2: the default environment ----------------------------------------
+
+
+cp environment.in tmp/environment
+
+
+# --- Stage 2: official splash screen -----------------------------------------
+
+
+../splash/splashimg.pl "$SPLASH" | gzip -9 >tmp/splash.gz
+
+
+# --- "devirginate" shell script ----------------------------------------------
+
+
cat <<EOF >devirginate
-#!/bin/sh
+#!/bin/sh -e
# MACHINE-GENERATED. DO NOT EDIT !
echo ===== STARTING ===========================================================
+
+stage0=false
+stage1=false
+stage2=false
+stage3=false
+all=true
+
+usage()
{
- echo script $PWD/tmp/script.ocd
- sleep 120
-} | telnet $OPENOCD_HOST $OPENOCD_PORT
-echo ===== CONTINUING IN THE BACKGROUND =======================================
+ echo "usage: \$0 [[-0] -1] [-2] [-3]" 1>&2
+ exit 1
+}
+
+while [ ! -z "\$1" ]; do
+ case "\$1" in
+ -0) stage0=true
+ all=false;;
+ -1) stage1=true
+ all=false;;
+ -2) stage2=true
+ all=false;;
+ -3) stage3=true
+ all=false;;
+ *) usage;;
+ esac
+ shift
+done
+
+if \$all; then
+ stage1=true
+ stage2=true
+ stage3=true
+fi
+
+if \$stage0 && ! \$stage1; then
+ usage
+fi
+
+if \$stage1; then
+ echo === STAGE 1: JTAG upload
+ if \$stage0; then
+ ln -sf preboot_override.scrub tmp/preboot_override
+ else
+ ln -sf preboot_override.noscrub tmp/preboot_override
+ fi
+ ./openocdcmd.pl $OPENOCD_HOST $OPENOCD_PORT \
+ "script $PWD/tmp/script.ocd" exit
+fi
+
+if \$stage2; then
+ echo === STAGE 2: DFU upload
+ sleep 5
+ $DFU_UTIL -a 3 -D $UIMAGE
+ $DFU_UTIL -a 5 -D $ROOTFS
+ $DFU_UTIL -a 4 -D tmp/splash.gz
+ $DFU_UTIL -a 2 -U tmp/env.old
+ ./openocdcmd.pl $OPENOCD_HOST $OPENOCD_PORT \
+ "bp 0x33f80000 4 hw" reset wait_halt "rbp 0x33f80000" resume exit
+ sleep 5
+ ./envedit.pl -i tmp/env.old -o tmp/env.new -f tmp/environment
+ $DFU_UTIL -a 2 -D tmp/env.new
+ ./openocdcmd.pl $OPENOCD_HOST $OPENOCD_PORT "reset run" exit
+fi
+
+echo ===== DONE ===============================================================
EOF
chmod +x devirginate
+
+# --- Done --------------------------------------------------------------------
+
+
cat <<EOF
-------------------------------------------------------------------------------
@@ -79,7 +290,7 @@
- connect it to power and JTAG
- switch it on
- run ./devirginate
-- wait until the smiley appears (takes about one minute)
+- wait until the smiley appears (takes about 1-2 minutes)
-------------------------------------------------------------------------------
EOF
Modified: trunk/src/host/devirginator/u-boot.in
===================================================================
--- trunk/src/host/devirginator/u-boot.in 2007-03-01 09:12:51 UTC (rev 1171)
+++ trunk/src/host/devirginator/u-boot.in 2007-03-01 10:01:03 UTC (rev 1172)
@@ -6,13 +6,20 @@
# interactive testing one may wish to do.
#
+# switch on the backlight, so one can see that we're alive
+
+neo1973 backlight off
+
# we're non-interactive
setenv dontask y
# remove any pre-existing bad block table and create a new one
-nand scrub 0x3ff0000 0x10000
+setenv scrub_true nand scrub 0x3ff0000 0x10000
+setenv scrub_ echo Not scrubbing
+run scrub_${scrub}
+
nand createbbt
# create the partition table
@@ -30,6 +37,12 @@
# set up the pre-DFU environment (604800 seconds is one week)
dynenv set u-boot_env
+
+setenv dontask
+setenv scrub_true
+setenv scrub_
+setenv scrub
+
setenv bootcmd
setenv bootdelay 604800
setenv splashimage nand read.e 0x32000000 splash 0x1000\; unzip 0x32000000 0x33d00000 0x96000
More information about the commitlog
mailing list