install.sh 22 KB
Newer Older
1
#!/usr/bin/env bash
2

3
4
set -e

5
6
7
QEMU_DIR=${QEMU_DIR:=qemu-eos}

# paths relative to QEMU_DIR (where it will be installed)
alex@thinkpad's avatar
alex@thinkpad committed
8
QEMU_NAME=${QEMU_NAME:=qemu-2.5.0}
9
10
11
ML_PATH=${ML_PATH:=../magic-lantern}

ML_NAME=${ML_PATH##*/}
12
GREP=${GREP:=grep}
13
WGET_OPTS="-c -q --show-progress --progress=dot:giga"
14
ARM_GDB=
15

16
17
18
19
20
# valid values: x86, x64
TOOLCHAIN_ARCH=${TOOLCHAIN_ARCH:=}

# whether to compile GDB 8.1 from source
COMPILE_GDB=${COMPILE_GDB:=false}
21

22
23
24
25
26
echo
echo "This will setup QEMU for emulating Magic Lantern."
echo "Thou shalt not be afraid of compiling stuff on Linux ;)"
echo -n "Continue? [y/n] "
read answer
27
28
29
if test "$answer" != "Y" -a "$answer" != "y"; then exit 0; fi
echo

30
31
32
33
34
function choose_toolchain_ask {
    echo
    echo "*** You may choose either a 32-bit or a 64-bit toolchain:"
    echo
    echo "1) 32-bit 5_4-2016q3 (recommended; default in ML Makefile)"
35
36
    if [  -z "$(lsb_release -i 2>/dev/null | grep -E 'Ubuntu|Debian')" ]; then
        # FIXME: auto-install 32-bit dependencies on systems other than Ubuntu/Debian?
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
        echo "   On 64-bit systems, you may need to install 32-bit libraries manually."
    fi
    echo
    echo "2) 64-bit 7-2018-q2 (known to work, but not thoroughly tested)"
    echo
    echo -n "Your choice? "
    read answer
    if [ "$answer" == "1" ]; then
        TOOLCHAIN_ARCH="x86"
    elif [ "$answer" == "2" ]; then
        TOOLCHAIN_ARCH="x64"
    else
        # invalid choice
        exit 1
    fi
}
function choose_toolchain {
    if [ $(uname) == "Darwin" ]; then
        # Mac, only 64-bit binaries are available for the prebuilt toolchain
        TOOLCHAIN_ARCH="x64"
    elif [  -n "$(uname -a | grep Microsoft)" ]; then
        # WSL, only 64-bit Linux binaries are working
        TOOLCHAIN_ARCH="x64"
    elif [[ $(uname -m) =~ i[3-6]86 ]]; then
        # 32-bit Linux
        TOOLCHAIN_ARCH="x86"
    elif [ $(uname -m) == "x86_64" ]; then
        # 64-bit Linux (other than WSL), can choose either 32-bit or 64-bit binaries
        if [ -z "$TOOLCHAIN_ARCH" ]; then
            # only ask once
            choose_toolchain_ask
        fi
69
70
71
    else
        echo "Unsupported platform: $(uname) $(uname -m)"
        exit 1
72
73
74
    fi
}

75
function install_gcc {
76

77
78
79
80
81
82
83
84
    # ask user for preferred toolchain, if not done yet
    choose_toolchain

    if [ -z "$TOOLCHAIN_ARCH" ]; then
        echo "Could not find a suitable toolchain for your $(uname -m) system."
        return
    fi

85
86
    UNTAR="tar -jxf"

87
88
89
90
91
    # 64-bit (with 64-bit GDB 8.1, known to work on all systems)
    TOOLCHAIN=gcc-arm-none-eabi-7-2018-q2-update
    DOWNLOAD=https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/7-2018q2/
    MIRROR="$DOWNLOAD"

92
    if [ $(uname) == "Darwin" ]; then
93
        # Mac, 64-bit binaries
94
95
        TARBALL=$TOOLCHAIN-mac.tar.bz2
    elif [  -n "$(uname -a | grep Microsoft)" ]; then
96
        # WSL, only 64-bit binaries are working
97
        TARBALL=$TOOLCHAIN-linux.tar.bz2
98
99
    elif [ "$TOOLCHAIN_ARCH" == "x86" ]; then
        # Linux (other than WSL), 32-bit toolchain
100
        TOOLCHAIN=gcc-arm-none-eabi-5_4-2016q3
101
102
        DOWNLOAD=https://developer.arm.com/-/media/Files/downloads/gnu-rm/5_4-2016q3/
        MIRROR=https://launchpad.net/gcc-arm-embedded/5.0/5-2016-q3-update/+download/
103
        TARBALL=$TOOLCHAIN-20160926-linux.tar.bz2
104
105
106
    else
        # Linux (other than WSL), 64-bit toolchain (same version used for Mac/WSL)
        TARBALL=$TOOLCHAIN-linux.tar.bz2
107
    fi
108

109
    echo
110
111
112
113
    echo "*** Will download $TOOLCHAIN from:"
    echo "    https://developer.arm.com/open-source/gnu-toolchain/gnu-rm"
    echo

114
115
    if [ ! -f ~/$TOOLCHAIN/bin/arm-none-eabi-gdb ]; then
        cd ~
116
        wget $WGET_OPTS $DOWNLOAD$TARBALL || wget $WGET_OPTS $MIRROR$TARBALL \
117
            && $UNTAR $TARBALL && rm $TARBALL
118
119
120
121
122
        cd -
    else
        echo "*** Toolchain already installed in:"
        echo "    ~/$TOOLCHAIN"
    fi
123

124
125
    echo
    echo "*** Please add GCC binaries to your executable PATH, then run this script again."
126
127
    echo "*** Run this command, or paste it into your .profile and reopen the terminal:"
    echo "    export PATH=~/$TOOLCHAIN/bin:\$PATH"
128
    echo
129
130
131
    exit
}

132
function gdb_error {
alex@thinkpad's avatar
alex@thinkpad committed
133
134
135
136
    echo
    echo "*** Last 30 lines from $1:"
    echo
    tail -n 30 $1
137
138
139
140
141
142
    echo
    echo "*** GDB compilation failed; logs saved in $(pwd)"
    echo "*** Please check what went wrong, try to fix it and report back."
    exit 1
}

143
144
145
146
function install_gdb {
    # we may need to compile a recent GDB
    # the latest pre-built version is buggy (at the time of writing)
    # on Linux, the old 32-bit version works fine, but we can't run it on Mac/WSL
147
    GDB_DIR=$HOME/gdb-arm-none-eabi-8_1
148
149
150
151
152
153

    if [ ! -f $GDB_DIR/bin/arm-none-eabi-gdb ]; then
        pushd . > /dev/null
        local MIRROR=https://ftp.gnu.org/gnu
        mkdir $GDB_DIR
        cd $GDB_DIR
154
        echo
alex@thinkpad's avatar
alex@thinkpad committed
155
        echo "*** Setting up GDB in $(pwd)/  ..."
156
157
        mkdir src
        cd src
158
        wget $WGET_OPTS $MIRROR/gdb/gdb-8.1.tar.xz
159
        echo
160
        tar xJf gdb-8.1.tar.xz || exit 1
161
162
163
164
        echo
        mkdir build-gdb
        cd build-gdb
        echo "Configuring arm-none-eabi-gdb... (configure.log)"
165
        ../gdb-8.1/configure --target=arm-none-eabi --prefix=$GDB_DIR/ &> configure.log || gdb_error configure.log
166
        echo "Building arm-none-eabi-gdb... (make.log)"
167
        make &> make.log || gdb_error make.log
168
        echo "Installing arm-none-eabi-gdb... (install.log)"
alex@thinkpad's avatar
alex@thinkpad committed
169
        (make install || make install MAKEINFO=true) &> install.log || gdb_error install.log
170
171
172
173
174
175
176
177
178
179
180
181
        popd > /dev/null
    else
        echo "*** GDB already installed in:"
        echo "    $GDB_DIR/bin/"
    fi

    echo
    echo "*** Please add GDB binaries to your executable PATH, then run this script again."
    echo "*** Run this command, or paste it into your .profile and reopen the terminal:"
    echo "    export PATH=$GDB_DIR/bin/:\$PATH"
    echo
    exit
182
183
}

184
function valid_arm_gdb {
185
    if ! arm-none-eabi-gdb -v &> /dev/null && ! gdb-multiarch -v &> /dev/null; then
186
187
188
189
        # not installed, or not able to run for any reason
        return 1
    fi

190
    # 8.0 and earlier is buggy on 64-bit; 8.1 is known to work
191
    # 8.2 and newer are also buggy, tested until 10.1...
192

193
    if arm-none-eabi-gdb -v 2>/dev/null | grep -q " 8\.1\.[0-9]"; then
194
        # this one is good, even if compiled for 64-bit
195
        ARM_GDB="arm-none-eabi-gdb"
196
197
198
        return 0
    fi

199
    if gdb-multiarch -v 2>/dev/null | grep -q " 8\.1\.[0-9]"; then
200
201
202
        # this one is just as good
        ARM_GDB="gdb-multiarch"
        return 0
203
204
    fi

205
206
207
208
209
210
211
212
213
214
    if arm-none-eabi-gdb -v 2>/dev/null | grep -qE " (9|10)\.[0-9]+\.[0-9]+"; then
        # arm-none-eabi-gdb 9.x and 10x are broken on i686 as well
        return 1
    fi

    if gdb-multiarch -v 2>/dev/null | grep -qE " (9|10)\.[0-9]+\.[0-9]+"; then
        # same for gdb-multiarch
        return 1
    fi

215
216
217
218
219
220
221
222
223
224
225
226
    if arm-none-eabi-gdb -v 2>/dev/null | grep -q "host=i[3-6]86"; then
        # let's hope it's OK
        ARM_GDB="arm-none-eabi-gdb"
        return 0
    fi

    if gdb-multiarch -v 2>/dev/null | grep -q "host=i[3-6]86"; then
        # let's hope it's OK
        ARM_GDB="gdb-multiarch"
        return 0
    fi

227
    echo "*** WARNING: your GDB version may not be able to run our scripts."
228
    return 1
229
230
}

231
232
233
234
235
236
237
238
239
240
241
242
243
function valid_arm_gcc {
    if ! arm-none-eabi-gcc -v &> /dev/null; then
        # not installed, or not able to run for any reason
        return 1
    fi

    echo "#include <stdlib.h>" > arm-gcc-test.c
    if ! arm-none-eabi-gcc -c arm-gcc-test.c; then
        echo "*** WARNING: your arm-none-eabi-gcc is unable to compile a simple program."
        rm arm-gcc-test.c
        return 1
    fi

alex@thinkpad's avatar
alex@thinkpad committed
244
    rm arm-gcc-test.c arm-gcc-test.o
245
246
247
    return 0
}

248
249
250
if [ $(uname) == "Darwin" ]; then
    echo "*** Installing dependencies for Mac..."
    echo
251
252
253
    # brew is "The missing package manager for macOS"
    # https://brew.sh
    if ! brew -v &> /dev/null; then
254
        /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
255
    fi
256

257
    packages="python3 wget mercurial xz grep pkg-config glib automake libtool pixman mtools"
258
259
260
    for pkg in $packages; do
        brew list $pkg &> /dev/null || brew install $pkg
    done
261

262
    GREP=ggrep
263
264
fi

265
266
if [  -n "$(lsb_release -i 2>/dev/null | grep -E 'Ubuntu|Debian')" ]; then
    # Ubuntu/Debian-based system? (including WSL)
267
268
269
    # install these packages, if not already
    # only request sudo if any of them is missing
    # instead of GTK (libgtk2.0-dev), you may prefer SDL (libsdl1.2-dev)
270
    packages="
271
        build-essential mercurial pkg-config libtool
272
        git libglib2.0-dev libpixman-1-dev zlib1g-dev
273
        libgtk2.0-dev xz-utils mtools netcat-openbsd
274
        python3 python3-pip python3-docutils"
275

276
    if [ -n "$(apt-cache search --names-only '^python2$')" ]; then
277
278
279
280
281
        packages="$packages python2"
    else
        packages="$packages python"
    fi

282
283
284
285
    # if a valid arm-none-eabi-gcc/gdb is already in PATH, try to use that
    # otherwise, we'll try to install something
    if ! valid_arm_gdb || ! valid_arm_gcc; then
        echo "*** You do not seem to have an usable arm-none-eabi-gcc and/or gdb installed."
alex@thinkpad's avatar
alex@thinkpad committed
286
        echo "*** Some 64-bit GDB versions are known to have issues."
287
288
289
        echo
        echo "*** You have a few options:"
        echo
alex@thinkpad's avatar
alex@thinkpad committed
290

291
        # 32-bit binaries not working under WSL
alex@thinkpad's avatar
alex@thinkpad committed
292
        if [  -z "$(uname -a | grep Microsoft)" ]; then
293
294
295
            echo "1) Download a precompiled toolchain (32-bit or 64-bit gcc-arm-embedded)"
            echo "   and install it into your HOME directory, without the package manager."
            echo "   Recommended."
296
            echo
297
            echo "2) Install gcc-arm-none-eabi from APT repository (native for your system)"
298
            echo "   and compile arm-none-eabi-gdb 8.1 from source. Slower installation."
299
            echo
300
301
302
303
            echo "3) Manually install the toolchain from https://launchpad.net/gcc-arm-embedded."
            echo "   Choose either 32-bit binaries (gcc 5.x, recommended 5_4-2016q3),"
            echo "   or 64-bit with gdb 8.1 (7-2018-q2 is the only one known to work)."
            echo "   Make sure the toolchain is in PATH, then run this script again."
304
            echo
305
        else
306
            # WSL
307
            echo
308
309
310
311
            echo "1) Download a precompiled toolchain (gcc-arm-embedded, 64-bit 7-2018-q2)"
            echo "   and install it into your HOME directory, without the package manager."
            echo "   Recommended."
            echo
312
            echo "2) Install gcc-arm-none-eabi from APT repository (64-bit binaries)"
313
            echo "   and compile arm-none-eabi-gdb 8.1 from source. Slower, but known to work."
314
            echo
315
316
317
            echo "3) Manually install arm-none-eabi-gcc / gdb 8.1 (7-2018-q2, not latest!)"
            echo "   from https://launchpad.net/gcc-arm-embedded (choose 64-bit Linux binaries),"
            echo "   make sure it is in PATH, then run this script again."
318
        fi
319

320
321
322
323
324
325
        echo
        echo -n "Your choice? "
        read answer
        echo
        case $answer in
            1)
