Skip to content

Commit c517ab8

Browse files
committed
Use custom QEMU build file
1 parent d072ba9 commit c517ab8

File tree

2 files changed

+117
-5
lines changed

2 files changed

+117
-5
lines changed

Makefile

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,15 +409,36 @@ ATF_BL33 := $(ATF_DIR)/bl33.bin
409409

410410
BEAR_CMD :=
411411
ifeq ($(BEAR),1)
412-
BEAR_CMD := bear --
412+
BEAR_CMD := bear --output $(TRUSTY_SRC) --
413413
endif
414414

415-
.PHONY: trusty-init
416-
trusty-init:
415+
# Trusty is not a submodule, we need to sync it manually
416+
$(TRUSTY_SRC):
417417
mkdir -p $(TRUSTY_SRC)
418+
419+
.PHONY: trusty-init
420+
trusty-init: | $(TRUSTY_SRC)
418421
cd $(TRUSTY_SRC) && repo init -u https://android.googlesource.com/trusty/manifest -b main
419422
cd $(TRUSTY_SRC) && repo sync -j`nproc` -c --no-tags
420423

424+
$(MAKE) trusty-qemu-init
425+
426+
# QEMU 3.0 is used by trusty by default. Let's use something newer, we just
427+
# need to apply some Android-specific patches
428+
.PHONY: trusty-qemu-init
429+
trusty-qemu-init:
430+
# TODO: Make this a loop, put commit message of each in a comment
431+
# TODO: Hardcode a stable version commit instead
432+
# TODO: Can we skip the third one
433+
cd $(TRUSTY_SRC)/external/qemu \
434+
&& git checkout aosp/upstream-master \
435+
&& git cherry-pick a4d024b2fdcc478402d00890965eeacb5542c12e \
436+
&& git cherry-pick f060068503259b661be8bd8c803291ff6412d2d6 \
437+
&& git cherry-pick 8a933fbb9c6fb8add1c74f5b523ecb44da7372fa \
438+
&& git cherry-pick 0bfea6599b8a3ebd2c3f98bf6e0d2705e5cb609c
439+
440+
sed -i 's|include project/qemu-qemu-inc.mk|include $(CONFIG_DIR)/trusty/qemu-qemu-inc.mk|g' $(TRUSTY_SRC)/trusty/device/arm/generic-arm64/project/qemu-inc.mk
441+
421442
.PHONY: trusty
422443
trusty $(ATF_BL1): | $(TRUSTY_SRC)
423444
$(BEAR_CMD) $(TRUSTY_SRC)/trusty/vendor/google/aosp/scripts/build.py \
@@ -463,6 +484,8 @@ QEMU_ARGS := \
463484
-no-reboot \
464485
-kernel $(QEMU_KERNEL_IMAGE) \
465486
-echr $(ECHR) \
487+
-netdev user,id=eth0,hostfwd=tcp::7777-:7777,hostfwd=tcp::2222-:22,hostfwd=tcp::2223-:23 -device virtio-net-pci,netdev=eth0 \
488+
-virtfs local,security_model=mapped-xattr,path=$(SHARED_DIR),mount_tag=shared \
466489
$(QEMU_EXTRA_ARGS)
467490

468491
ifeq ($(TRUSTY),1)
@@ -512,8 +535,8 @@ else ifeq ($(ARCH),i386)
512535
QEMU_KERNEL_CMDLINE += console=ttyS0
513536
else
514537
ifeq ($(TRUSTY),1)
515-
# Trusty currently only runs with its patched build of QEMU
516-
QEMU_BIN ?= $(TRUSTY_OUT)/qemu-build/aarch64-softmmu/qemu-system-aarch64
538+
# Trusty needs to use its own build of QEMU which has some custom patches
539+
QEMU_BIN ?= $(TRUSTY_OUT)/qemu-build/qemu-system-aarch64
517540
else
518541
QEMU_BIN ?= qemu-system-aarch64
519542
endif

