#!/bin/bash # Install QEMU and run ML on a fresh Ubuntu VM. # TODO: adapt it for other operating systems. # # The script is hardcoded and pretty much open loop, # other than waiting for screen to settle on long actions. # # For reproducing the demo: # # - install Ubuntu on a VM (I've used virsh / QEMU) # - set resolution to 1024x680 (3:2) using xrandr # sudo xrandr --newmode "1024x680" 56.25 1024 1072 1176 1328 680 683 693 707 -hsync +vsync # sudo xrandr --addmode VGA-1 "1024x680" # sudo xrandr --output VGA-1 --mode "1024x680" # - launch a background task that will place the terminal and QEMU windows where we want them # sudo apt install wmctrl # (while true; do wmctrl -Fr QEMU -e 0,280,80,720,503; wmctrl -Fr "alex@ubuntu: ~" -e 0,48,30,735,450; sleep 1; done) & # disown # # close the terminal # - copy the ROMs for 5D3.113 under /sdcard/ML/LOGS (create the directories) # - save a live snapshot on the VM (from the host): # virsh snapshot-create-as ubuntu fresh-install-live-winpos-5D3113 # - before running this script, restore the VM to that snapshot # virsh snapshot-revert ubuntu fresh-install-live-winpos-5D3113 # - make sure you can access the VM using VNC VNCDISP=":1" # and hope for the best :) # press a key on the VM # save a screenshot right before pressing function key { echo "key $@" vncdotool -s $VNCDISP capture $((cnt++))-$1.png vncdotool -s $VNCDISP key "$@" sleep 1 } # type a message on the VM # capture a few screenshots before pressing ENTER # (this will give small pause in the animation) function type { echo "$*" vncdotool --force-caps -s $VNCDISP --delay=50 type "$*" vncdotool -s $VNCDISP capture $((cnt++))-type.png vncdotool -s $VNCDISP capture $((cnt++))-type.png vncdotool -s $VNCDISP capture $((cnt++))-type.png vncdotool -s $VNCDISP key enter sleep 1 } # type a string on the VM and save it as caption to a .txt file # the caption will be later displayed over these screenshots # type 16 chars at a time, to simulate typing on long string function type_caption { msg="$*" for (( i=0; i<${#msg}; i+=16 )); do echo -n "${msg:$i:16}" vncdotool --force-caps -s $VNCDISP --delay=50 type "${msg:$i:16}" echo $msg > $((cnt))-type.txt; vncdotool -s $VNCDISP capture $((cnt++))-type.png done echo $msg > $((cnt))-type.txt; vncdotool -s $VNCDISP capture $((cnt++))-type.png echo $msg > $((cnt))-type.txt; vncdotool -s $VNCDISP capture $((cnt++))-type.png echo $msg > $((cnt))-type.txt; vncdotool -s $VNCDISP capture $((cnt++))-type.png echo vncdotool -s $VNCDISP key enter sleep 1 } # types your sudo password on the VM function sudo_password { echo "" vncdotool --force-caps -s $VNCDISP --delay=50 type your-sudo-password key enter sleep 1 } # capture a named snapshot function snap { echo "snap $1" vncdotool -s $VNCDISP capture $((cnt++))-$1 } # wait until the VM screen no longer changes # optional parameter: timeout (for how long it should settle) # if you need this higher than say 30 seconds, hide the clock! # every 10 seconds, a snapshot will be made # (so long actions will appear in the animation, but time-warped) function settle { vncdotool -s $VNCDISP capture snap.png old=$(md5sum snap.png) countdown=${1:-2} iter=0 while true; do sleep 1 vncdotool -s $VNCDISP capture snap.png new=$(md5sum snap.png) if [ "$new" == "$old" ]; then ((countdown--)) echo -n $countdown else echo -n . countdown=${1:-2} fi if [ "$countdown" == "0" ]; then break fi if (((iter++) % 10 == 0)); then snap wait.png fi old="$new" done echo } # move old stuff from previous runs mkdir -p old mv *.png *.txt old/ # start screenshots from 1 cnt=1 # open a terminal # this will be different on other OS key alt-f2 sleep 1 type mate-terminal sleep 1 # try hg clone # it should print "sudo apt install mercurial" type_caption hg clone https://bitbucket.org/hudson/magic-lantern sleep 1 # now run "sudo apt install mercurial" type_caption sudo apt install mercurial sudo_password type_caption y settle # now we can clone the ML repository type_caption hg clone https://bitbucket.org/hudson/magic-lantern settle snap hg-clone.png # run the install script from contrib/qemu (qemu branch) type_caption cd magic-lantern type_caption hg update qemu -C settle type_caption cd contrib/qemu type_caption ./install.sh snap install-prompt.png # answers to what the script is going to ask type_caption y settle type_caption 2 settle type_caption y settle 16 # setup compiler path, then run the script again type_caption 'PATH=~/gcc-arm-none-eabi-5_4-2016q3/bin:$PATH' type_caption ./install.sh type_caption y settle 10 # click the scrollbar to see the installation instructions # the "Next steps" from install.sh vncdotool -s $VNCDISP move 780 300 click 1 snap install-instructions.png vncdotool -s $VNCDISP move 780 300 click 1 snap install-instructions.png snap install-instructions.png snap install-instructions.png snap install-instructions.png snap install-instructions.png snap install-instructions.png snap install-instructions.png # compile QEMU type_caption cd /home/alex/qemu/qemu-2.5.0 type_caption ../configure_eos.sh settle 5 type_caption make -j1 settle 10 snap qemu-compiled.png snap qemu-compiled.png snap qemu-compiled.png snap qemu-compiled.png snap qemu-compiled.png # copy 5D3 1.1.3 ROMs type_caption cd .. type_caption cp /sdcard/ML/LOGS/ROM*.BIN 5D3/ # run with default options (portable display test) type_caption ./run_canon_fw.sh 5D3 settle snap qemu-5D3-test.png snap qemu-5D3-test.png snap qemu-5D3-test.png snap qemu-5D3-test.png snap qemu-5D3-test.png # close QEMU window key alt-f4 sleep 2 snap off.png snap off.png snap off.png snap off.png # run 5D3 1.1.3 GUI # this requires 32-bit GDB # if you don't have, try other camera model type_caption './run_canon_fw.sh 5D3,firmware="boot=0" -s -S & arm-none-eabi-gdb -x 5D3/patches.gdb -ex quit' settle key f1 snap qemu-5D3-gui.png snap qemu-5D3-gui.png snap qemu-5D3-gui.png snap qemu-5D3-gui.png snap qemu-5D3-gui.png # open Canon menu and navigate to Firmware Version: 1.1.3 # these steps may differ with your ROM key m key left key up snap qemu-5D3-menu.png snap qemu-5D3-menu.png snap qemu-5D3-menu.png snap qemu-5D3-menu.png snap qemu-5D3-menu.png # stop the emulation key alt-f4 sleep 2 snap off.png snap off.png snap off.png snap off.png # compile ML for 5D3 1.1.3 and install it on QEMU's virtual SD card type_caption make -C ../magic-lantern/platform/5D3.113 install_qemu settle snap compiled.png snap compiled.png snap compiled.png snap compiled.png # now run ML for 5D3 1.1.3 type_caption './run_canon_fw.sh 5D3,firmware="boot=1" -s -S & arm-none-eabi-gdb -x 5D3/patches.gdb -ex quit' settle snap qemu-5D3-ml.png key delete sleep 1 # go to Modules menu and enable Lua (hardcoded steps) snap qemu-5D3-ml-menu.png for i in `seq 1 9`; do key right done for i in `seq 1 9`; do key down done key space # close ML menu key delete sleep 1 # power down QEMU cleanly # otherwise we'll get an error and the modules will not load key alt-m key down key down snap qemu-5D3-ml-poweroff.png key d sleep 1 # run the last command (re-launch QEMU to run ML) key up key enter snap lastcmd.png snap lastcmd.png snap lastcmd.png settle # open ML menu and navigate towards the Scripts menu key delete key left # pause on Sokoban snap soko.png snap soko.png snap soko.png key space key space # Sokoban game screen snap qemu-5D3-lua-sokoban.png snap qemu-5D3-lua-sokoban.png snap qemu-5D3-lua-sokoban.png snap qemu-5D3-lua-sokoban.png # pretend you're playing for k in right up right right down down left; do key $k done # got stuck snap soko.png snap soko.png snap soko.png snap soko.png # quit the game key q key q # keep browsing ML menu key left key down key down key down # run the Hello World script key space snap wip.png sleep 1 snap wip.png sleep 1 snap wip.png settle snap qemu-5D3-lua-hello.png # power down QEMU key alt-m key down key down snap powerdown.png snap powerdown.png snap powerdown.png snap powerdown.png snap powerdown.png key d sleep 1 # final screen after powering down snap fini.png snap fini.png snap fini.png snap fini.png snap fini.png # that's it! # run anim.py to render the animation