| 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 | |
|---|
| 18 | uboot_wildcard="uboot-ok.bin" |
|---|
| 19 | |
|---|
| 20 | #----------------------------------------------------------------------- |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | if [[ "$1" != "" ]]; then |
|---|
| 24 | img_dir="`(cd \"$1\"; pwd)`" |
|---|
| 25 | else |
|---|
| 26 | img_dir="$script_dir" |
|---|
| 27 | fi |
|---|
| 28 | |
|---|
| 29 | cd $script_dir |
|---|
| 30 | |
|---|
| 31 | if ! which pngtopnm || ! which ppmtorgb3; then |
|---|
| 32 | echo Splash needs \'pngtopnm\' and \'ppmtorgb3\' - make \ |
|---|
| 33 | sure that they\'re in \$PATH. |
|---|
| 34 | exit -1 |
|---|
| 35 | fi |
|---|
| 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. |
|---|
| 41 | most_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 | |
|---|
| 51 | most_recent "$kernel_wildcard" kernel_image kernel_size || exit -1 |
|---|
| 52 | most_recent "$rootfs_wildcard" rootfs_image rootfs_size || exit -1 |
|---|
| 53 | most_recent "$uboot_wildcard" uboot_image uboot_size || exit -1 |
|---|
| 54 | |
|---|
| 55 | echo Using \'$kernel_image\' as the kernel image. |
|---|
| 56 | echo Using \'$rootfs_image\' as the root filesystem image. |
|---|
| 57 | echo Using \'$uboot_image\' as bootloader. |
|---|
| 58 | |
|---|
| 59 | # Make sure ^C wipes everything we might have spawned along the way. |
|---|
| 60 | trap '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. |
|---|
| 65 | rm -rf $uboot_symlink |
|---|
| 66 | ln -s $script_dir_relative/$uboot_image $uboot_symlink |
|---|
| 67 | |
|---|
| 68 | rm -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. |
|---|
| 76 | emu () { |
|---|
| 77 | $qemu -mtdblock "$script_dir/$flash_base" -kernel "$script_dir/$1" \ |
|---|
| 78 | -serial stdio -nographic -usb -monitor null <&0 & pid=$! |
|---|
| 79 | } |
|---|
| 80 | uboot () { |
|---|
| 81 | cd $src_dir |
|---|
| 82 | emu $1 <<< " |
|---|
| 83 | $3 |
|---|
| 84 | neo1973 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 | |
|---|
| 109 | uboot $uboot_image 600 " |
|---|
| 110 | setenv dontask y |
|---|
| 111 | nand createbbt |
|---|
| 112 | setenv bootcmd 'setenv bootargs \${bootargs_base} \${mtdparts}; bootm $kernel_addr' |
|---|
| 113 | setenv 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 |
|---|
| 114 | setenv menu_2 'Set console to USB: setenv stdin usbtty; setenv stdout usbtty; setenv stderr usbtty' |
|---|
| 115 | setenv menu_3 'Set console to serial: setenv stdin serial; setenv stdout serial; setenv stderr serial' |
|---|
| 116 | setenv menu_4 'Power off: neo1973 power-off' |
|---|
| 117 | setenv splashimage 'nand read.e $splash_addr splash $splash_size; unzip $splash_addr 0x33d00000 0x96000' |
|---|
| 118 | setenv mtdids nand0=neo1973-nand |
|---|
| 119 | #setenv mtdparts mtdparts=neo1973-nand:0x00050000(u-boot),0x00004000(u-boot_env),0x00208000(kernel),0x00010000(splash),0x039a4000(rootfs) |
|---|
| 120 | dynpart |
|---|
| 121 | nand write.e $kernel_addr u-boot $uboot_size |
|---|
| 122 | dynenv set u-boot_env |
|---|
| 123 | saveenv" |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | #----------------------------------------------------------------------- |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | # Program bootsplash. |
|---|
| 134 | uboot splash.gz 600 " |
|---|
| 135 | nand write.e $kernel_addr splash $splash_size" |
|---|
| 136 | |
|---|
| 137 | # Program the kernel binary. |
|---|
| 138 | uboot $kernel_image 160 " |
|---|
| 139 | nand write.e $kernel_addr kernel $kernel_size" |
|---|
| 140 | |
|---|
| 141 | # Program the root filesystem. |
|---|
| 142 | uboot $rootfs_image 600 " |
|---|
| 143 | nand write.jffs2 $kernel_addr rootfs $rootfs_size" |
|---|
| 144 | |
|---|
| 145 | # Make the kernel image accessible under a fixed name |
|---|
| 146 | rm -rf openmoko-kernel.bin |
|---|
| 147 | ln -s $kernel_image openmoko-kernel.bin |
|---|
| 148 | |
|---|
| 149 | # Make the flash image accessible under a fixed name |
|---|
| 150 | rm -rf $flash_image |
|---|
| 151 | ${make} $flash_image || exit -1 |
|---|
| 152 | |
|---|
| 153 | echo |
|---|
| 154 | echo " "All done. |
|---|
| 155 | echo |
|---|
| 156 | echo " "Read the qemu manual and use a commandline like the following to boot: |
|---|
| 157 | echo \ \$ $qemu_relative -mtdblock $script_dir_relative/$flash_image -kernel $script_dir_relative/openmoko-kernel.bin -usb -show-cursor |
|---|
| 158 | echo |
|---|
| 159 | echo " "Append \'-snapshot\' to make the flash image read-only so that every |
|---|
| 160 | echo " "time emulation starts in the original unmodified state. |
|---|
| 161 | echo " "Use [Enter] for AUX button, [Space] for POWER. |
|---|
| 162 | echo " "Append \'-usbdevice keyboard\' to attach a standard keyboard. |
|---|
| 163 | echo " " |
|---|
| 164 | echo " "If you\'ve configured qemu with --enable-phonesim \(requieres Qt4 and |
|---|
| 165 | echo " "a C++ toolchain\), use the following commandline to run phonesim: |
|---|
| 166 | echo \ \$ \(cd phonesim\; LD_LIBRARY_PATH=lib ./phonesim -gui ../openmoko/neo1973.xml\)\& |
|---|
| 167 | echo " "The GUI is optional. When phonesim is running, append |
|---|
| 168 | echo " "\'-serial tcp:localhost:12345\' to qemu invocation. Security |
|---|
| 169 | echo " "note a la GLSA: phonesim listens on 0.0.0.0. |
|---|
| 170 | echo |
|---|