Simplified doc-site generation
[AGL/documentation.git] / docs / 0_Getting_Started / 2_Developing_an_AGL_Image / 7_Building_for_Emulation.md
1 ---
2 edit_link: ''
3 title: Building for Emulation
4 origin_url: >-
5   https://raw.githubusercontent.com/automotive-grade-linux/docs-sources/master/docs/getting-started/machines/qemu.md
6 ---
7
8 <!-- WARNING: This file is generated by fetch_docs.js using /home/boron/Documents/AGL/docs-webtemplate/site/_data/tocs/getting_started/master/image-development-workflow-getting-started-book.yml -->
9
10 # Building for Emulation
11
12 Building an image for emulation allows you to simulate your
13 image without actual target hardware.
14
15 This section describes the steps you need to take to build the
16 AGL demo image for emulation using either Quick EMUlator (QEMU) or
17 VirtualBox.
18
19 ## 1. Making Sure Your Build Environment is Correct
20
21 The
22 "[Initializing Your Build Environment](../image-workflow-initialize-build-environment.html)"
23 section presented generic information for setting up your build environment
24 using the `aglsetup.sh` script.
25 If you are building the AGL demo image for emulation, you need to specify some
26 specific options when you run the script:
27
28 ```bash
29 source meta-agl/scripts/aglsetup.sh -f -m qemux86-64 agl-demo agl-devel
30 ```
31
32 The "-m" option specifies the "qemux86-64" machine.
33 The list of AGL features used with script are appropriate for development of
34 the AGL demo image suited for either QEMU or VirtualBox.
35
36 ## 2. Using BitBake
37
38 This section shows the `bitbake` command used to build the AGL image.
39 Before running BitBake to start your build, it is good to be reminded that AGL
40 does provide pre-built images for developers that can be emulated
41 using QEMU and VirtualBox.
42 You can find these pre-built images on the
43 [AGL Download web site](https://download.automotivelinux.org/AGL/release).
44
45 For supported images, the filenames have the following forms:
46
47 ```
48 <release-name>/<release-number>/qemuarm/*
49 <release-name>/<release-number>/qemuarm64/*
50 <release-name>/<release-number>/qemux86-64/*
51 ```
52
53 Start the build using the `bitbake` command.
54
55 **NOTE:** An initial build can take many hours depending on your
56 CPU and and Internet connection speeds.
57 The build also takes approximately 100G-bytes of free disk space.
58
59 For this example, the target is "agl-demo-platform":
60
61 ```bash
62   bitbake agl-demo-platform
63 ```
64
65 By default, the build process puts the resulting image in the Build Directory:
66
67 ```
68 <build_directory>/tmp/deploy/images/qemux86-64/
69
70 e.g.
71
72 <build_directory>/tmp/deploy/images/qemux86-64/agl-demo-platform-qemux86-64.vmdk.xz
73 ```
74
75 **Note:**
76
77 If you built your image with bitbake, you can now just use the ``runqemu`` wrapper.
78
79 **Note:**
80 If you need to run it outside of the bitbake environment or need special settings for
81 hardware pass-through or the like, read on:
82
83
84 ## 3. Deploying the AGL Demo Image
85
86 Deploying the image consists of decompressing the image and then
87 booting it using either QEMU or VirtualBox.
88
89 ### Decompress the image:
90
91 For Linux, use the following commands to decompress the image and prepare it for boot:
92
93 ```bash
94 cd tmp/deploy/images/qemux86-64
95 xz -d agl-demo-platform-qemux86-64.vmdk.xz
96 ```
97
98 For Windows, download [7-Zip](http://www.7-zip.org/) and then
99 select **agl-demo-platform-qemux86-64.vmdk.xz** to decompress
100 the image and prepare it for boot.
101
102 ### Boot the Image:
103
104 The following steps show you how to boot the image with QEMU or VirtualBox.
105
106 #### QEMU
107
108 Depending on your Linux distribution, use these commands to install QEMU:
109
110 **NOTE:** if you have created an AGL crosssdk, it will contain a
111 QEMU binary for the build host.
112 This SDK QEMU binary does not support graphics.
113 Consequently,  you cannot use it to boot the AGL image and
114 need to call your host's qemu binary instead.
115
116 **NOTE:** the VM images need UEFI in the emulator to boot. Thus you need
117 to install the necessary files with below commands (ovmf).
118
119 If your build host is running
120 [Arch Linux](https://www.archlinux.org/), use the following commands:
121
122 ```bash
123 sudo pacman -S qemu ovmf
124 export OVMF_PATH=/usr/share/ovmf/x64/OVMF_CODE.fd
125 ```
126
127 If your build host is running Debian or Ubuntu, use the following commands:
128
129 ```bash
130 sudo apt-get install qemu-system-x86 ovmf
131 export OVMF_PATH=/usr/share/ovmf/OVMF.fd
132 ```
133
134 If you build host is running Fedora, use the following commands:
135
136 ```bash
137 sudo yum install qemu qemu-kvm edk2-ovmf
138 export OVMF_PATH=/usr/share/edk2/ovmf/OVMF_CODE.fd
139 ```
140
141 Once QEMU is installed, boot the image with KVM support:
142
143 ```bash
144 qemu-system-x86_64 -enable-kvm -m 2048 \
145     -bios ${OVMF_PATH} \
146     -hda agl-demo-platform-qemux86-64.wic.vmdk \
147     -cpu kvm64 -cpu qemu64,+ssse3,+sse4.1,+sse4.2,+popcnt \
148     -vga virtio -show-cursor \
149     -device virtio-rng-pci \
150     -serial mon:stdio -serial null \
151     -soundhw hda \
152     -net nic \
153     -net user,hostfwd=tcp::2222-:22
154 ```
155
156 **NOTE:** KVM may not be supported within a virtualized environment such as
157 VirtualBox. This is indicated by the qemu command above giving the error
158 message `Could not access KVM kernel module: No such file or directory` or
159 the kernel log output contains the error message `kvm: no hardware support`.
160 The image can be booted in such an environment by removing `-enable-kvm` from
161 the qemu command line, however this will result in lower perfromance within
162 the AGL demo.
163
164 #### VirtualBox
165
166 Start by downloading and installing [VirtualBox](https://www.virtualbox.org/wiki/Downloads) 5.2.0 or later.
167
168 Once VirtualBox is installed, follow these steps to boot the image:
169
170 1. Start VirtualBox
171 2. Click **New** to create a new machine
172 3. Enter **AGL QEMU** as the *Name*
173 4. Select **Linux** as the *Type*
174 5. Select **Other Linux (64-bit)** as the *Version*
175 6. Set *Memory size* to **2 GB**
176 7. Click **Use an existing virtual hard disk file** under *Hard disk*
177 8. Navigate to and select the **agl-demo-platform-qemux86-64.vmdk** image
178 9. Select the newly created **AGL QEMU** machine and click **Settings**
179 10. Go to the **System** tab and ensure **Enable EFI (special OSes only)** is enabled then click **OK**
180 11. With the **AGL QEMU** machine still selected, click **Start** to boot the virtual machine