config/trusty/qemu-qemu-inc.mk

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#
2+
# Copyright (c) 2018, Google, Inc. All rights reserved
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
#
18+
# This makefile contains rules for building QEMU for running Trusty.
19+
# It is expected that it will be included by the project that uses QEMU
20+
# and the caller will configure the following variables:
21+
#
22+
# QEMU_ROOT - Root of qemu project
23+
# QEMU_BUILD_BASE - location that will be used to store temp files and
24+
# build results.
25+
# QEMU_ARCH - qemu arch to build
26+
# QEMU_TARGET - targets to build, use comma to separate targets
27+
# if multiple targets are specified.
28+
#
29+
# The following variable is returned to the caller:
30+
# QEMU_BIN - resulting qemu image
31+
# QEMU_BUILD_BASE - location that will be used to store temp files and
32+
# build results.
33+
#
34+
#
35+
36+
QEMU_BIN:=$(QEMU_BUILD_BASE)/$(QEMU_ARCH)-softmmu/qemu-system-$(QEMU_ARCH)
37+
QEMU_MAKEFILE:=$(QEMU_BUILD_BASE)/Makefile
38+
39+
# Set of features disabled by the AOSP emulator. We don't need these features
40+
# either, and we want minimal dependencies.
41+
QEMU_AOSP_DISABLES := \
42+
--disable-curses \
43+
--disable-docs \
44+
--disable-glusterfs \
45+
--disable-gtk \
46+
--disable-spice \
47+
--disable-opengl \
48+
49+
# Warnings which pollute the build output and which can make us miss
50+
# warnings in non-external code that we should be paying attention to.
51+
QEMU_EXTRA_CFLAGS := \
52+
-Wno-address-of-packed-member \
53+
-Wno-format-truncation \
54+
-Wno-stringop-truncation \
55+
-Wno-array-bounds \
56+
57+
# Newer capstone releases have the headers under include/capstone
58+
QEMU_EXTRA_CFLAGS += -I$(TRUSTY_TOP)/$(QEMU_ROOT)/capstone/include/capstone
59+
60+
$(QEMU_MAKEFILE): QEMU_ROOT:=$(QEMU_ROOT)
61+
$(QEMU_MAKEFILE): QEMU_BUILD_BASE:=$(QEMU_BUILD_BASE)
62+
$(QEMU_MAKEFILE): QEMU_TARGET:=$(QEMU_TARGET)
63+
$(QEMU_MAKEFILE): QEMU_AOSP_DISABLES:=$(QEMU_AOSP_DISABLES)
64+
$(QEMU_MAKEFILE): QEMU_EXTRA_CFLAGS:=$(QEMU_EXTRA_CFLAGS)
65+
$(QEMU_MAKEFILE):
66+
mkdir -p $(QEMU_BUILD_BASE)
67+
#--with-git=true sets the "git" program to /bin/true - it essentially disables git
68+
#--disable-git-update may look like what we want, but it requests manual intervention, not disables git
69+
# TODO(b/148904400): Our prebuilt Clang can't build QEMU yet, and there is no
70+
# prebuilts GCC, i.e. currently we can only build QEMU with host toolchain. On
71+
# some hosts compiler will complain about stringop truncation.
72+
cd $(QEMU_BUILD_BASE) && $(abspath $(QEMU_ROOT)/configure) \
73+
--target-list=$(QEMU_TARGET) --disable-werror \
74+
--extra-cflags="$(QEMU_EXTRA_CFLAGS)" \
75+
--disable-gcrypt $(QEMU_AOSP_DISABLES) \
76+
--enable-slirp
77+
78+
$(QEMU_BIN): QEMU_BUILD_BASE:=$(QEMU_BUILD_BASE)
79+
$(QEMU_BIN): $(QEMU_MAKEFILE) .PHONY
80+
$(MAKE) -C $(QEMU_BUILD_BASE)
81+
82+
# Add QEMU_BIN to the list of project dependencies
83+
EXTRA_BUILDDEPS += $(QEMU_BIN)
84+
85+
QEMU_ARCH:=
86+
QEMU_ROOT:=
87+
QEMU_TARGET:=
88+
QEMU_AOSP_DISABLES:=
89+
QEMU_EXTRA_CFLAGS:=

0 commit comments

Comments
 (0)