326
327
328
329
330
331
332
333
                # ask user for preferred toolchain
                choose_toolchain

                # precompiled toolchain has some additional dependencies
                if [ "$TOOLCHAIN_ARCH" == "x86" ]; then
                    packages="$packages libc6:i386 libncurses5:i386"
                else
                    packages="$packages libc6 libncurses5"
334
                fi
335
                ;;
336
            2)
337
                # install native (64 or 32) arm-none-eabi-gcc from package manager
338
                # and compile arm-none-eabi-gdb 8.1 from source
339
                packages="$packages gcc-arm-none-eabi libnewlib-arm-none-eabi"
340
                COMPILE_GDB=true
341
                ;;
342
            3)
343
                # user will install arm-none-eabi-gdb and run the script again
344
345
346
                exit 0
                ;;
            *)
347
                # invalid choice
348
349
350
351
352
353
354
                exit 1
                ;;
        esac
    else
        echo "*** You have a valid ARM GCC/GDB already installed - using that one."
    fi

355
    echo "*** Checking dependencies for Ubuntu/Debian..."
356
    echo
357
358
359
    # https://wiki.debian.org/ListInstalledPackages
    # dpkg -l also returns packages that are not installed
    deps_installed=yes
360
    for package in $packages; do
361
362
363
        if ! dpkg -l $package 2>/dev/null | grep -q '^.i'; then
            echo Not installed: $package
            deps_installed=no
