4 echo "Usage: $(basename $0) [options]"
5 echo -e "Builds QEMU and Linux kernel from source.\n"
6 echo -e " --help\t\t\tDisplay this information."
7 echo -e " --kernel {arm|arm64}\t\tBuild Linux kernel for the architecture."
8 echo -e " --qemu\t\t\tBuild QEMU from source."
9 echo -e " --clean\t\t\tRemove qemu.git and linux.git directories in current directory."
13 update_repositories
() {
14 echo -e "\nUpdating apt repositories. "
15 echo -e "\nPress 'y' to continue or any other key to exit..."
16 read -s -n 1 user_input
17 if [[ $user_input == 'Y' ]] ||
[[ $user_input == 'y' ]]; then
27 echo -e "\n$1 already exists in working directory and will not be updated."
28 echo -e "\nPress 'y' to continue or any other key to exit..."
29 read -s -n 1 user_input
30 if [[ $user_input != 'Y' ]] && [[ $user_input != 'y' ]]; then
37 echo "ERROR: Unrecognized argument: $1" >&2
42 echo "Installing QEMU build dependencies ..."
43 sudo apt
install git python3-dev libsdl1.2
-dev build-essential libpixman-1-dev
45 # Checkout source code
46 check_dir_exists
"qemu.git"
47 if [ ! -d "qemu.git" ]; then
48 git clone
--depth 1 https
://gitlab.com
/qemu-project
/qemu.git qemu.git
52 # We are going to build QEMU Arm and AArch64 system mode emulation.
53 # ./configure --help emits a list of other possible targets supported by QEMU.
54 .
/configure
--target-list=arm-softmmu
,aarch64-softmmu
55 make -j`getconf _NPROCESSORS_ONLN`
59 echo "Installing Linux kernel build dependencies ..."
60 sudo apt
install git bison flex build-essential libssl-dev
bc
62 check_dir_exists
"linux.git"
64 if [ ! -d "linux.git" ]; then
66 https
://git.kernel.org
/pub
/scm
/linux
/kernel
/git
/torvalds
/linux.git linux.git
72 if [[ "$1" == "arm" ]]; then
73 echo "Installing gcc-arm-linux-gnueabihf ..."
74 sudo apt
install gcc-arm-linux-gnueabihf
76 # Configure kernel_branch=master arch=arm config=vexpress_defconfig
77 make O
=..
/linux.build
/arm ARCH
=arm CROSS_COMPILE
=arm-linux-gnueabihf- \
80 # Trigger Arm kernel build
81 make -j`getconf _NPROCESSORS_ONLN` O
=..
/linux.build
/arm ARCH
=arm \
82 CROSS_COMPILE
=arm-linux-gnueabihf-
83 elif [[ "$1" == "arm64" ]]; then
84 echo "Installing gcc-aarch64-linux-gnu ..."
85 sudo apt
install gcc-aarch64-linux-gnu
87 # Configure kernel_branch=master arch=arm64 config=defconfig
88 make O
=..
/linux.build
/arm64 ARCH
=arm64 CROSS_COMPILE
=aarch64-linux-gnu- \
91 # Trigger AArch64 kernel build
92 make -j`getconf _NPROCESSORS_ONLN` O
=..
/linux.build
/arm64 ARCH
=arm64 \
93 CROSS_COMPILE
=aarch64-linux-gnu-
95 echo "ERROR: Unrecognized architecture: $1" >&2
102 if [ -d "linux.git" ]; then
103 echo "Removing linux.git ..."
107 if [ -d "linux.build" ]; then
108 echo "Removing linux.build ..."
112 if [ -d "qemu.git" ]; then
113 echo "Removing qemu.git ..."
121 while [[ $# -gt 0 ]]; do
122 case "${END_OF_OPT}${1}" in
123 -h|
--help) print_usage
0 ;;
125 if [ "$2" == "arm64" ] ||
[ "$2" == "arm" ]; then
134 *) invalid_arg
"$1" ;;
141 if [ "$KERNEL_ARCH" != "" ]; then
143 build_linux
$KERNEL_ARCH
147 if [[ $QEMU -eq 1 ]]; then