H1_under_Qemu: flash-h1.sh

File flash-h1.sh, 5.4 KB (added by zecrazytux, 3 years ago)

flash.sh script for qemu-neo1973 from openmoko, to enable boot from SD

Line 
1#! /usr/bin/env bash
2#
3# Flash virtual openmoko (freerunner) to get a working qemu image
4# adds a boot menu to boot on SD
5# correct uboot (as of 09/01/05, daily one seems to be broken)
6#
7# based on openmoko''s flash.sh script
8
9
10#-----------------------------------------------------------------------
11
12. openmoko/env
13
14# Override env: to correct uboot
15# before flashing: wget http://zecrazytux.net/Bordel/h1/uboot-ok.bin
16# that's the one found into the precompiled qemu binaries for windows
17
18uboot_wildcard="uboot-ok.bin"
19
20#-----------------------------------------------------------------------
21
22
23if [[ "$1" != "" ]]; then
24        img_dir="`(cd \"$1\"; pwd)`"
25else
26        img_dir="$script_dir"
27fi
28
29cd $script_dir
30
31if ! which pngtopnm || ! which ppmtorgb3; then
32        echo Splash needs \'pngtopnm\' and \'ppmtorgb3\' - make \
33                sure that they\'re in \$PATH.
34        exit -1
35fi
36
37${make} splash.gz || exit -1
38
39# Find the most recent OpenMoko images in the current directory.
40# We assume they have numeric date or some build number in their names.
41most_recent () {
42        cd $src_dir
43        export $2="`basename \`ls -d -1 $img_dir/$1 | sort -n | tail -n 1\``"
44        export $3="`python -c \"import os; print '0x%lx' \
45                %(os.stat('$img_dir/${!2}').st_size)\"`"
46        cd $script_dir
47        [ -e "${!2}" ] || ln -sf $img_dir/${!2} ${!2}
48        [ -s "${!2}" ]
49}
50
51most_recent "$kernel_wildcard" kernel_image kernel_size || exit -1
52most_recent "$rootfs_wildcard" rootfs_image rootfs_size || exit -1
53most_recent "$uboot_wildcard" uboot_image uboot_size || exit -1
54
55echo Using \'$kernel_image\' as the kernel image.
56echo Using \'$rootfs_image\' as the root filesystem image.
57echo Using \'$uboot_image\' as bootloader.
58
59# Make sure ^C wipes everything we might have spawned along the way.
60trap 'kill -- -$$' INT EXIT
61
62# Currently we just make the u-boot image accessible under u-boot.bin
63# and qemu will load it from the working directory.  This is a
64# temporary solution.
65rm -rf $uboot_symlink
66ln -s $script_dir_relative/$uboot_image $uboot_symlink
67
68rm -rf $flash_base
69${make} $flash_base || exit -1
70
71# Launch the emulator assuming that u-boot is now functional enough
72# for us to be able to issue u-boot commands.
73# This is also an example of how you *shouldn't* write scripts.
74# We should parse the u-boot output for command prompt lines and only
75# issue commands when u-boot is awaiting them.
76emu () {
77        $qemu -mtdblock "$script_dir/$flash_base" -kernel "$script_dir/$1" \
78                -serial stdio -nographic -usb -monitor null <&0 & pid=$!
79}
80uboot () {
81        cd $src_dir
82        emu $1 <<< "                               
83$3
84neo1973 power-off
85"
86        echo Please wait, programming the NAND flash...
87        (sleep $2; kill $pid; sleep 1; kill -KILL $pid)& timer=$!
88        if ! wait $pid; then
89                kill $timer
90                echo
91                echo U-boot failed to finish writing in $2 seconds, giving up.
92                echo
93                exit -1
94        fi
95        kill $timer
96        cd $script_dir
97}
98
99# Set up BBT, u-boot environment, boot menu and program u-boot binary.
100
101
102
103
104#-----------------------------------------------------------------------
105# adds an entry to boot on SD
106
107
108
109uboot $uboot_image 600 "
110setenv dontask y
111nand createbbt
112setenv bootcmd 'setenv bootargs \${bootargs_base} \${mtdparts}; bootm $kernel_addr'
113setenv menu_1 Boot from SD: setenv bootargs \${bootargs_base} rootfstype=ext2 root=/dev/mmcblk0p2 rootdelay=5 \${mtdparts}\; mmcinit\; ext2load mmc 0 0x32000000 uImage\; bootm 0x32000000
114setenv menu_2 'Set console to USB: setenv stdin usbtty; setenv stdout usbtty; setenv stderr usbtty'
115setenv menu_3 'Set console to serial: setenv stdin serial; setenv stdout serial; setenv stderr serial'
116setenv menu_4 'Power off: neo1973 power-off'
117setenv splashimage 'nand read.e $splash_addr splash $splash_size; unzip $splash_addr 0x33d00000 0x96000'
118setenv mtdids nand0=neo1973-nand
119#setenv mtdparts mtdparts=neo1973-nand:0x00050000(u-boot),0x00004000(u-boot_env),0x00208000(kernel),0x00010000(splash),0x039a4000(rootfs)
120dynpart
121nand write.e $kernel_addr u-boot $uboot_size
122dynenv set u-boot_env
123saveenv"
124
125
126
127
128#-----------------------------------------------------------------------
129
130
131
132
133# Program bootsplash.
134uboot splash.gz 600 "
135nand write.e $kernel_addr splash $splash_size"
136
137# Program the kernel binary.
138uboot $kernel_image 160 "
139nand write.e $kernel_addr kernel $kernel_size"
140
141# Program the root filesystem.
142uboot $rootfs_image 600 "
143nand write.jffs2 $kernel_addr rootfs $rootfs_size"
144
145# Make the kernel image accessible under a fixed name
146rm -rf openmoko-kernel.bin
147ln -s $kernel_image openmoko-kernel.bin
148
149# Make the flash image accessible under a fixed name
150rm -rf $flash_image
151${make} $flash_image || exit -1
152
153echo
154echo "    "All done.
155echo
156echo "    "Read the qemu manual and use a commandline like the following to boot:
157echo \ \$ $qemu_relative -mtdblock $script_dir_relative/$flash_image -kernel $script_dir_relative/openmoko-kernel.bin -usb -show-cursor
158echo
159echo "    "Append \'-snapshot\' to make the flash image read-only so that every
160echo "    "time emulation starts in the original unmodified state.
161echo "    "Use [Enter] for AUX button, [Space] for POWER.
162echo "    "Append \'-usbdevice keyboard\' to attach a standard keyboard.
163echo "    "
164echo "    "If you\'ve configured qemu with --enable-phonesim \(requieres Qt4 and
165echo "    "a C++ toolchain\), use the following commandline to run phonesim:
166echo \ \$ \(cd phonesim\; LD_LIBRARY_PATH=lib ./phonesim -gui ../openmoko/neo1973.xml\)\&
167echo "    "The GUI is optional.  When phonesim is running, append
168echo "    "\'-serial tcp:localhost:12345\' to qemu invocation.  Security
169echo "    "note a la GLSA: phonesim listens on 0.0.0.0.
170echo