364
365
        fi
    done
366
367
368

    if [ "$deps_installed" == "no" ]; then
        echo
369
        echo "*** Installing dependencies for Ubuntu/Debian..."
370
        echo
371
372
        if [[ "$packages" == *i386* ]]; then
            sudo dpkg --add-architecture i386
373
        fi
374
        sudo apt-get update || true
375
376
377
378
379
380
381
382
383
384
385
386
387
388
        sudo apt-get install $packages
        echo
    fi

    deps_installed=yes
    for package in $packages; do
        if ! dpkg -l $package 2>/dev/null | grep -q '^.i'; then
            echo Not installed: $package
            deps_installed=no
        fi
    done

    if [ "$deps_installed" == "no" ]; then
        echo
389
        echo "*** Error: Ubuntu/Debian dependencies could not be installed."
390
        echo
391
        exit 1
392
    fi
393
394
fi

395
396
397
if [ -n "$TOOLCHAIN_ARCH" ]; then
    # toolchain already chosen? don't ask again, just install it
    # this will provide a valid gdb as well
398
399
400
    install_gcc
fi

401
402
403
404
405
if [ "$COMPILE_GDB" == "true" ]; then
    # if user already selected to compile GDB from source, don't ask again
    install_gdb
fi

406
# all systems (including Mac, or Ubuntu/Debian/WSL if previous steps failed)
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434

