Skip to content

Commit 2634c41

Browse files
committed
Use custom QEMU build file
1 parent 9ebec4e commit 2634c41

File tree

2 files changed

+117
-12
lines changed

2 files changed

+117
-12
lines changed

Makefile

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

407407
BEAR_CMD :=
408408
ifeq ($(BEAR),1)
409-
BEAR_CMD := bear --
409+
BEAR_CMD := bear --output $(TRUSTY_SRC) --
410410
endif
411411

412-
.PHONY: trusty-init
413-
trusty-init:
412+
# Trusty is not a submodule, we need to sync it manually
413+
$(TRUSTY_SRC):
414414
mkdir -p $(TRUSTY_SRC)
415+
416+
.PHONY: trusty-init
417+
trusty-init: | $(TRUSTY_SRC)
415418
cd $(TRUSTY_SRC) && repo init -u https://android.googlesource.com/trusty/manifest -b main
416419
cd $(TRUSTY_SRC) && repo sync -j`nproc` -c --no-tags
417420

421+
$(MAKE) trusty-qemu-init
422+
423+
# QEMU 3.0 is used by trusty by default. Let's use something newer, we just
424+
# need to apply some Android-specific patches
425+
.PHONY: trusty-qemu-init
426+
trusty-qemu-init:
427+
# TODO: Make this a loop, put commit message of each in a comment
428+
# TODO: Hardcode a stable version commit instead
429+
# TODO: Can we skip the third one
430+
cd $(TRUSTY_SRC)/external/qemu \
431+
&& git checkout aosp/upstream-master \
432+
&& git cherry-pick a4d024b2fdcc478402d00890965eeacb5542c12e \
433+
&& git cherry-pick f060068503259b661be8bd8c803291ff6412d2d6 \
434+
&& git cherry-pick 8a933fbb9c6fb8add1c74f5b523ecb44da7372fa \
435+
&& git cherry-pick 0bfea6599b8a3ebd2c3f98bf6e0d2705e5cb609c
436+
437+
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
438+
418439
.PHONY: trusty
419440
trusty $(ATF_BL1): | $(TRUSTY_SRC)
420441
$(BEAR_CMD) $(TRUSTY_SRC)/trusty/vendor/google/aosp/scripts/build.py \
@@ -460,6 +481,8 @@ QEMU_ARGS := \
460481
-no-reboot \
461482
-kernel $(QEMU_KERNEL_IMAGE) \
462483
-echr $(ECHR) \
484+
-netdev user,id=eth0,hostfwd=tcp::7777-:7777,hostfwd=tcp::2222-:22,hostfwd=tcp::2223-:23 -device virtio-net-pci,netdev=eth0 \
485+
-virtfs local,security_model=mapped-xattr,path=$(SHARED_DIR),mount_tag=shared \
463486
$(QEMU_EXTRA_ARGS)
464487

465488
ifeq ($(TRUSTY),1)
@@ -468,13 +491,6 @@ else ifeq ($(UBOOT),1)
468491
QEMU_ARGS += -bios $(UBOOT_BIN)
469492
endif
470493

471-
ifneq ($(TRUSTY),1)
472-
# Trusty currently only works with a very old version of QEMU, these flags
473-
# don't seem to work with it
474-
QEMU_ARGS += -netdev user,id=eth0,hostfwd=tcp::7777-:7777,hostfwd=tcp::2222-:22,hostfwd=tcp::2223-:23 -device virtio-net-pci,netdev=eth0
475-
QEMU_ARGS += -virtfs local,security_model=mapped-xattr,path=$(SHARED_DIR),mount_tag=shared
476-
endif
477-
478494
ifneq ($(INITRD),)
479495
ifeq ($(INITRD),1)
480496
INITRD := $(CPIO_FILE)
@@ -505,8 +521,8 @@ else ifeq ($(ARCH),i386)
505521
QEMU_KERNEL_CMDLINE += console=ttyS0
506522
else
507523
ifeq ($(TRUSTY),1)
508-
# Trusty currently only runs with its patched build of QEMU
509-
QEMU_BIN ?= $(TRUSTY_OUT)/qemu-build/aarch64-softmmu/qemu-system-aarch64
524+
# Trusty needs to use its own build of QEMU which has some custom patches
525+
QEMU_BIN ?= $(TRUSTY_OUT)/qemu-build/qemu-system-aarch64
510526
else
511527
QEMU_BIN ?= qemu-system-aarch64
512528
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)