|
1 | 1 | # QEMU |
2 | 2 |
|
3 | | -By default, the build system will download a pre-built release of our [QEMU fork](https://github.com/lowRISC/qemu/). |
4 | | -In order to support local development and testing, the build system also supports a way to build QEMU from source. |
5 | | -See instructions below. |
6 | | - |
7 | | -## Building from source using Bazel |
8 | | - |
9 | | -To perform local development, you first need to check out a copy of [QEMU fork](https://github.com/lowRISC/qemu/) and switch to the correct branch. |
10 | | - |
11 | | -The following step must only be done once: |
12 | | -```bash |
13 | | -# Run the following commands at the root of your QEMU checkout. |
14 | | -touch REPO.bazel |
15 | | -ln -s "/path/to/your/opentitan/repo/third_party/qemu/BUILD.qemu_opentitan.bazel" "BUILD.bazel" |
16 | | -``` |
17 | | - |
18 | | -Once done, every time you compile something using QEMU in OpenTitan, you need to tell Bazel to use your QEMU repository instead of downloading a release archive. |
19 | | -This is done by passing the following command-line argument to bazel: |
20 | | -``` |
21 | | ---override_repository="+qemu+qemu_opentitan_src=/path/to/your/qemu/repo/" |
22 | | -``` |
23 | | -For example: |
24 | | -```bash |
25 | | -./bazelisk.sh cquery --override_repository=... @qemu_opentitan//:build/qemu-system-riscv32 |
26 | | -``` |
27 | | -Since this can become quite tedious, you also have the option of adding this to your local bazelrc file. The recommended way of doing is to create a `.bazelrc-site` file at the root of the repo (if does not exists) and add: |
28 | | -``` |
29 | | -common --override_repository=... |
30 | | -``` |
31 | | - |
32 | | -**Important note:** when using this override, Bazel will essentially share your QEMU source repository. |
33 | | -In particular, the content of the `build/` directory will be used to support incremental compilation in Bazel. |
34 | | -The content of this directory can change when you run Bazel command. |
35 | | -Bazel will automatically watch all files in the QEMU repository so that it can rebuild it if it changes. |
| 3 | +For instructions on setting up QEMU for local development and troubleshooting steps, see the [setup guide](./setup.md). |
36 | 4 |
|
37 | 5 | ## Test parameters |
38 | 6 |
|
@@ -67,26 +35,3 @@ opentitan_test( |
67 | 35 | # ... |
68 | 36 | ) |
69 | 37 | ``` |
70 | | - |
71 | | -## Troubleshooting |
72 | | - |
73 | | -### Bazel tells me that `+qemu+qemu_opentitan_src` is not a valid repository name |
74 | | - |
75 | | -Unfortunately bazel requires the canonical name of the repository to be given on the command line and this name may change in the future. |
76 | | -If this happens, you can run the following commands to figure out the canonical name: |
77 | | -```bash |
78 | | -./bazelisk.sh mod dump_repo_mapping "" | jq .qemu_opentitan_src |
79 | | -``` |
80 | | -If the opentitan repository is not the root repository, |
81 | | -you will need to update the above command to pass the canonical name of the opentitan repository |
82 | | -instead of `""`. |
83 | | - |
84 | | -### How does it work? |
85 | | - |
86 | | -When passing `--override_repository="+qemu+qemu_opentitan_src=/path/to/your/qemu/repo/"`, the `qemu_bazel_build_or_forward` repository rules |
87 | | -detect the override by looking for a specific marker file which is added to the release archive. |
88 | | -If an override is detected, the repository rule will run the `build_qemu.sh` script inside the user's QEMU source directory. |
89 | | -This script configures QEMU if necessary and then builds everything using ninja. |
90 | | -Finally, it uses the OpenTitan release script to create a fake release archive. |
91 | | -The repository rule then extracts this archive into the repository so that the content looks identical to normal, downloaded release. |
92 | | -Finally, the repository rule also asks Bazel to watch all the files in the QEMU source directory, except for the `build/` directory. |
0 commit comments