if valid_arm_gcc; then
    if ! valid_arm_gdb; then
        echo
        echo "*** You already have a valid arm-none-eabi-gcc,"
        echo "*** but you also need arm-none-eabi-gdb. What to do?"
        echo
        echo "1) Install the prebuilt ARM toolchain (arm-none-eabi-gcc / gdb)"
        echo "   from https://developer.arm.com/open-source/gnu-toolchain/gnu-rm"
        echo "   into your HOME directory. Recommended."
        echo
        echo "2) Keep your existing ARM compiler (arm-none-eabi-gcc) and compile"
        echo "   gdb 8.1 from source. Slower installation, but should work fine."
        echo
        echo -n "Your choice? "
        read answer
        if [ "$answer" == "1" ]; then
            # this will provide a valid gdb as well
            install_gcc
        elif [ "$answer" == "2" ]; then
            # compile gdb from sources
            install_gdb
        else
            # invalid choice
            exit 1
        fi
    fi
else
435
    echo
436
    echo "*** WARNING: a valid arm-none-eabi-gcc could not be found."
437
    echo "*** Downloading a prebuilt toolchain and installing it in your HOME directory."
438
    echo
439
440
441
442
    echo -n "Continue? [y/n] "
    read answer
    if test "$answer" != "Y" -a "$answer" != "y"; then exit 0; fi
    echo
