#!/bin/bash
#
# uBoot configuration for Debian on the Openmoko FreeRunner (GTA02)
#
# Copyright 2008 Joachim Breitner <nomeata@debian.org>
#
# 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.
#
# 18.08.08: * default boot in quiet-mode for speed
# * added option to boot without quiet-mode for debugging
# (Rorschach)
set -e
echo "This will configure your uboot environment to boot a Debian installation"
echo "It also adds a menu entry to boot the image installed in flash"
echo "Make sure this script runs as root, that uBoot is running on your Freerunner"
echo "And that it is plugged in via usb"
echo
tmpdir=$(mktemp -d -t uboot-env.XXXXXXXXXX)
trap "rm -f $tmpdir/env.orig $tmpdir/env.new $tmpdir/uboot_menu.in ; rmdir $tmpdir" EXIT
cd $tmpdir
cat > uboot_menu.in <<'__END__'
bootcmd=
setenv bootargs
${bootargs_base} ${mtdparts}
rootfstype=ext2 root=/dev/mmcblk0p2 quiet rootdelay=5;
mmcinit;
ext2load mmc 1 0x32000000 ${sd_image_name};
bootm 0x32000000
menu_1=
Boot without quiet-mode:
setenv bootargs
${bootargs_base} ${mtdparts}
rootfstype=ext2 root=/dev/mmcblk0p2 rootdelay=5;
mmcinit;
ext2load mmc 1 0x32000000 ${sd_image_name};
bootm 0x32000000
menu_2=
Boot from Flash:
setenv bootargs
${bootargs_base} ${mtdparts};
nand read.e 0x32000000 kernel 0x200000;
bootm 0x32000000
menu_3=
Reboot:
reset
menu_4=
Power off:
neo1973 power-off
menu_5=
Set console to USB:
setenv stdin usbtty;
setenv stdout usbtty;
setenv stderr usbtty
menu_6=
Set console to serial:
setenv stdin serial;
setenv stdout serial;
setenv stderr serial
menu_7=
menu_8=
__END__
echo Dumping current uboot environment
dfu-util -a u-boot_env -U env.orig
echo "Merging debian menu entries into uboot environment"
uboot-envedit -i env.orig -f uboot_menu.in -o env.new
echo Writing back uboot environment
dfu-util -a u-boot_env -D env.new
echo Done modifying uboot environment
echo
echo Restart and enjoy