443
444

    # this will provide a valid gdb as well
445
446
447
    install_gcc
fi

448
449
450
451
452
# make sure we have a valid arm-none-eabi-gcc (regardless of operating system)
if ! valid_arm_gcc; then
    echo "*** Please set up a valid arm-none-eabi-gcc before continuing."
    echo "*** Make sure arm-none-eabi-gcc is in your executable PATH."
    exit 1
453
454
fi

455
# same for arm-none-eabi-gdb
456
if ! valid_arm_gdb; then
457
    echo "*** Please set up a valid arm-none-eabi-gdb or gdb-multiarch before continuing."
458
    echo "*** Make sure either arm-none-eabi-gdb or gdb-multiarch is in your PATH."
459
460
461
    exit 1
fi

462
463
464
echo
echo -n "*** Using GCC: "
command -v arm-none-eabi-gcc
465
arm-none-eabi-gcc -v 2>&1 | grep "gcc version"
466
echo
467
echo -n "*** Using GDB: "
468
469
command -v $ARM_GDB         # set by valid_arm_gcc
$ARM_GDB -v | head -n1
470
echo
471

472
# install docutils (for compiling ML modules) and vncdotool (for test suite)
473
# only install if any of them is missing
474
475
pip3 list | grep docutils  || rst2html -h  > /dev/null || pip3 install docutils
pip3 list | grep vncdotool || vncdotool -h > /dev/null || pip3 install vncdotool
476

477
478
function die { echo "${1:-"Unknown Error"}" 1>&2 ; exit 1; }

479
pwd | grep $ML_NAME/contrib/qemu > /dev/null || die "error: we should be in $ML_NAME/contrib/qemu"
480
481
482

# go to the parent of magic-lantern folder
cd ../../..
483
ls | $GREP $ML_NAME > /dev/null || die "error: expecting to find $ML_NAME here"
484

485
486
mkdir -p $QEMU_DIR
cd $QEMU_DIR
487
488

echo
alex@thinkpad's avatar
alex@thinkpad committed
489
echo "*** Setting up QEMU in $(pwd)/ ..."
490
491
echo

alex@thinkpad's avatar
alex@thinkpad committed
492
if [ -d $QEMU_NAME ]; then
493
  DATE=`date '+%Y-%m-%d_%H-%M-%S'`
494
  echo "*** Directory $(pwd)/$QEMU_NAME already exists."
495
496
  echo "*** To reinstall, please rename or delete it first."
  echo ""
alex@thinkpad's avatar
alex@thinkpad committed
497
498
499
500
  echo "- R or r       : rename to $(pwd)/${QEMU_NAME}_$DATE/"
  echo "- C or c       : make clean & rename to $(pwd)/${QEMU_NAME}_$DATE/"
  echo "- uppercase D  : delete $(pwd)/$QEMU_NAME/ without confirmation (!)"
  echo "- any other key: cancel the operation (exit the script)"
501
502
  echo ""
  echo -n "Your choice? "
503
504
505
506
507
508
  read answer
  case "$answer" in
      D)
        rm -Rf $QEMU_NAME
        ;;
      R|r)
509
        mv $QEMU_NAME ${QEMU_NAME}_$DATE
510
        ;;
alex@thinkpad's avatar
alex@thinkpad committed
511
512
513
514
      C|c)
        make -C $QEMU_NAME clean
        mv $QEMU_NAME ${QEMU_NAME}_$DATE
        ;;
515
516
517
518
      *)
        exit 1
        ;;
  esac
519
520
fi

521
# get qemu
522
wget $WGET_OPTS http://wiki.qemu-project.org/download/$QEMU_NAME.tar.bz2
523
echo
524
tar jxf $QEMU_NAME.tar.bz2
525
echo
526

527
528
# initialize a git repo, to make it easy to track changes to QEMU source
cd $QEMU_NAME
529
530
if [ ! -d .git ]; then
  git init
531
532
533
  # git requires a valid email; add one for this directory only
  git config user.email qemu-eos@magiclantern.fm
  git config user.name qemu-eos
534
  git add . && git commit -q -m "$QEMU_NAME vanilla"
535
fi
536
537
cd ..

538
539
echo "Copying files..."

540
# copy our helper scripts
541
cp -r $ML_PATH/contrib/qemu/scripts/* .
542
chmod +x *.sh
543
544
545

# copy our testing scripts
mkdir -p tests
546
cp -r $ML_PATH/contrib/qemu/tests/* tests/
547
548
chmod +x tests/*.sh

549
# apply our patches
550
cd ${QEMU_NAME}
551
mkdir -p hw/eos
552
553
cp -r ../$ML_PATH/contrib/qemu/eos/* hw/eos/
cp -r ../$ML_PATH/src/backtrace.[ch] hw/eos/dbi/
554

555
556
557
558
559
560
561
# although created for gcc 7.x and newer compilers,
# this doesn't break gcc 5.x and it also helps clang
echo "Patching $QEMU_NAME for recent compilers..."
patch -N -p1 < ../$ML_PATH/contrib/qemu/$QEMU_NAME-recent-gcc.patch
git add -u . && git commit -q -m "$QEMU_NAME patched for recent compilers"

echo "Patching $QEMU_NAME for EOS emulation..."
562
patch -N -p1 < ../$ML_PATH/contrib/qemu/$QEMU_NAME-eos.patch
563
564
# don't commit this one - we'll use "git diff" to update the above patch

565
566
cd ..

567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
echo
echo "Setting up SD/CF card images..."

if [ -f "sd.img" ] || [ -f "cf.img" ]; then
    echo -n "Replace (overwrite) old sd.img and cf.img? [y/n] "
    read answer
    echo
    if test "$answer" == "Y" -o "$answer" == "y"; then
        rm -f sd.img cf.img sd.img.xz
    fi
fi

# always overwritten
cp -v $ML_PATH/contrib/qemu/sd.img.xz .

582
583
584
if [ ! -f "sd.img" ]; then
    unxz -v sd.img.xz
else
585
    echo "Keeping previous SD image."
586
587
588
589
590
fi

if [ ! -f "cf.img" ]; then
    cp -v sd.img cf.img
else
591
    echo "Keeping previous CF image."
592
593
fi

594
595
596
597
598
599
echo ""
echo "Next steps:"
echo "==========="
echo
echo "1) Compile QEMU"
echo
600
echo "   cd `pwd`/${QEMU_NAME}"
601
echo "   ../configure_eos.sh"
602
echo "   make -j`$GREP -c processor /proc/cpuinfo 2> /dev/null || sysctl -n hw.ncpu 2> /dev/null || echo 1`"
603
echo
604
echo -n "Shall this script attempt to compile QEMU now? [y/n] "
605
606
607
608
609
610
read answer
if test "$answer" == "Y" -o "$answer" == "y"
 then
    cd `pwd`/${QEMU_NAME}
    ../configure_eos.sh
    if make -j`$GREP -c processor /proc/cpuinfo 2> /dev/null || sysctl -n hw.ncpu 2> /dev/null || echo 1`; then
611
        cd ..
612
613
614
615
616
617
618
619
620
621
622
        echo
        echo "*** Done compiling."
        echo
        echo
        echo "Next steps:"
        echo "==========="
        echo
        echo "1) Go to QEMU directory"
        echo
        echo "   cd `pwd`/"
    else
623
        cd ..
624
625
626
        echo
        echo "*** Compilation failed."
        echo "*** Please check what went wrong, try to fix it and report back."
alex@thinkpad's avatar
alex@thinkpad committed
627
        exit 1
628
629
630
    fi
fi
echo
631
632
633
634
echo "2) Grab a copy of the Canon firmware from your own camera"
echo "   (don't request one and don't share it online - it's copyrighted)"
echo
echo "   Look on your SD card - you should find ML/LOGS/ROM0.BIN and ROM1.BIN"
635
636
echo "   Copy them under your camera model's subdirectory, for example:"
echo "   `pwd`/60D/"
637
echo
638
639
echo "   For models that use a serial flash, you may have to dump its contents"
echo "   using the sf_dump module, then copy SFDATA.BIN as well."
640
echo
641
echo "3) Install Magic Lantern on your SD/CF card image:"
642
echo
643
echo "   make -C ../magic-lantern 60D_install_qemu "
644
echo
645
646
echo "   The included card image is bootable and contains a small autoexec.bin"
echo "   that runs on all supported EOS cameras and prints some basic info."
647
echo
648
echo "4) Start emulation with:"
649
650
echo
echo "   cd `pwd`/"
651
652
653
echo "   ./run_canon_fw.sh 60D"
echo
echo "   This will recompile QEMU, but not ML."
654
echo
655
echo "   Note: Canon GUI emulation (menu navigation, no LiveView) only works on:"
656
echo -n "   "; echo $($GREP --color=never -oPz "(?<=GUI_CAMS=\( )[^()]*(?=\))" tests/run_tests.sh | tr '\0' '\n');
657
echo
658
echo "5) Tips & tricks:"
659
660
echo "   - to enable or disable the boot flag in ROM, use something like:"
echo "     ./run_canon_fw.sh 60D,firmware=\"boot=1\""
661
662
echo "   - to use multiple firmware versions, place the ROMs under e.g. 5D3/113/ROM*.BIN and run:"
echo "     ./run_canon_fw.sh 5D3,firmware=\"113;boot=1\""
663
664
665
666
667
echo "   - to show MMIO activity (registers) and interrupts, use:"
echo "     ./run_canon_fw.sh 60D -d io,int"
echo "   - to show the executed ASM code, step by step, use:"
echo "     ./run_canon_fw.sh 60D -d exec,int -singlestep"
echo "   - to trace debug messages and various functions in the firmware, use:"
668
echo "     ./run_canon_fw.sh 60D -d debugmsg -s -S & $ARM_GDB -x 60D/debugmsg.gdb"
669
echo "   - some camera models require GDB patches to bypass tricky code sequences:"
670
echo "     ./run_canon_fw.sh EOSM -s -S & $ARM_GDB -x EOSM/patches.gdb"
671
echo
672
673
674
echo
echo "Online documentation: "
echo
alex@thinkpad's avatar
alex@thinkpad committed
675
676
echo "   https://bitbucket.org/hudson/magic-lantern/src/qemu/contrib/qemu/README.rst"
echo "   https://bitbucket.org/hudson/magic-lantern/src/qemu/contrib/qemu/HACKING.rst"
677
678
echo
echo "Enjoy!"
alex@thinkpad's avatar
alex@thinkpad committed
679
680
echo

681
if [ $(uname) != "Darwin" ] && ! [[ $DISPLAY ]]; then
alex@thinkpad's avatar
alex@thinkpad committed
682
683
684
685
686
687
688
    echo "P.S. To run the GUI, please make sure you have a valid DISPLAY."
    if [  -n "$(uname -a | grep Microsoft)" ]; then
        echo "Under Windows, you may install either VcXsrv or XMing."
        echo "Start it, then type the following into the terminal:"
        echo "    export DISPLAY=:0"
    fi
fi